实战SSM_O2O商铺_17【商铺编辑】Dao层开发
生活随笔
收集整理的這篇文章主要介紹了
实战SSM_O2O商铺_17【商铺编辑】Dao层开发
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 概述
- ShopDao接口
- ShopDao映射文件
- 單元測試
- Github地址
概述
ShopDao接口
com.artisan.o2o.dao.ShopDao.java 新增查詢接口
/*** * * @Title: selectShopById* * @Description: 根據shopId查詢shop* * @param shopId* @return* * @return: Shop*/Shop selectShopById(long shopId);ShopDao映射文件
/o2o/src/main/resources/mapper/ShopDao.xml
<resultMap id="shopMap" type="com.artisan.o2o.entity.Shop"><id column="shop_id" property="shopId"/><!-- property對應實體類中的屬性名 column 對應庫表中的字段名 --><result column="shop_name" property="shopName"/><result column="shop_desc" property="shopDesc"/><result column="shop_addr" property="shopAddr"/><result column="phone" property="phone"/><result column="shop_img" property="shopImg"/><result column="priority" property="priority"/><result column="create_time" property="createTime"/><result column="last_edit_time" property="lastEditTime"/><result column="enable_status" property="enableStatus"/><result column="advice" property="advice"/><!-- 復合對象 --><!-- property對應實體類中的屬性名 column 對應庫表中的字段名 --><association property="owner" column="owner_id" javaType="com.artisan.o2o.entity.PersonInfo"><id column="user_id" property="userId"/><result column="name" property="name"/></association><association property="area" column="area_id" javaType="com.artisan.o2o.entity.Area"><id column="area_id" property="areaId"/><result column="area_name" property="areaName"/></association><association property="shopCategory" column="shop_category_id" javaType="com.artisan.o2o.entity.ShopCategory"><id column="shop_category_id" property="shopCategoryId"/><result column="shop_category_name" property="shopCategoryName"/></association></resultMap>單元測試
@Testpublic void testSelectShopById() {Shop shop = shopDao.selectShopById(30L);Assert.assertNotNull(shop);Assert.assertEquals("優樂美", shop.getShopName());Assert.assertEquals("北京", shop.getArea().getAreaName());Assert.assertEquals("奶茶", shop.getShopCategory().getShopCategoryName());System.out.println(shop.toString());}單元測試運行通過, 控制臺的日志輸出如下:
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10] Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@36cda2c2] was not registered for synchronization because synchronization is not active 六月 02, 2018 5:29:37 下午 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 -> 1hge9g69v1hxv2gi151wrqu|73e22a3d, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge9g69v1hxv2gi151wrqu|73e22a3d, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/o2o?useUnicode=true&characterEncoding=utf8, 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 ] JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@416c58f5] will not be managed by Spring ==> Preparing: SELECT s.shop_id, s.shop_name, s.shop_desc, s.shop_addr, s.phone, s.shop_img, s.priority, s.create_time, s.last_edit_time, s.enable_status, s.advice, a.area_id, a.area_name, sc.shop_category_id, sc.shop_category_name FROM tb_shop s, tb_area a, tb_shop_category sc WHERE s.area_id = a.area_id AND s.shop_category_id = sc.shop_category_id AND s.shop_id = ? ==> Parameters: 30(Long) <== Columns: shop_id, shop_name, shop_desc, shop_addr, phone, shop_img, priority, create_time, last_edit_time, enable_status, advice, area_id, area_name, shop_category_id, shop_category_name <== Row: 30, 優樂美, 優樂美奶茶店, 復興街, 123456, \upload\item\shopImage\30\2018053001010899137.png, null, 2018-05-30 01:01:07.0, 2018-05-30 01:01:07.0, 0, null, 1, 北京, 3, 奶茶 <== Total: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@36cda2c2] Shop [shopId=30, shopName=優樂美, shopDesc=優樂美奶茶店, shopAddr=復興街, phone=123456, shopImg=\upload\item\shopImage\30\2018053001010899137.png, priority=null, createTime=Wed May 30 01:01:07 BOT 2018, lastEditTime=Wed May 30 01:01:07 BOT 2018, enableStatus=0, advice=null, owner=null, area=Area [areaId=1, areaName=北京, areaDesc=null, priority=null, createTime=null, lastEditTime=null], shopCategory=ShopCategory [shopCategoryId=3, shopCategoryName=奶茶, shopCategoryDesc=null, shopCategoryImg=null, priority=null, createTime=null, lastEditTime=null, parent=null]] 六月 02, 2018 5:29:38 下午 org.springframework.context.support.GenericApplicationContext doClose 信息: Closing org.springframework.context.support.GenericApplicationContext@45afc369: startup date [Sat Jun 02 17:29:33 BOT 2018]; root of context hierarchy庫表中的數據
Github地址
代碼地址: https://github.com/yangshangwei/o2o
總結
以上是生活随笔為你收集整理的实战SSM_O2O商铺_17【商铺编辑】Dao层开发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle-使用切片删除的方式清理非分
- 下一篇: 实战SSM_O2O商铺_18【商铺编辑】