<?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">
<!--<1--namespace与mapper接口的全类名保持一致,-->
<mapper namespace="com.sunyu.mapper.EmpMapper">
<!-- Student selectStudent(@Param("studentName") String studentName);-->
<resultMap id="getEmpInforResultMap" type="Emp">
<id column="emp_id" property="empId"></id>
<result column="emp_name" property="empName"></result>
<result column="emp_age" property="empAge"></result>
</resultMap>
<select id="getEmpInfor" resultMap="getEmpInforResultMap">
select * from t_emp
<where>
<if test="empName != null and empName != ''">
and emp_name = #{empName}
</if>
<if test="empAge != null and empAge != ''">
and emp_age = #{empAge}
</if>
</where>
</select>
<!-- Emp selecet(@Param("empName") String empName);-->
<select id="selecetemp" resultMap="getEmpInforResultMap">
select * from t_emp where emp_name = #{empName}
</select>
</mapper>
遇到的问题:找不到emp_name在Emp.class文件中的位置
原因是在if标签中吧empName写成数据库中的emp_name
if标签中的内容是前端勾选之后传给后端需要查找什么,然后判断它如果不为空就执行sql从数据库中查询出来,所以if标签后应该写的是实体类的属性而不是数据库中的字段。