spring boot+layui分页实战

项目用了layui,做了个简单的图书搜索页,分享出来。

喜欢的朋友给点个赞!!!

 

实现效果

spring boot+layui分页实战_第1张图片

 

开发步骤

1.前端页面和JS




    
    
    
    搜索图书

    

    


Bookman图书检索

 

2.数据层

 

3.服务层

package com.laoxu.java.bookman.service;

import com.laoxu.java.bookman.framework.AbstractService;
import com.laoxu.java.bookman.model.Book;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @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.控制层

@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;

    }

 

5.数据格式参考

{
    "code": 0,
    "msg": "查询成功",
    "count": 1,
    "data": [{
        "id": 10,
        "createTime": "2020-01-12T11:22:49.000+0000",
        "creater": null,
        "updateTime": "2020-02-04T15:31:28.000+0000",
        "updater": null,
        "name": "大秦帝国",
        "isbn": "111",
        "categoryCode": "10",
        "categoryName": "K 历史、地理",
        "author": "孙皓晖",
        "publisherCode": "7-302",
        "publisherName": "清华大学出版社-北京",
        "price": 588,
        "edition": 1,
        "translator": "",
        "languageCode": "CH",
        "languageName": "汉语",
        "pages": 1200,
        "words": 5000000,
        "locationCode": "一号架",
        "locationName": "一号架",
        "totalNumber": 122,
        "leftNumber": 4,
    }]
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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