mybatis查询映射字段为null

根本原因:数据字段名称和实体字段名称不一致
解决办法1
将实体中的变量名称和数据库中的字段保持一致
解决办法2
在mapper文件中用resultMap 做映射

<?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">
<mapper namespace="pojo.BizSensitiveWords">
    <resultMap id="bizSensitiveWords" type="pojo.BizSensitiveWords">
        <id column="sensitive_word" property="sensitiveWord" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="querySensitiveWords" resultMap="bizSensitiveWords" parameterType="string">
		SELECT * FROM `biz_sensitive_words` WHERE sensitive_word LIKE #{username}
	</select>
</mapper>

日常一记!!!!!!!

你可能感兴趣的:(#,mybatis)