mybatis解决数据库表列明与实体不一致问题

来源:互联网 发布:软件性质 编辑:程序博客网 时间:2024/05/19 23:58
问题提出:数据库表的列明一般是t_userid,t_username ...
                    而我们定义的实体属性时不能带下划线。这样使我们在使用mybatis查询时查不出来信息。


解决方案:这个是一张表我们可以加resultMap
<mapper namespace="com.myspotlight.entity.SingerMapper">
这里面的Singer使用的时候已经在mybatis-config.xml进行了配置
<resultMap type="Singer" id="singerResultMap">
这两个的区别 id是主键
<id column="s_id" property="sId" />
<result column="s_id" property="sId" />
<result column="s_name" property="sName" />
<result column="s_sex" property="sSex" />
<result column="s_birthday" property="sBirthday" />
<result column="s_type" property="sType" />
<result column="s_history" property="sHistory" />
<result column="s_achievement" property="sAchievement" />
<result column="s_message" property="sMessage" />
<result column="s_remark" property="sRemark" />
</resultMap>
resultMap 解决了列明和属性名不匹配的问题
<select id="selectAllSinger" parameterType="Singer" resultMap="singerResultMap">
SELECT * FROM myspotlight_singer
</select>
</mapper> 
阅读全文
0 0