1、目的
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.7</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<bean id="inventoryDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="username" value="${jdbc.inventory.username}" />
<property name="password" value="${jdbc.inventory.password}" />
<property name="driverClassName" value="${jdbc.common.driverClassName}" />
<property name="url" value="${jdbc.inventory.url}" />
<property name="maxActive" value="${jdbc.inventory.maximumConnectionCount}"/>
<property name="initialSize" value="${jdbc.inventory.minimumConnectionCount}"/>
<property name="minIdle" value="${jdbc.inventory.minimumConnectionCount}"/>
# inventory
jdbc.inventory.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST ...
jdbc.inventory.username=global_app
jdbc.inventory.password=jReSebMb9Finw
jdbc.inventory.maximumConnectionCount=10
jdbc.inventory.minimumConnectionCount=2
jdbc.inventory.houseKeepingTestSql=select sysdate from DUAL
jdbc.inventory.readonly.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST...
public interface InventoryDao {
List<Inventory> getInventoryBySkuId(@Param("skuId") String skuId);
List<Inventory> getInventoryBySkuIdFromYZ(@Param("skuId") String skuId);
}
<mapper namespace="com.netease.qa.dao.InventoryDao">
<select id="getInventoryBySkuId" parameterType="String" resultMap="inventoryMap">
SELECT *
FROM GLOBAL_PRODUCT.TB_INVENTORY
WHERE SKU_Id =#{skuId}
</select>
</mapper>
public class ShadowTest extends BaseDubboTest {
@Resource
private StoreForOnlineFacade storeForOnlineFacade;
@Resource
private InventoryDao inventoryDao; //依赖注入
Long goodsId = 59081265L;
String skuId = "59081265-ecc4090b639c47f89b453980923afb8e";
@Test
public void shadowTest_trace() throws InvException {
List resultList = storeForOnlineFacade.queryInvBySkuIds(skuId);
Assert.assertNotNull(resultList);
Assert.assertTrue(resultList.get(0).getStore().equals(inventoryDao.getInventoryBySkuId(skuId).get(0).getStore())); //dao调用
}
网易云新用户大礼包:https://www.163yun.com/gift
本文来自网易实践者社区,经作者陈伟授权发布。