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

来源:4-5 店铺注册之Service层的实现

慕莱坞445437

2019-11-14

http://img.mukewang.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

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

	<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
0

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程