<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.southwind.repository.CustomerRepository"><!-- 多对多的查询 --><selectid="findById"parameterType="int"resultMap="customerMap">
select c.id cid,c.name cname,g.id gid,g.name gname
from customer as c,goods as g,customer_goods as cg
where c.id = #{id} and c.id = cg.cid and g.id = cg.gid
</select><resultMapid="customerMap"type="com.southwind.entity.Customer"><idcolumn="cid"property="id"></id><resultcolumn="cname"property="name"></result><collectionproperty="goods"ofType="com.southwind.entity.Goods"><idcolumn="gid"property="id"/><resultcolumn="gname"property="name"/></collection></resultMap></mapper>
<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.southwind.repository.GoodsRepository"><!-- 多对多的关系查询 --><selectid="findById"parameterType="int"resultMap="goodsMap">
select c.id cid,c.name cname,g.id gid,g.name gname
from customer as c,goods as g,customer_goods as cg
where g.id = #{id} and c.id = cg.cid and g.id = cg.gid
</select><resultMapid="goodsMap"type="com.southwind.entity.Goods"><idcolumn="gid"property="id"></id><resultcolumn="gname"property="name"></result><collectionproperty="customers"ofType="com.southwind.entity.Customer"><idcolumn="cid"property="id"/><resultcolumn="cname"property="name"/></collection></resultMap></mapper>