Spring Boot图书管理系统项目实战-4.基础信息管理

导航:

pre:  3.用户登录

next:5.读者管理

 

只挑重点的讲,具体的请看项目源码。

1.项目源码

需要的朋友请给个赞,并留下邮箱,给你们发!

 

2.页面设计

出版社管理、语种管理、书架管理功能参考图书类别管理。

Spring Boot图书管理系统项目实战-4.基础信息管理_第1张图片

 





    
    
    图书分类管理
    





3.图书分类service

/**
 * @Description: 图书分类service
 * @Author laoxu
 * @Date 2019/5/2 9:26
 **/
@Service
public class BookCategoryService extends AbstractService {
    public void add(BookCategory entity) {
        //String username = SecurityUtil.getLoginUser();
        insert("bookCategoryMapper.insert",entity);
    }

    public void modify(BookCategory entity) {
        update("bookCategoryMapper.update",entity);
    }

    public void remove(Long id) {
        delete("bookCategoryMapper.delete",id);
    }

    public void removes(Long[] ids) {
        delete("bookCategoryMapper.deletes",ids);
    }

    public BookCategory get(Long id) {
        return selectOne("bookCategoryMapper.select",id);
    }

    public List getParentList(Long id) {
        return selectList("bookCategoryMapper.selectParentList",id);
    }

    public int count(Map param) {
        return selectOne("bookCategoryMapper.count",param);
    }

    public List getList(Map param) {
        return selectList("bookCategoryMapper.selectList",param);
    }

    public List getPageResult(Map param) {
        return selectList("bookCategoryMapper.selectPageResult",param);
    }


    public int checkCode(BookCategory entity){
        return selectOne("bookCategoryMapper.countCode",entity);
    }

}

4.图书分类controller

/**
 * @Description: 分类控制器
 * @Author laoxu
 * @Date 2019/5/2 10:16
 **/
@RestController
@RequestMapping("/api/bookCategory")
public class BookCategoryController {
    @Autowired
    BookCategoryService categoryService;

    /**
     * 保存(新增/修改)
     *
     * @param entity
     * @return
     */
    @PostMapping("/save")
    public Result modify(@RequestBody BookCategory entity) {
        String code = entity.getCode();
        int count = categoryService.checkCode(entity);
        if(count>0){
            return ResultUtil.fail("编码已存在!");
        }
        if(entity.getId()!=null){
            categoryService.modify(entity);
        }else{
            categoryService.add(entity);
        }

        return ResultUtil.ok();
    }


    @PostMapping("/remove")
    public Result remove(@RequestBody Long[] ids) {
        categoryService.removes(ids);
        return ResultUtil.ok();
    }

    @GetMapping("/get")
    public Result get(@RequestParam("id") Long id) {
        BookCategory entity = categoryService.get(id);

        return ResultUtil.ok(entity);
    }

    @GetMapping("/list")
    public ResultBean> list(){
        List entities = categoryService.getList(null);
        return new ResultBean(0, "查询成功", entities.size(), entities);
    }

    @GetMapping("/getPageResult")
    public ResultBean> getPageResult(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit) {

        Map param = new HashMap<>();
        // 统计记录数
        int totalRows = categoryService.count(param);
        // 计算起始行号
        int offset = (page - 1) * limit;
        int rows = limit;

        param.put("offset", offset);
        param.put("rows", rows);

        // 获取当前页结果集
        List entities = categoryService.getPageResult(param);

        ResultBean result = new ResultBean(0, "查询成功", totalRows, entities);

        return result;

    }
}

 

 

需要源码的朋友留下邮箱:)

 

 

 

 

 

你可能感兴趣的:(#,Spring-Boot,Java项目实战)