在MyBatis中,可以使用columnPrefix属性来设置列名的前缀。这在处理复杂的数据结构,例如嵌套对象或者关联表查询时非常有用。
具体配置方法如下:
<resultMap id="userResultMap" type="User">
<id column="id" property="id"/>
<result column="user_name" property="name"/>
<result column="user_age" property="age"/>
</resultMap>
<select id="getUser" resultMap="userResultMap" >
SELECT id, user_name, user_age
FROM users
</select>
这样,在查询结果映射到User对象时,列名会自动添加前缀,例如结果集中的"user_name"列会映射到User对象的"name"属性。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:columnprefix在mybatis中的性能影响