spring boot项目实现条件查询及分页

EmpMapper

<resultMap id="BaseResultMap" type="com.test.po.Emp" >
    <id column="empno" property="empno" jdbcType="INTEGER" />
    <result column="empname" property="empname" jdbcType="VARCHAR" />
    <result column="job" property="job" jdbcType="VARCHAR" />
    <result column="mgr" property="mgr" jdbcType="INTEGER" />
    <result column="hiredate" property="hiredate" jdbcType="TIMESTAMP" />
    <result column="sal" property="sal" jdbcType="INTEGER" />
    <result column="comm" property="comm" jdbcType="INTEGER" />
    <result column="deptno" property="deptno" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    empno, empname, job, mgr, hiredate, sal, comm, deptno
  </sql>
  <select id="queryemps" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from emp where 1=1
    <if test="deptno!=0">
    AND deptno=#{deptno,jdbcType=INTEGER}
    </if>
    <if test="empname != null">
      AND empname like CONCAT(CONCAT('%', #{empname,jdbcType=VARCHAR}), '%')
    </if>
  </select>

EmpDao

List<Emp> queryemps(@Param("deptno") Integer deptno,@Param("empname") String empname);

 

页面代码

<form id="query" action="/login.do" method="post" style="text-align: center;">
        姓名:<input type="text" name="ename" value="${name}">
        请选择部门:<select name="dNo">
        <option value="0">全部</option>
        <c:forEach items="${dList}" var="depts">
        <option value="${depts.deptno}" <c:if test="${depts.deptno==deptNo}">selected="selected"</c:if> >${depts.deptname}</option>
        </c:forEach>
        <input type="hidden" name="now" id="pageno">
        <input type="submit" value="查询">
        <a href="/add.htm">添加员工信息</a>
      </form>

EmpAction

@Autowired
    private EmpService empService;

    @Autowired
    private DeptService deptService;

    @RequestMapping("/login.do")
//    @ResponseBody
    public String  login(@RequestParam(value="dNo",required=false,defaultValue="0")Integer dNo,@RequestParam(value="ename",required=false)String ename, @RequestParam(value = "now", required = false, defaultValue = "1")Integer now, ModelMap map) {
        List<Dept> depts = deptService.selectAllDepts();
        map.put("dList",depts);
        PageHelper.startPage(now, 3);
        List<Emp> emps = empService.queryemps(dNo,ename);
        PageInfo<Emp> pageInfo = new PageInfo<>(emps);
        map.put("pageInfo", pageInfo);
        map.put("deptNo",dNo);
        map.put("name",ename);
        return "index";
    }

总结:今天初次了解spring boot并建立了完整的项目,了解并清楚了spring boot项目的构成及环境搭建,并通过以往学习的springMvc的相关知识点套用在新的spring boot项目上,实现了对数据库数据的条件查询及分页,还实现了对数据库数据的添加功能。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值