如题,*Mapper.xml 里面我是这么写的,
<resultMap id="BaseResultMap" type="com.steam.entity.Goods" >
<id column="gid" property="gid" />
<result column="gname" property="gname" jdbcType="VARCHAR" />
<result column="desc" property="desc" jdbcType="VARCHAR" />
<result column="price" property="price" jdbcType="INTEGER"/>
<result column="status" property="status" jdbcType="INTEGER" />
<result column="pname" property="pname" jdbcType="VARCHAR" />
<result column="type_name" property="typeName" jdbcType="VARCHAR" />
<result column="pid" property="pid" />
<result column="tid" property="tid"/>
<result column="model_number" property="modelNumber" jdbcType="VARCHAR" />
<result column="goods_bianma" property="goodsBianma" jdbcType="VARCHAR" />
<result column="type_name" property="typeName" jdbcType="VARCHAR" />
<!-- <result column="goods_img" property="goodsImg" jdbcType="VARCHAR" /> -->
</resultMap>
<select id="goodsListAll" resultMap="BaseResultMap">
select a.*,b.type_name,c.pname from tb_goods a left join tb_product b on a.tid=b.tid left join tb_brand c on a.pid=c.pid
</select>
Controller层
@RequestMapping(value="/goodsList",method=RequestMethod.GET)
public String goodsListAll(HttpServletRequest request){
List<Goods> glist = this.goodsService.goodsListAll();
request.setAttribute("glist", glist);
return "goods/goods_list";
}
jsp页面:
<c:forEach items="${glist}" var="g">
<tr class="text-c">
<td>${g.gid}</td>
<td>${g.gname}</td>
<td>${g.desc}</td>
<td>${g.plist.typeName}</td>
<td>${g.price}</td>
<td>${g.blist.pname}</td>
<td>${g.modelNumber}</td>
<td>${g.goodsBianma}</td>
</tr>
实体类
public class Goods {
private Long gid;
private String gname;
private String desc;
private Double price;
private Integer status;
private Long pid;
private Long tid;
private String modelNumber;
private String goodsBianma;
private List<Product> plist;
private List<Brand> blist;
还有两个实体类就是Product和Brand,不多说了,现在死活就是不好使,求各位大神帮忙看看
自己重新定义一个实体类 吧查询结果放到这个实体类中,实体类包含所有的查询结果的字段
https://www.cnblogs.com/xdp-gacl/p/4264440.html
一个更好的办法,我发现你这关联表所查字段并不多。例如这个b和c表都只关联了一个字段,而a表字段全要,那么可以在a表的映射实体类里面加上b表和c表所需的这个2个字段就可以了。
Goods类是否定义了多个实例的所有字段,第二,字段不能重复名字。
http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html
其实早该解决的玩意,最后还是重启了一下eclipse,然后所有问题都不见了! 看来是eclipse 缓存的问题啊~~~~希望大家以后都注意一下这个不是问题的问题