UserMapper.xml是映射文件,结构和mybatis的映射文件保持一致,就只是去掉了xml头文件。
<mapper namespace="userMapper">
<resultMap id="userMap" type="com.example.aninbatisdemo.pojo.User">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
</resultMap>
<select id="queryUserById" parameterType="com.example.aninbatisdemo.pojo.User"
resultType="com.example.aninbatisdemo.pojo.User" statementType="PREPARED">
select * from `user` where id = #{id}
<if test="name != null and name !='' ">
AND username like '%${name}'
<if test="name != null and name !=''">
AND 1=1
</if>
</if>
</select>
</mapper>