SpringSSM(jsp分页查询)

分页查询

Controller层 

Controller层:MVC架构中的接口层,用户访问请求时对接;是对项目里的功能做统一的调度。

@Controller
@RequestMapping("/api/v1/TStorageRecord")
public class TStorageRecordController {



    @Autowired
    private TStorageRecordService tStorageRecordService;



    @RequestMapping("/listpage")
    public String listpage(TStorageRecord tStorageRecord, Model model){
        List<TStorageRecord> list=tStorageRecordService.getlist(tStorageRecord);
        Page01 page01=new Page01();
//        model.addAttribute("page",page01);
        model.addAttribute("tslist",list);
        return "list.jsp";
    }

    @RequestMapping("/goadd")
    public String goadd(){
        return "add.jsp";
    }

    @RequestMapping("/add")
    public String add(TStorageRecord tStorageRecord){
        tStorageRecordService.add(tStorageRecord);
        return "redirect:/api/v1/TStorageRecord/listlimit";
    }

    @RequestMapping("/del")
    public String del(int id){
        tStorageRecordService.del(id);
        return "redirect:/api/v1/TStorageRecord/listlimit";
    }

    @RequestMapping("/update")
    public String update(TStorageRecord tStorageRecord){
        tStorageRecordService.update(tStorageRecord);
        return "redirect:/api/v1/TStorageRecord/listlimit";
    }

    @RequestMapping("/gotupdate")
    public String gotupdate(Integer id,Model model){
        TStorageRecord tStorageRecord=tStorageRecordService.gettStorage(id);
        model.addAttribute("TSto",tStorageRecord);
        return "update.jsp";
    }

    @RequestMapping("getRoleLimit")
    public String getRolelimit(HttpServletRequest request){
        Page01 page01=new Page01();
        String currPageNostr=request.getParameter("currPageNo");
        if(currPageNostr==null||"".equals(currPageNostr)){
            page01.setCurrPageNo(1);
        }else{
            page01.setCurrPageNo(Integer.parseInt(currPageNostr));
        }
        String pageSizeStr=request.getParameter("pageSize");
        if(pageSizeStr==null||"".equals(pageSizeStr)){
            page01.setPageSize(2);
        }else{
            page01.setPageSize(Integer.parseInt(pageSizeStr));
        }
        page01.setTotalCount(tStorageRecordService.getRoleCount());
        page01.settStorageRecords(tStorageRecordService.getSysRoleList(page01.getCurrPageNo(),page01.getPageSize()));


        request.setAttribute("page",page01);
        request.setAttribute("Records",page01.gettStorageRecords());

        return "list.jsp";
    }
}

mapper层

 mapper层的作用是对数据库进行数据持久化操作,他的方法语句是直接针对数据库操作的现在用mybatis逆向工程生成的

public interface TStorageRecordMapper {

    List<TStorageRecord> getlist(TStorageRecord tStorageRecord);

    int add(TStorageRecord tStorageRecord);

    TStorageRecord gettStorage(Integer id);

    int update (TStorageRecord tStorageRecord);

    int del(Integer id);

    int getRoleCount();

    List<TStorageRecord> getSysRoleList(@Param("num")int num,@Param("pageSize")int pageSize);

}

service层

Service层主要负责业务模块的逻辑应用设计。同样是首先设计接口,再设计其实现的类,接着再Spring的配置文件中配置其实现的关联

public interface TStorageRecordService {
    List<TStorageRecord> getlist(TStorageRecord tStorageRecord);

    int add(TStorageRecord tStorageRecord);

    TStorageRecord gettStorage(Integer id);

    int update (TStorageRecord tStorageRecord);

    int del(Integer id);

    int getRoleCount();

    List<TStorageRecord> getSysRoleList(@Param("pageSize")int pageSize, @Param("currPageNo")int currPageNo);

}
@Service
public class TStorageRecordServiceimpl implements TStorageRecordService {

    @Autowired
    private TStorageRecordMapper tStorageRecordMapper;

    @Override
    public List<TStorageRecord> getlist(TStorageRecord tStorageRecord) {
        return tStorageRecordMapper.getlist(tStorageRecord);
    }

    @Override
    public int add(TStorageRecord tStorageRecord) {
        return tStorageRecordMapper.add(tStorageRecord);
    }

    @Override
    public TStorageRecord gettStorage(Integer id) {
        return tStorageRecordMapper.gettStorage(id);
    }

    @Override
    public int update(TStorageRecord tStorageRecord) {
        return tStorageRecordMapper.update(tStorageRecord);
    }

    @Override
    public int del(Integer id) {
        return tStorageRecordMapper.del(id);
    }

    @Override
    public int getRoleCount() {
        return tStorageRecordMapper.getRoleCount();
    }

    @Override
    public List<TStorageRecord> getSysRoleList(int currPageNo , int  pageSize) {
        int num=(currPageNo-1)*pageSize;
        return tStorageRecordMapper.getSysRoleList(num,pageSize);
    }

}

until层

存放工具类信息

public class Page01 {
    private int totalPageCount=0;//总页数 计算 根据每页展示记录数和记录总数计算出来的
    private int pageSize=3;//每页展示记录数,用户指定,通常有默认值
    private int totalCount;//记录总数,数据库查询
    private int currPageNo=1;//当前页码  用户指定 ,默认显示第一页
    private List<TStorageRecord> tStorageRecords;//每页数据集合  数据库查询

    public int getTotalPageCount() {
        if (totalCount%pageSize==0){
            return totalCount/pageSize;
        }else{
            return totalCount/pageSize+1;
        }

    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {
        this.currPageNo = currPageNo;
    }

    public List<TStorageRecord> gettStorageRecords() {
        return tStorageRecords;
    }

    public void settStorageRecords(List<TStorageRecord> tStorageRecords) {
        this.tStorageRecords = tStorageRecords;
    }
}

mappers层

<?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.xinxi2.mapper.TStorageRecordMapper">


    <insert id="add" keyProperty="id" keyColumn="id" useGeneratedKeys="true" parameterType="com.xinxi2.bean.TStorageRecord">
        INSERT INTO `t_storage_record`(goodsname)
        VALUES (#{goodsname})
    </insert>


    <update id="update" parameterType="com.xinxi2.bean.TStorageRecord">
        update t_storage_record
        <set>
            <if test="goodsname!=null">
                goodsname=#{goodsname},
            </if>
        </set>
        where id=#{id}
    </update>


    <delete id="del" parameterType="com.xinxi2.bean.TStorageRecord">
        delete from `t_storage_record` WHERE id=#{id}
    </delete>


    <select id="getlist" resultType="com.xinxi2.bean.TStorageRecord">
        SELECT * FROM `t_storage_record`
        <where>
            <if test="goodsname!=null">
               and goodsname=#{goodsname}
            </if>
            <if test="id!=null">
               and id=#{id}
            </if>
        </where>
    </select>

    <select id="gettStorage" resultType="com.xinxi2.bean.TStorageRecord">
        SELECT * FROM `t_storage_record` WHERE id=#{id}
    </select>


    <select id="getRoleCount" resultType="java.lang.Integer">
        SELECT count(1) FROM `t_storage_record`
    </select>

    <select id="getSysRoleList" resultType="com.xinxi2.bean.TStorageRecord">
        SELECT * FROM `t_storage_record`  LIMIT #{num},#{pageSize}
    </select>


</mapper>
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

困困的小熊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值