一对多时,遇到了一点问题,现将正确的应对关系记录下,以免下次再花费很长时间拍错。
mybatis 映射文件,若属性是一个集合,使用 collection
<collection property="books" ofType="Book">
property="books" :对应实体的属性名
ofType="Book" :该属性名的类型
如下是Book类 与数据库的对应关系。
<id property="id" column="bid"/> <result property="bname" column="bname"/>
<result property="bprice" column="bprice"/>
<result property="bathor" column="bathor"/>
<result property="icreate_time" column="icreate_time"/>
</collection>

本文详细介绍了在MyBatis中如何正确处理一对多关系的集合映射,包括使用collection元素进行配置的方法,以及Book类与数据库字段的具体对应关系。

被折叠的 条评论
为什么被折叠?



