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项目上,实现了对数据库数据的条件查询及分页,还实现了对数据库数据的添加功能。