新增店铺出错,好像是数据传不到ShopDao
来源:4-1 Dao层之新增店铺
怪味豆9781880
2020-02-19
ShopDaoTest.java:
package com.imooc.o2o.dao;
import static org.junit.Assert.assertEquals;
import java.util.Date;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.imooc.o2o.BaseTest;
import com.imooc.o2o.entity.Area;
import com.imooc.o2o.entity.PersonInfo;
import com.imooc.o2o.entity.Shop;
import com.imooc.o2o.entity.ShopCategory;
public class ShopDaoTest extends BaseTest{
@Autowired
private ShopDao shopDao;
@Test
public void testInsertShop() {
Shop shop = new Shop();
PersonInfo owner = new PersonInfo();
Area area = new Area();
ShopCategory shopCategory = new ShopCategory();
owner.setUserId(1L);
area.setAreaId(123);
shopCategory.setShopCategoryId(1L);
shop.setOwner(owner);
shop.setArea(area);
shop.setShopCategory(shopCategory);
shop.setShopName(“测试店铺”);
shop.setPriority(0);
shop.setShopDesc(“test”);
shop.setShopAddr(“test”);
shop.setPhone(“test”);
shop.setShopImg(“test”);
shop.setCreateTime(new Date());
shop.setLastEditTime(null);
shop.setEnableAtatus(1);
shop.setAdvice(“审核中”);
int effectedNum = shopDao.insertShop(shop);
assertEquals(1,effectedNum);
}
}
ShopDao.xml :<?xml version="1.0" encoding="UTF-8"?>
控制台为:二月 19, 2020 10:16:57 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getDefaultTestExecutionListenerClassNames
信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
二月 19, 2020 10:16:57 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners
信息: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@60f82f98, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@35f983a6, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@7f690630, org.springframework.test.context.support.DirtiesContextTestExecutionListener@edf4efb, org.springframework.test.context.transaction.TransactionalTestExecutionListener@2f7a2457, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@566776ad]
二月 19, 2020 10:16:57 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring/spring-dao.xml]
二月 19, 2020 10:16:57 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring/spring-service.xml]
二月 19, 2020 10:16:57 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.GenericApplicationContext@458ad742: startup date [Wed Feb 19 22:16:57 CST 2020]; root of context hierarchy
二月 19, 2020 10:16:57 下午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
二月 19, 2020 10:16:58 下午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
二月 19, 2020 10:16:59 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool… com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 3, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 3000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge0w5a8q114sv16pbdgk|42e99e4a, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge0w5a8q114sv16pbdgk|42e99e4a, idleConnectionTestPeriod -> 60, initialPoolSize -> 5, jdbcUrl -> jdbc:mysql://localhost:3306/maven?useUnicode=true&characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 100, maxStatementsPerConnection -> 3, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> select1, properties -> {user=**, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
2020-02-19 22:16:59.719 [main] DEBUG com.imooc.o2o.dao.ShopDao.insertShop - ==> Preparing: INSERT INTO tb_shop(owner_id,area_id,shop_categroy_id,shop_name,shop_desc,shop_addr,phone,shop_img,priority,create_time, last_edit_time,enable_status,advice) VALUES (?,?,?,?,?,?,?, ?,?,?,?,?,?)
2回答
-
同学好,我看问题是
There is no getter for property named 'useId' in 'class com.imooc.o2o.entity.PersonInfo' a
你的PersonInfo 里面没有userId的setter
需要加上才行
public Long getUserId() { return userId; } public void setUserId(Long userId) { this.userId = userId; }
00 -
怪味豆9781880
提问者
2020-02-20
问题已解决,是书写错误,userId错写为useId
00
相似问题