Thymeleaf 实现分页模糊查询

在SpringBoot项目中,通过引入Thymeleaf,配置分页自适应,创建实体类Plate,定义PlateMapper及XML文件,实现List selectByParamter方法。在Service层和Impl层分别设计并实现PageInfo的分页查询功能。Controller层创建PlateController进行处理,最后在templates下的index.html页面展示查询结果。
摘要由CSDN通过智能技术生成

在springboot项目中

使用之前需导包

    <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

在在application.yml文件中配置分页自适应

pagehelper:   //前面没有空格
  reasonable: true   //前面必须两个空格
  auto-dialect: true

1,在pojo包中创建实体类 Plate
2, 在Mapper包中创建PlateMapper (包含 List selectByParamter(Plate plate);方法)
3, 在resoures资源文件夹下的Mapper文件加中创建PlateMapper.xml

  <select id="selectByParamter" parameterType="plate" resultMap="BaseResultMap">
    select ID, PNAME, PLEVEL, PID, SORT, IS_HOT, IS_LOGIN, URL
    from T_PLATE
    <where>
      <if test="pname !=null and pname !=''">
--         and PNAME like '%'||#{pname,jdbcType=VARCHAR}||'%'
        and PNAME like '%${pname}%'
      </if>
      <if test="plevel !=null and plevel !=0">
        and PLEVEL = #{plevel,jdbcType=NUMERIC}
      </if>
    </where>
    order by sort
  </select>

4, 在Service包中创建PlateService (包含PageInfo page(Plate plate, int pageNumber, int pageSize);方法 )
5,在Service包中的impl包中创建PlateServiceImpl.java类,如下图

package com.seecen.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.seecen.sys.mapper.IPlateMapper;
import com.seecen.sys.pojo.Plate;
i
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值