Spring Boot图书管理系统项目实战-6.图书管理

导航:

pre:  5.读者管理

next:7.借阅图书

 

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

1.项目源码

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

 

2.页面设计

 

2.1 book.html





    
    
    图书管理
    





 

3.图书管理service

/**
 * @Description: 图书服务
 * @Author laoxu
 * @Date 2019/5/2 9:26
 **/
@Service
public class BookService extends AbstractService {
    public void add(Book entity) {
        //String username = SecurityUtil.getLoginUser();
        insert("bookMapper.insert",entity);
    }

    public void modify(Book entity) {
        update("bookMapper.update",entity);
    }

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

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

    public Book get(Long id) {
        return selectOne("bookMapper.select",id);
    }

    public Book getByIsbn(String isbn) {
        return selectOne("bookMapper.selectByIsbn",isbn);
    }

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

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

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

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


    public int checkCode(Book entity){
        return selectOne("bookMapper.countCode",entity);
    }

}

 

4.图书管理controller

 

/**
 * @Description: 图书控制器
 * @Author laoxu
 * @Date 2019/5/2 10:16
 **/
@RestController
@RequestMapping("/api/book")
public class BookController {
    @Autowired
    BookService bookService;

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

        return ResultUtil.ok();
    }


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

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

        return ResultUtil.ok(entity);
    }

    @GetMapping("/list")
    public ResultBean> getPageResult(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String isbn,
            @RequestParam(required = false) String author,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit) {

        Map param = new HashMap<>();

        // 计算起始行号
        int offset = (page - 1) * limit;
        int rows = limit;

        param.put("name",name);
        param.put("isbn",isbn);
        param.put("author",author);
        param.put("offset", offset);
        param.put("rows", rows);

        // 统计记录数
        int totalRows = bookService.count(param);

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

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

        return result;

    }
}

 

 

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

 

 

 

 

 

 

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