一对多时,遇到了一点问题,现将正确的应对关系记录下,以免下次再花费很长时间拍错。
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>