11 图书管理系统(SSM+LayUi)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了11 图书管理系统(SSM+LayUi),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5768字,纯文字阅读大概需要9分钟。
内容图文
1、DAO层接口和实现
- 在classInfoDao.java里写增删改
接口
package com.gychen.dao;
import com.gychen.po.ClassInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("classDao")
public interface ClassInfoDao {
/**
* 查询所有图书类型信息
*/
// @Select("select * from class_info")
// List<ClassInfo> queryClassInfoAll();
List<ClassInfo> queryClassInfoAll(@Param(value = "name")String name);
/**
* 添加图书类型
*/
void addBookType(ClassInfo classInfo);
/**
* 修改 根据id查询记录信息
*/
ClassInfo queryBookTypeById(Integer id);
/**
* 修改图书类型信息
*/
void updateBookType(ClassInfo classInfo);
/**
* 删除 根据一个或多个id删除
*/
void deleteBookTypeByIds(List<Integer> id);
}
- 在ClassInfoDao.xml里
实现
增删改语句
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.gychen.dao.ClassInfoDao" >
<!-- 查询全部信息 -->
<select id="queryClassInfoAll" resultType="com.gychen.po.ClassInfo">
select * from class_info
<where>
<if test="name!=null">
and name like ‘%${name}%‘
</if>
</where>
</select>
<!-- 增加图书类型 -->
<insert id="addBookType" parameterType="classInfo">
insert into class_info (name,remarks) values (#{name},#{remarks})
</insert>
<!-- 根据id查询类型信息 -->
<select id="queryBookTypeById" parameterType="int" resultType="classInfo">
select * from class_info where id=#{id}
</select>
<!-- 修改图书类型信息 -->
<update id="updateBookType" parameterType="classInfo">
update class_info set name=#{name},remarks=#{remarks} where id=#{id}
</update>
<!-- 根据ids 删除图书类型信息 -->
<delete id="deleteBookTypeByIds" parameterType="list">
delete from class_info where id in
<foreach collection="list" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
</delete>
</mapper>
2、service层接口和实现
- 在ClassInfoService里写增删改
接口
package com.gychen.service;
import com.github.pagehelper.PageInfo;
import com.gychen.po.ClassInfo;
import java.util.List;
public interface ClassInfoService {
/**
* 查询所有的图书类型信息
*/
PageInfo<ClassInfo> queryClassInfoAll(String name,int page,int limit);
/**
* 添加图书类型
*/
void addBookType(ClassInfo classInfo);
/**
* 修改 根据id查询记录信息
*/
ClassInfo queryBookTypeById(Integer id);
/**
* 修改图书类型信息
*/
void updateBookType(ClassInfo classInfo);
/**
* 删除 根据一个或多个id删除
*/
void deleteBookTypeByIds(List<Integer> ids);
}
- 在ClassInfoServiceImpl里
实现
增删改语句
package com.gychen.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gychen.dao.ClassInfoDao;
import com.gychen.po.ClassInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("classInfoService")
public class ClassInfoServiceImpl implements ClassInfoService {
@Autowired
private ClassInfoDao classDao;
@Override
public PageInfo<ClassInfo> queryClassInfoAll(String name,int page, int limit) {
// 传入参数,每页条数,当前页
PageHelper.startPage(page,limit);
List<ClassInfo> list = classDao.queryClassInfoAll(name);
// 通过包装获取分页需要的其他值
PageInfo<ClassInfo> pageInfo = new PageInfo<>(list);
return pageInfo;
}
@Override
public void addBookType(ClassInfo classInfo) {
classDao.addBookType(classInfo);
}
@Override
public ClassInfo queryBookTypeById(Integer id) {
return classDao.queryBookTypeById(id);
}
@Override
public void updateBookType(ClassInfo classInfo) {
classDao.updateBookType(classInfo);
}
@Override
public void deleteBookTypeByIds(List<Integer> ids) {
classDao.deleteBookTypeByIds(ids);
}
}
3、Controller层实现
- 在TypeController里添加增删改
package com.gychen.controller;
import com.github.pagehelper.PageInfo;
import com.gychen.po.ClassInfo;
import com.gychen.service.ClassInfoService;
import com.gychen.util.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
@Controller
public class TypeController {
@Autowired
private ClassInfoService classInfoService; // 这里的classInfoService要和ClassInfoServiceImpl中的注解名字相同
@RequestMapping("/typeIndex")
public String typeIndex(){
return "type/typeIndex";
}
/**
* 添加页面的转换
*/
@GetMapping("/typeAdd")
public String typeAdd(){
return "type/addType";
}
/**
* 获取type数据信息 分页
*/
@RequestMapping("/typeAll")
@ResponseBody
public RestResponse typeAll(String name, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "15") Integer limit){
PageInfo<ClassInfo> pageInfo = classInfoService.queryClassInfoAll(name, page, limit);
return RestResponse.ok(pageInfo.getList());
}
/**
* 类型添加
*/
@ResponseBody
@RequestMapping("/addBookType")
public RestResponse addBookType(ClassInfo classInfo){
classInfoService.addBookType(classInfo);
return RestResponse.ok();
}
/**
* 根据id查询
*/
@GetMapping("/queryBookTypeById")
public String queryBookTypeById(Integer id, Model model){
ClassInfo classInfo = classInfoService.queryBookTypeById(id);
model.addAttribute("info",classInfo);
return "type/updateType";
}
/**
* 修改提交功能
*/
@ResponseBody
@RequestMapping("/updateBookType")
public RestResponse updateBookType(@RequestBody ClassInfo classInfo){
classInfoService.updateBookType(classInfo);
return RestResponse.ok();
}
/**
* 删除类型
*/
@ResponseBody
@RequestMapping("/deleteType")
public RestResponse deleteType(String ids){
List list = Arrays.asList(ids.split(","));
classInfoService.deleteBookTypeByIds(list);
return RestResponse.ok();
}
}
原文:https://www.cnblogs.com/nuister/p/13361213.html
内容总结
以上是互联网集市为您收集整理的11 图书管理系统(SSM+LayUi)全部内容,希望文章能够帮你解决11 图书管理系统(SSM+LayUi)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。