老师帮忙看一下

来源:4-3 ResultMap结果映射

dobe001

2020-02-23 23:49:30

<resultMap id="rmGoods" type="com.imooc.mybatis.dto.GoodsDTO">
    <id property="goods.goodsId" column="goods_id"></id>
    <result property="goods.title" column="title"></result>
    <result property="goods.originalCost" column="original_cost"></result>
    <result property="goods.currentPrice" column="current_price"></result>
    <result property="goods.discount" column="discount"></result>
    <result property="goods.isFreeDelivery" column="is_free_delivery"></result>
    <result property="goods.categoryID" column="category_id"></result>
    <result property="categoryName" column="category_name"></result>
    <result property="test" column="test"></result>
</resultMap>
<select id="selectGoodsDTO" resultMap="rmGoods">
    select g.* , c.category_name ,'1' as test from t_goods g , t_category c
    where g.category_id = c.category_id
</select>
package com.imooc.mybatis.dto;

import com.imooc.mybatis.entity.Goods;

public class GoodsDTO {
    private Goods goods = new Goods();
    private String categoryName;
    private String test;

    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}
@Test
public void testSelectGoodsDTO() throws Exception {
    SqlSession session = null;
    try{
        session = MyBatisUtils.openSession();
        List<GoodsDTO> list = session.selectList("goods.selectGoodsDTO");
        for (GoodsDTO g : list) {
            System.out.println(g.getGoods().getTitle());
        }
    }catch(Exception e){
        throw e;
    }finally{
        MyBatisUtils.closeSession(session);
    }

http://img.mukewang.com/climg/5e529ee10966201115300220.jpg

http://img.mukewang.com/climg/5e529ef309923e3f11750053.jpg

又是List那儿出了问题,哪边参数错了

写回答

1回答

好帮手慕酷酷

2020-02-24

同学你好,根据报错信息,表示不能设置属性categoryID,具体如下:

http://img.mukewang.com/climg/5e536be20995204910230107.jpg

建议同学检查Goods实体类中,分类编号是否为categoryID,例如老师这里分类编号为categoryId,小写的d,则映射时也应该是categoryId,具体如下:

http://img.mukewang.com/climg/5e536c5309a10f7704030204.jpg

http://img.mukewang.com/climg/5e536bb1092bdc0407490159.jpg

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

0 学习 · 8016 问题

查看课程