根据需要设置模糊查询条件
上图对应的是mapper类,代码如下
public Page<Complain> selectAllByCode(@Param("page") IPage<Complain> page,@Param("c_comp_code")String c_comp_code,@Param("c_comp_person")String c_comp_person,@Param("c_comp_name")String c_comp_name,@Param("c_comp_message")String c_comp_message,@Param("c_person_type")String c_person_type,@Param("c_begin_date")String c_begin_date,@Param("c_end_date")String c_end_date);
mapper实现类
<?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.mybatisplus.mapper.ComplainMapper">
<select id="selectAllByCode" resultType="com.mybatisplus.entity.Complain" parameterType="map">
select * from tb_complain
<where>
<if test="c_comp_code!=null and c_comp_code!=''">
<bind name="c_comp_codeBind" value="'%'+c_comp_code+'%'" />
<![CDATA[ and c_comp_code like #{c_comp_codeBind} ]]>
</if>
<if test="c_comp_person!=null and c_comp_person!=''">
<bind name="c_comp_personBind" value="'%'+c_comp_person+'%'" />
<![CDATA[ and c_comp_person like #{c_comp_personBind} ]]>
</if>
<if test="c_comp_name!=null and c_comp_name!=''">
<![CDATA[ and c_comp_name = #{c_comp_name} ]]>
</if>
<if test="c_comp_message!=null and c_comp_message!=''">
<bind name="c_comp_messageBind" value="'%'+c_comp_message+'%'" />
<![CDATA[ and c_comp_message like #{c_comp_messageBind} ]]>
</if>
<if test="c_person_type!=null and c_person_type!=''">
<![CDATA[ and c_person_type = #{c_person_type} ]]>
</if>
<if test="c_begin_date!=null and c_begin_date!='' and c_end_date!=null and c_end_date!=''">
<![CDATA[
and c_comp_date between #{c_begin_date} and #{c_end_date}]]>
</if>
and c_comp_state = '1'
</where>
</select>
</mapper>
其中模糊查询一般都是伴随的是分页查询,利用mybatisPlus自带的类可以实现分页功能
Page<Complain> userPage = new Page<>();
// 设置分页的大小
userPage.setSize(input.getPageSize());
// 设置当前页
userPage.setCurrent(input.getPageNo());
// 这里调用的mapper和上面是对应的,直接使用就行,需要注意的是返回的类要对应,不然会出现查到的数据和返回的不对应
Page<Complain> complainPage = complainMapper.selectAllByCode(userPage, input.getC_comp_code(),input.getC_comp_person(), input.getC_comp_name(), input.getC_comp_message(), input.getC_person_type(), input.getBegin_date(), input.getEnd_date());