mybatis映射文件配置-1对多

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 <mapper namespace="com.echo.digital.beans.TbTypeMapper">
 6 
 7     <resultMap id="TbTypeResultMap" type="com.echo.digital.beans.TbType">
 8         <id column="type_id" property="typeId" javaType="java.lang.Integer"></id>
 9         <result column="type_name" property="typeName" javaType="java.lang.String"></result>
10         <result  column="type_img" property="typeImg" javaType="java.lang.String"></result>
11         <collection property="brands" ofType="com.echo.digital.beans.TbBrand">
12             <id column="brand_id" property="brandId" javaType="java.lang.Integer"></id>
13             <result column="brand_name" property="brandName" javaType="java.lang.String"></result>
14         </collection>
15     </resultMap>
16 
17     <select id="findType" resultMap="TbTypeResultMap">
18         select type_name,type_img,brand_name from tb_type
19     </select>
20 
21     <select id="findBrand" resultMap="TbTypeResultMap">
22         select brand_name from tb_type t join tb_brand b on t.type_id=b.brand_type_id
23         and t.type_name=#{typeName}
24     </select>
25 
26 </mapper>
多对一:用association标签
历经苦难而不厌,此乃阿修罗之道。
原文地址:https://www.cnblogs.com/echo1314/p/10192665.html