UserMapper.xml是映射文件,结构和mybatis的映射文件保持一致,就只是去掉了xml头文件。

    1. <mapper namespace="userMapper">
    2. <resultMap id="userMap" type="com.example.aninbatisdemo.pojo.User">
    3. <result property="id" column="id" jdbcType="INTEGER"/>
    4. <result property="name" column="name" jdbcType="VARCHAR"/>
    5. </resultMap>
    6. <select id="queryUserById" parameterType="com.example.aninbatisdemo.pojo.User"
    7. resultType="com.example.aninbatisdemo.pojo.User" statementType="PREPARED">
    8. select * from `user` where id = #{id}
    9. <if test="name != null and name !='' ">
    10. AND username like '%${name}'
    11. <if test="name != null and name !=''">
    12. AND 1=1
    13. </if>
    14. </if>
    15. </select>
    16. </mapper>