请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

shopserviceTest设置shop.setShopCategory(shopCategory);出错

https://img1.sycdn.imooc.com//szimg/5dcccf1109f0bd9717890446.jpg

public class ShopServiceTest extends BaseTest {
   @Autowired
   private ShopService shopService;

   @Test
   public void testAddShop() throws FileNotFoundException {
       Shop shop = new Shop();
       PersonInfo owner = new PersonInfo();
       Area area = new Area();
       ShopCategory shopCategory = new ShopCategory();
       owner.setUserId(2L);
       area.setAreaId(2);
       shopCategory.setShopCategoryId(1L);
       shop.setOwner(owner);
       shop.setArea(area);
       shop.setShopCategory(shopCategory);
       shop.setShopName("十八碗2");
       shop.setShopDesc("test1");
       shop.setShopAddr("test1");
       shop.setPhone("1233240");
       shop.setCreateTime(new Date());
       shop.setEnableStatus(ShopStateEnum.CHECK.getState());
       shop.setAdvice("审核中");
       File shopImg = new File("E:/Pro/testpro/img/achang.jpg");
       InputStream is = new FileInputStream(shopImg);
       ShopExecution se = shopService.addShop(shop,is,shopImg.getName());
       assertEquals(ShopStateEnum.CHECK.getState(),se.getState());
   }
}

添加店铺设置  shop.setShopCategory(shopCategory);提示nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'shop_Category' in 'field list',shopCategory作为一个ShopCategory类的对象设置,但shop数据库中是没有的,所以出错了但不知道怎么解决

正在回答

插入代码

1回答

翔仔 2019-11-15 00:30:05

同学好,需要你检查Shop.java里面是不是有个field叫做shop_Category了?这是不对的,视频里面是shopCategory;如果不是这个问题,看看ShopDao.xml里面是不是定义了shop_Category这个东西,这样解析肯定报错,因为数据库没有这个字段

1
2
3
4
5
6
7
8
9
10
11
12
13
<insert id="insertShop" useGeneratedKeys="true" keyColumn="shop_id"
    keyProperty="shopId">
    INSERT INTO
    tb_shop(owner_id, area_id, shop_category_id,
    shop_name, shop_desc, shop_addr,
    phone, shop_img, priority,
    create_time, last_edit_time, enable_status,
    advice)
    VALUES
    (#{owner.userId},#{area.areaId},#{shopCategory.shopCategoryId},#{shopName},
    #{shopDesc},#{shopAddr},#{phone},#{shopImg},#{priority},
    #{createTime},#{lastEditTime}, #{enableStatus},#{advice})
</insert>


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号