老师为啥我这里会报错呢?
八月 11, 2019 11:21:48 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager 信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 2, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 10000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge1hia4z5j8nv7h1hwm|79e2c065, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge1hia4z5j8nv7h1hwm|79e2c065, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/o2o?useSSL=false&serverTimezone=Hongkong&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&allowMultiQueries=true, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ] Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 2019-08-11 11:21:48.729 [main] DEBUG com.mason.o2o.dao.ShopDao.updateShop - ==> Preparing: update tb_shop SET shop_desc=?, shop_addr=?, last_edit_time=? where shop_id=? 2019-08-11 11:21:48.762 [main] DEBUG com.mason.o2o.dao.ShopDao.updateShop - ==> Parameters: 测试描述111(String), 测试地址(String), 2019-08-11 11:21:48.449(Timestamp), 1(Long) 2019-08-11 11:21:48.764 [main] DEBUG com.mason.o2o.dao.ShopDao.updateShop - <== Updates: 0 java.lang.AssertionError: Expected :1 Actual :0 <Click to see difference> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit.Assert.assertEquals(Assert.java:645) at org.junit.Assert.assertEquals(Assert.java:631) at com.mason.o2o.dao.ShopDaoTest.testUpdateShop(ShopDaoTest.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 八月 11, 2019 11:21:48 上午 org.springframework.context.support.GenericApplicationContext doClose 信息: Closing org.springframework.context.support.GenericApplicationContext@8bd1b6a: startup date [Sun Aug 11 11:21:47 CST 2019]; root of context hierarchy
package com.mason.o2o.dao; import com.mason.o2o.BaseTest; import com.mason.o2o.entity.Shop; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; import static org.junit.Assert.assertEquals; public class ShopDaoTest extends BaseTest { @Autowired private ShopDao shopDao; // public void testInsertShop() { // Shop shop = new Shop(); // PersonInfo owner = new PersonInfo(); // Area area = new Area(); // ShopCategory shopCategory = new ShopCategory(); // owner.setUserId(1L); // area.setAreaId(2); // shopCategory.setShopCategoryId(1L); // shop.setOwner(owner); // shop.setShopCategory(shopCategory); // shop.setShopName("测试的店铺"); // shop.setShopDesc("test"); // shop.setShopAddr("test"); // shop.setPhone("test"); // shop.setShopImg("test"); // shop.setCreateTime(new Date()); // shop.setEnableStatus(1); // shop.setAdvice("审核中"); // int effectedNum = shopDao.insertShop(shop); // assertEquals(1, effectedNum); // } @Test public void testUpdateShop() { Shop shop = new Shop(); shop.setShopId(1L); shop.setShopDesc("测试描述111"); shop.setShopAddr("测试地址"); shop.setLastEditTime(new Date()); int effectedNum = shopDao.updateShop(shop); assertEquals(1, effectedNum); } }
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.mason.o2o.dao.ShopDao"> <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> <update id="updateShop" parameterType="com.mason.o2o.entity.Shop"> update tb_shop <set> <if test="shopName!=null">shop_name=#{shopName},</if> <if test="shopDesc!=null">shop_desc=#{shopDesc},</if> <if test="shopAddr!=null">shop_addr=#{shopAddr},</if> <if test="phone!=null">phone=#{phone},</if> <if test="shopImg!=null">shop_img=#{shopImg},</if> <if test="priority!=null">priority=#{priority},</if> <if test="lastEditTime!=null">last_edit_time=#{lastEditTime},</if> <if test="enableStatus!=null">enable_status=#{enableStatus},</if> <if test="advice!=null">advice=#{advice},</if> <if test="area!=null">area_id=#{area.areaId},</if> <if test="shopCategory!=null">shop_category_id=#{shopCategory.shopCategoryId}</if> </set> where shop_id=#{shopId} </update> </mapper>
package com.mason.o2o.dao; import com.mason.o2o.entity.Shop; public interface ShopDao{ /** * 新增店铺 * @param shop * @return */ int insertShop(Shop shop); /** * 更新店铺信息 * @param shop * @return */ int updateShop(Shop shop); }
13
收起
正在回答
3回答
同学你好。这里由于被<set></set>包裹,语句最后一个“,”会自动忽略不计,所以不会报错哦~,祝学习愉快~
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星