这是一个多条件查询,当查询时给出条件,则按条件查询符合条件的所有数据;不给条件时,则查询全部。
mapper层:
/** 部门查询全部 条件:登录名称、手机号、状态、时间区间 */ List<XzUser> selectAll(@Param("userName") String userName, @Param("phoneNumber") String phoneNumber, @Param("status") String status, @Param("createTime") String createTime, @Param("endTime") String endTime);
sql:
<sql id="xzUser"> user_id, dept_id, user_name, nick_name, user_type, email, sex, avatar, password, status, del_flag, login_ip, login_date, phonenumber, create_by, create_time, update_by, update_time, remark </sql>
<resultMap id="xzUser" type="com.ruoyi.xinzhi.model.pojo.XzUser"> <id property="userId" column="user_id"></id> <id property="deptId" column="dept_id"></id> <id property="userName" column="user_name"></id> <id property="nickName" column="nick_name"></id> <id property="userType" column="user_type"></id> <id property="email" column="email"></id> <id property="sex" column="sex"></id> <id property="avatar" column="avatar"></id> <id property="password" column="password"></id> <id property="status" column="status"></id> <id property="delFlag" column="del_flag"></id> <id property="loginIp" column="login_ip"></id> <id property="loginDate" column="login_date"></id> <id property="phoneNumber" column="phonenumber"></id> <id property="createBy" column="create_by"></id> <id property="createTime" column="create_time"></id> <id property="updateBy" column="update_by"></id> <id property="updateTime" column="update_time"></id> <id property="remark" column="remark"></id> </resultMap>
<!-- 部门查询全部 条件:登录名称、手机号、状态、时间区间 --> <select id="selectAll" resultMap="xzUser"> select <include refid="xzUser"/> from xz_user <where> <if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%') </if> <if test="phoneNumber != null and phoneNumber != ''"> and phonenumber like concat('%', #{phoneNumber}, '%') </if> <if test="status != null and status != ''"> and ( (#{status} = '0' and status = '0') or (#{status} = '1' and status = '1') ) </if> <if test="createTime != null"> and create_time between #{createTime} and #{endTime} </if> </where> </select>
service层:
/** 部门查询全部 条件:登录名称、手机号、状态、时间区间 */ AjaxResult selectAll(String userName, String phoneNumber, String status, String createTime, String endTime,Integer pageNum, Integer pageSize);
impl实现类:
使用 PageHelper.startPage(pageNum, pageSize); 作为参,pageNum:起始页;pageSize:煤业显示数据几条;/** * 部门查询全部 条件:登录名称、手机号、状态、时间区间 * @param userName 登录名称 * @param phoneNumber 手机号 * @param status 0与1状态 * @param createTime 创建时间 * @param endTime 取件时间末 * @return 实体类对象 */ @Override public AjaxResult selectAll(String userName, String phoneNumber, String status, String createTime, String endTime, Integer pageNum, Integer pageSize) { PageHelper.startPage(pageNum, pageSize); List<XzUser> selected = xzUserMapper.selectAll(userName, phoneNumber, status, createTime, endTime); if (selected.isEmpty()) { return AjaxResult.error("无符合此条件的数据"); }else { return AjaxResult.success(selected); } }
controller层:
/** * 部门查询全部 条件:登录名称、手机号、状态、时间区间 * @param userName 登录名称 * @param phoneNumber 手机号 * @param status 0与1状态 * @param createTime 创建时间 * @param endTime 取件时间末 * @return 实体类对象 */ @GetMapping("/all") public AjaxResult selectAll(String userName, String phoneNumber, String status, String createTime, String endTime, Integer pageNum, Integer pageSize) { AjaxResult selected = iXzUserService.selectAll(userName, phoneNumber, status, createTime, endTime, pageNum, pageSize); return AjaxResult.success(selected); }
查询:
标签:status,String,param,PageHelper,startPage,phoneNumber,endTime,createTime,分页 From: https://www.cnblogs.com/warmNest-llb/p/18120512