redis作為mybatis的二級緩存


redis作為二級緩存服務器,來替代mybatis的二級緩存,至於二級緩存有什么缺點我想大家都懂吧,

 1  [service] 2016-08-31 21:01:32,912 - com.erp.dao.TestMybatisMapper.selectByPrimaryKey -19446 [http-nio-8080-exec-6] DEBUG com.erp.dao.TestMybatisMapper.selectByPrimaryKey  - ==>  Preparing: select TID, TNAME from TESTMYBATIS where TID = ? 
 2     [service] 2016-08-31 21:01:32,912 - com.erp.dao.TestMybatisMapper.selectByPrimaryKey -19446 [http-nio-8080-exec-6] DEBUG com.erp.dao.TestMybatisMapper.selectByPrimaryKey  - ==> Parameters: 6(BigDecimal)
 3     [service] 2016-08-31 21:01:32,944 - com.erp.dao.TestMybatisMapper.selectByPrimaryKey -19478 [http-nio-8080-exec-6] DEBUG com.erp.dao.TestMybatisMapper.selectByPrimaryKey  - <==      Total: 1
 4     [service] 2016-08-31 21:01:32,945 - com.erp.utils.redcache.RedisCache -19479 [http-nio-8080-exec-6] DEBUG com.erp.utils.redcache.RedisCache  - >>>>>>>>>>>>>>>>>>>>>>>>putObject:1716629384:864926724:com.erp.dao.TestMybatisMapper.selectByPrimaryKey:0:2147483647:select 
 5      
 6     TID, TNAME
 7    
 8     from TESTMYBATIS
 9     where TID = ?:6=[TestMybatis [tid=6, tname=asd]]
10     [service] 2016-08-31 21:01:32,946 - org.mybatis.spring.SqlSessionUtils -19480 [http-nio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils  - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a766442]
11     [service] 2016-08-31 21:01:32,946 - org.springframework.jdbc.datasource.DataSourceUtils -19480 [http-nio-8080-exec-6] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Returning JDBC Connection to DataSource
12     TestMybatis [tid=6, tname=asd]
13 [service] 2016-08-31 21:01:32,947 - org.springframework.web.servlet.DispatcherServlet -19481 [http-nio-8080-exec-6] DEBUG org.springframework.web.servlet.DispatcherServlet  - Null ModelAndView returned to DispatcherServlet with name 'springMVC': assuming HandlerAdapter completed request handling
 1   [service] 2016-08-31 21:12:33,225 - org.springframework.web.servlet.DispatcherServlet -23378 [http-nio-8080-exec-10] DEBUG org.springframework.web.servlet.DispatcherServlet  - Last-Modified value for [/mybatisRedis/s] is: -1
 2     [service] 2016-08-31 21:12:33,243 - org.mybatis.spring.SqlSessionUtils -23396 [http-nio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils  - Creating a new SqlSession
 3     [service] 2016-08-31 21:12:33,251 - org.mybatis.spring.SqlSessionUtils -23404 [http-nio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils  - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@377e5451] was not registered for synchronization because synchronization is not active
 4     [service] 2016-08-31 21:12:33,477 - com.erp.utils.redcache.RedisCache -23630 [http-nio-8080-exec-10] DEBUG com.erp.utils.redcache.RedisCache  - >>>>>>>>>>>>>>>>>>>>>>>>getObject:1716629384:864926724:com.erp.dao.TestMybatisMapper.selectByPrimaryKey:0:2147483647:select 
 5      
 6     TID, TNAME
 7    
 8     from TESTMYBATIS
 9     where TID = ?:6=[TestMybatis [tid=6, tname=asd]]
10     [service] 2016-08-31 21:12:33,477 - com.erp.dao.TestMybatisMapper -23630 [http-nio-8080-exec-10] DEBUG com.erp.dao.TestMybatisMapper  - Cache Hit Ratio [com.erp.dao.TestMybatisMapper]: 1.0
11     [service] 2016-08-31 21:12:33,477 - org.mybatis.spring.SqlSessionUtils -23630 [http-nio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils  - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@377e5451]
12     TestMybatis [tid=6, tname=asd]
13 [service] 2016-08-31 21:12:33,482 - org.springframework.web.servlet.DispatcherServlet -23635 [http-nio-8080-exec-10] DEBUG org.springframework.web.servlet.DispatcherServlet  - Null ModelAndView returned to DispatcherServlet with name 'springMVC': assuming HandlerAdapter completed request handling
14     [service] 2016-08-31 21:12:33,482 - org.springframework.web.servlet.DispatcherServlet -23635 [http-nio-8080-exec-10] DEBUG org.springframework.web.servlet.DispatcherServlet  - Successfully completed request

兩次都是查詢數據庫里的數據,只不過第一次在查詢之前我們先插入了一條數據,更新了緩存,

其實這並不能發揮redis的優勢,更多的redis作為二級緩存服務器使用,實現我們自定義的二級緩存,如何利用號redis實現更加的靈活的實現數據的同步才是最重要的

 1 package com.erp.controller;
 2 
 3 import java.math.BigDecimal;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.web.bind.annotation.RequestMapping;
 7 import org.springframework.web.bind.annotation.RestController;
 8 
 9 import com.erp.dao.TestMybatisMapper;
10 import com.erp.model.TestMybatis;
11 
12 @RestController
13 public class BaseController {
14 
15     @Autowired
16     private TestMybatisMapper testMybatisMapper;
17 
18     @RequestMapping("s")
19     public void test() {
20         TestMybatis test = new TestMybatis();
21         BigDecimal b = new BigDecimal("6");
22         // test.setTid(b);
23         // test.setTname("asd");
24         // this.testMybatisMapper.insert(test);
25         TestMybatis testMybatis = this.testMybatisMapper.selectByPrimaryKey(b);
26         System.out.println(testMybatis.toString());
27     }
28 
29 }

這里我們需要注意一下我們好像不能使用junit和spring的那個test測試類,因為我們在那個好像每次都是從新加載的配置文件導致了每次都是重啟的服務器一樣

 1 package com.erp.model;
 2 
 3 import java.io.Serializable;
 4 import java.math.BigDecimal;
 5 
 6 public class TestMybatis implements Serializable{
 7     /**
 8      * 
 9      */
10     private static final long serialVersionUID = 1L;
11 
12     private BigDecimal tid;
13 
14     private String tname;
15 
16     public BigDecimal getTid() {
17         return tid;
18     }
19 
20     public void setTid(BigDecimal tid) {
21         this.tid = tid;
22     }
23 
24     public String getTname() {
25         return tname;
26     }
27 
28     public void setTname(String tname) {
29         this.tname = tname == null ? null : tname.trim();
30     }
31 
32     @Override
33     public String toString() {
34         return "TestMybatis [tid=" + tid + ", tname=" + tname + "]";
35     }
36 
37 }
1   <cache type="com.erp.utils.redcache.LoggingRedisCache"/>
 1 package com.erp.utils.redcache;
 2 
 3 import org.apache.ibatis.cache.decorators.LoggingCache;
 4 
 5 public class LoggingRedisCache extends LoggingCache {
 6 
 7     public LoggingRedisCache(String id) {
 8         super(new RedisCache(id));
 9     }
10 
11 }
 1 package com.erp.utils.redcache;
 2 
 3 import org.junit.Test;
 4 
 5 import redis.clients.jedis.Jedis;
 6 import redis.clients.jedis.JedisPool;
 7 import redis.clients.jedis.JedisPoolConfig;
 8 
 9 public class PoolResource {
10 
11     private static String ADDRESS = "localhost";
12     private static int PORT = 6379;
13     private static String PASSWORD = "wang";
14     // 可用連接最大數目
15     // -1 表示不限制
16     private static int MAX_ACTIVE = 1024;
17     // 控制一個pool最多有多少個空閑的jedis實例,默認是8
18     private static int MAX_JEDIS = 200;
19 
20     // 等待的可用連接的最大時間,單位毫秒,默認值為-1,表示永不超時,如果等待超時時間
21     // 則拋出JedisConnectionException
22     // redis.clients.jedis.exceptions.JedisConnectionException: Could not get a
23     // resource from the pool
24     private static int MAX_WAIT = 10000;
25     private static int TIMROUT = 10000;
26 
27     // 在borrow一個jedis實例時,是否提前進行validate操作:true ,得到的jedis實例是可用的;
28     private static boolean TEST_ON_BORROW = true;
29     private static JedisPool jedisPool = null;
30 
31     /**
32      * 初始化連接池
33      */
34     static {
35         JedisPoolConfig config = new JedisPoolConfig();
36         //設置最大的連接數目,注意版本不同方法會有不同
37         config.setMaxTotal(MAX_ACTIVE);
38         config.setMaxIdle(MAX_JEDIS);
39         config.setMaxWaitMillis(MAX_WAIT);
40         config.setTestOnBorrow(TEST_ON_BORROW);
41         jedisPool = new JedisPool(config, ADDRESS, PORT, TIMROUT, PASSWORD);
42     }
43 
44     /**
45      * 獲取Jedis實例
46      * 
47      * @return
48      */
49     // synchronized是Java中的關鍵字,是一種同步鎖。它修飾的對象有以下幾種:
50     // 1. 修飾一個代碼塊,被修飾的代碼塊稱為同步語句塊,其作用的范圍是大括號{}括起來的代碼,作用的對象是調用這個代碼塊的對象;
51     // 2. 修飾一個方法,被修飾的方法稱為同步方法,其作用的范圍是整個方法,作用的對象是調用這個方法的對象;
52     // 3. 修改一個靜態的方法,其作用的范圍是整個靜態方法,作用的對象是這個類的所有對象;
53     // 4. 修改一個類,其作用的范圍是synchronized后面括號括起來的部分,作用主的對象是這個類的所有對象。
54     // 當兩個並發線程訪問同一個對象object中的這個synchronized(this)同步代碼塊時,一個時間內只能有一個線程得到執行。另一個線程必須等待當前線程執行完這個代碼塊以后才能執行該代碼塊。
55 
56     public synchronized static Jedis getJedis() {
57         try {
58             if (jedisPool != null) {
59                 Jedis resource = jedisPool.getResource();
60                 return resource;
61             } else {
62                 return null;
63             }
64         } catch (Exception e) {
65             e.printStackTrace();
66             return null;
67         }
68     }
69 
70     /**
71      * 釋放jedis資源
72      * 
73      * @param jedis
74      */
75     public static void returnResource(final Jedis jedis) {
76         // if (jedis != null) {
77         // jedisPool.returnResource(jedis);
78         // }
79         if (jedis != null) {
80             jedis.close();
81         }
82     }
83 
84     @Test
85     public void testConnect() {
86         for (int i = 0; i < 100; i++) {
87             Jedis jedis = getJedis();
88             System.out.println("Connect");
89         }
90     }
91 }
 1 package com.erp.utils.redcache;
 2 
 3 import java.util.concurrent.locks.ReadWriteLock;
 4 import java.util.concurrent.locks.ReentrantReadWriteLock;
 5 
 6 import org.apache.commons.logging.Log;
 7 import org.apache.commons.logging.LogFactory;
 8 import org.apache.ibatis.cache.Cache;
 9 
10 import redis.clients.jedis.Jedis;
11 
12 /**
13  * 繼承cache接口使用redis自定義實現mybatis的緩存技術
14  * 
15  * @author Administrator
16  *
17  */
18 public class RedisCache implements Cache {
19     private static Log logger = LogFactory.getLog(RedisCache.class);
20     private Jedis redisClient = createClient();
21     /** The ReadWriteLock.讀寫鎖 */
22     private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
23 
24     private String id;
25 
26     public RedisCache(final String id) {
27         if (id == null) {
28             throw new IllegalArgumentException("Cache instances require an ID");
29         }
30         logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>RedisCache:id=" + id);
31         this.id = id;
32     }
33 
34     public String getId() {
35         return this.id;
36     }
37 
38     public int getSize() {
39         return Integer.valueOf(redisClient.dbSize().toString());
40     }
41 
42     public void putObject(Object key, Object value) {
43         logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>putObject:" + key + "=" + value);
44         redisClient.set(SerializeUtil.serialize(key.toString()), SerializeUtil.serialize(value));
45     }
46 
47     public Object getObject(Object key) {
48         Object value = SerializeUtil.unserialize(redisClient.get(SerializeUtil.serialize(key.toString())));
49         logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>getObject:" + key + "=" + value);
50         return value;
51     }
52 
53     public Object removeObject(Object key) {
54         return redisClient.expire(SerializeUtil.serialize(key.toString()), 0);
55     }
56 
57     public void clear() {
58         redisClient.flushDB();
59     }
60 
61     public ReadWriteLock getReadWriteLock() {
62         return readWriteLock;
63     }
64 
65     protected static Jedis createClient() {
66         try {
67             //可以使用默認的config
68             //JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
69             return PoolResource.getJedis();
70         } catch (Exception e) {
71             e.printStackTrace();
72         }
73         throw new RuntimeException("初始化連接池錯誤");
74     }
75 
76 }
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 3 "http://mybatis.org/dtd/mybatis-3-config.dtd">
 4 <configuration>
 5     <settings>
 6         <!-- 這個配置使全局的映射器啟用或禁用緩存 -->
 7         <setting name="cacheEnabled" value="true" />
 8         <!-- 對於未知的SQL查詢,允許返回不同的結果集以達到通用的效果 -->
 9         <setting name="multipleResultSetsEnabled" value="true" />
10         <!-- 配置默認的執行器。SIMPLE 執行器沒有什么特別之處。REUSE 執行器重用預處理語句。BATCH 執行器重用語句和批量更新 -->
11         <setting name="defaultExecutorType" value="REUSE" />
12         <!-- 全局啟用或禁用延遲加載。當禁用時,所有關聯對象都會即時加載。 -->
13         <setting name="lazyLoadingEnabled" value="false" />
14         <setting name="aggressiveLazyLoading" value="true" />
15         <!-- <setting name="enhancementEnabled" value="true"/> -->
16         <!-- 設置超時時間,它決定驅動等待一個數據庫響應的時間。 -->
17         <setting name="defaultStatementTimeout" value="25000" />
18     </settings>
19 </configuration>
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:aop="http://www.springframework.org/schema/aop" 
 6     xmlns:cache="http://www.springframework.org/schema/cache"  
 7     xmlns:mvc="http://www.springframework.org/schema/mvc"
 8     xmlns:tx="http://www.springframework.org/schema/tx"
 9     xsi:schemaLocation="http://www.springframework.org/schema/beans  
10                         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
11                         http://www.springframework.org/schema/context  
12                         http://www.springframework.org/schema/context/spring-context-3.1.xsd  
13                         http://www.springframework.org/schema/tx
14                         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
15                         http://www.springframework.org/schema/aop 
16                         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
17                         http://www.springframework.org/schema/cache 
18                         http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">
19     <!-- 自動掃描 -->
20     <context:component-scan base-package="com" />   
21     <aop:aspectj-autoproxy proxy-target-class="true" />
22 
23     <!-- 引入配置文件 -->
24     <bean id="propertyConfigurer"
25         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
26         <property name="location" value="classpath:jdbc.properties" />
27     </bean>
28 
29     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
30         destroy-method="close">
31         <property name="driverClassName" value="${driver}" />
32         <property name="url" value="${url}" />
33         <property name="username" value="${username}" />
34         <property name="password" value="${password}" />
35         <!-- 初始化連接大小 -->
36         <property name="initialSize" value="${initialSize}"></property>
37         <!-- 連接池最大數量 -->
38         <property name="maxActive" value="${maxActive}"></property>
39         <!-- 連接池最大空閑 -->
40         <property name="maxIdle" value="${maxIdle}"></property>
41         <!-- 連接池最小空閑 -->
42         <property name="minIdle" value="${minIdle}"></property>
43         <!-- 獲取連接最大等待時間 -->
44         <property name="maxWait" value="${maxWait}"></property>
45     </bean>
46 
47     <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
48     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
49         <property name="dataSource" ref="dataSource" />
50         <property name="mapperLocations" value="classpath:com/erp/mapping/*.xml"/>
51         <property name="configLocation" value="classpath:mybatis-config.xml" />
52     </bean>
53 
54     <!-- DAO接口所在包名(sql映射類所對應的方法接口所在的位置),Spring會自動查找其下的類 -->
55     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
56         <property name="basePackage" value="com.erp.dao" />
57         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
58     </bean>
59 
60     <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->
61     <bean id="transactionManager"
62         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
63         <property name="dataSource" ref="dataSource" />
64     </bean>
65 
66     <!--通過注解管理事物@Transactional -->
67     <tx:annotation-driven transaction-manager="transactionManager" />
68 
69 </beans>
  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3     <modelVersion>4.0.0</modelVersion>
  4     <groupId>jdu</groupId>
  5     <artifactId>mybatisRedis</artifactId>
  6     <packaging>war</packaging>
  7     <version>0.0.1-SNAPSHOT</version>
  8     <name>mybatisRedis Maven Webapp</name>
  9     <url>http://maven.apache.org</url>
 10     <properties>
 11         <!-- spring版本號 -->
 12         <spring.version>4.0.2.RELEASE</spring.version>
 13         <!-- mybatis版本號 -->
 14         <mybatis.version>3.2.6</mybatis.version>
 15         <!-- log4j日志文件管理包版本 -->
 16         <slf4j.version>1.7.7</slf4j.version>
 17         <log4j.version>1.2.17</log4j.version>
 18     </properties>
 19 
 20     <dependencies>
 21         <dependency>
 22             <groupId>junit</groupId>
 23             <artifactId>junit</artifactId>
 24             <version>4.11</version>
 25             <!-- 表示開發的時候引入,發布的時候不會加載此包 -->
 26             <scope>test</scope>
 27         </dependency>
 28         <!-- spring核心包 -->
 29         <dependency>
 30             <groupId>org.springframework</groupId>
 31             <artifactId>spring-core</artifactId>
 32             <version>${spring.version}</version>
 33         </dependency>
 34 
 35         <dependency>
 36             <groupId>org.springframework</groupId>
 37             <artifactId>spring-web</artifactId>
 38             <version>${spring.version}</version>
 39         </dependency>
 40         <dependency>
 41             <groupId>org.springframework</groupId>
 42             <artifactId>spring-oxm</artifactId>
 43             <version>${spring.version}</version>
 44         </dependency>
 45         <dependency>
 46             <groupId>org.springframework</groupId>
 47             <artifactId>spring-tx</artifactId>
 48             <version>${spring.version}</version>
 49         </dependency>
 50 
 51         <dependency>
 52             <groupId>org.springframework</groupId>
 53             <artifactId>spring-jdbc</artifactId>
 54             <version>${spring.version}</version>
 55         </dependency>
 56 
 57         <dependency>
 58             <groupId>org.springframework</groupId>
 59             <artifactId>spring-webmvc</artifactId>
 60             <version>${spring.version}</version>
 61         </dependency>
 62         <dependency>
 63             <groupId>org.springframework</groupId>
 64             <artifactId>spring-aop</artifactId>
 65             <version>${spring.version}</version>
 66         </dependency>
 67         <!-- 使用Spring的aop時需要使用到aspectjweaver包,所以需要添加aspectjweaver包 -->
 68         <dependency>
 69             <groupId>org.aspectj</groupId>
 70             <artifactId>aspectjrt</artifactId>
 71             <version>1.8.2</version>
 72         </dependency>
 73         <dependency>
 74             <groupId>org.aspectj</groupId>
 75             <artifactId>aspectjweaver</artifactId>
 76             <version>1.8.4</version>
 77         </dependency>
 78         <dependency>
 79             <groupId>org.springframework</groupId>
 80             <artifactId>spring-context-support</artifactId>
 81             <version>${spring.version}</version>
 82         </dependency>
 83 
 84         <dependency>
 85             <groupId>org.springframework</groupId>
 86             <artifactId>spring-test</artifactId>
 87             <version>${spring.version}</version>
 88             <!-- 表示開發的時候引入,發布的時候不會加載此包 -->
 89             <scope>test</scope>
 90         </dependency>
 91         <!-- mybatis核心包 -->
 92         <dependency>
 93             <groupId>org.mybatis</groupId>
 94             <artifactId>mybatis</artifactId>
 95             <version>${mybatis.version}</version>
 96         </dependency>
 97         <!-- mybatis/spring包 -->
 98         <dependency>
 99             <groupId>org.mybatis</groupId>
100             <artifactId>mybatis-spring</artifactId>
101             <version>1.2.2</version>
102         </dependency>
103 
104         <dependency>
105             <groupId>redis.clients</groupId>
106             <artifactId>jedis</artifactId>
107             <version>2.6.2</version>
108         </dependency>
109         <!-- 導入java ee jar 包 -->
110         <dependency>
111             <groupId>javax</groupId>
112             <artifactId>javaee-api</artifactId>
113             <version>7.0</version>
114         </dependency>
115         <!-- D:\wanglihu\apacemaven\changku\oracle\ojdbc14\14\ojdbc14-14.jar -->
116         <dependency>
117             <groupId>oracle</groupId>
118             <artifactId>ojdbc14</artifactId>
119             <version>14</version>
120         </dependency>
121         <!--數據源 -->
122         <!-- 導入dbcp的jar包,用來在applicationContext.xml中配置數據庫 -->
123         <dependency>
124             <groupId>commons-dbcp</groupId>
125             <artifactId>commons-dbcp</artifactId>
126             <version>1.2.2</version>
127         </dependency>
128         <!-- JSTL標簽類 -->
129         <dependency>
130             <groupId>jstl</groupId>
131             <artifactId>jstl</artifactId>
132             <version>1.2</version>
133         </dependency>
134         <!-- 日志文件管理包 -->
135         <!-- log start -->
136         <dependency>
137             <groupId>log4j</groupId>
138             <artifactId>log4j</artifactId>
139             <version>${log4j.version}</version>
140         </dependency>
141         <!-- 格式化對象,方便輸出日志 -->
142         <dependency>
143             <groupId>com.alibaba</groupId>
144             <artifactId>fastjson</artifactId>
145             <version>1.1.41</version>
146         </dependency>
147 
148         <dependency>
149             <groupId>org.slf4j</groupId>
150             <artifactId>slf4j-api</artifactId>
151             <version>${slf4j.version}</version>
152         </dependency>
153 
154         <dependency>
155             <groupId>org.slf4j</groupId>
156             <artifactId>slf4j-log4j12</artifactId>
157             <version>${slf4j.version}</version>
158         </dependency>
159         <!-- log end -->
160         <!-- 映入JSON -->
161         <dependency>
162             <groupId>org.codehaus.jackson</groupId>
163             <artifactId>jackson-mapper-asl</artifactId>
164             <version>1.9.13</version>
165         </dependency>
166         <!-- 上傳組件包 -->
167         <dependency>
168             <groupId>commons-fileupload</groupId>
169             <artifactId>commons-fileupload</artifactId>
170             <version>1.3.1</version>
171         </dependency>
172         <dependency>
173             <groupId>commons-io</groupId>
174             <artifactId>commons-io</artifactId>
175             <version>2.4</version>
176         </dependency>
177         <dependency>
178             <groupId>commons-codec</groupId>
179             <artifactId>commons-codec</artifactId>
180             <version>1.9</version>
181         </dependency>
182 
183         <!--添加json包 -->
184         <dependency>
185             <groupId>net.sf.json-lib</groupId>
186             <artifactId>json-lib</artifactId>
187             <version>2.2.3</version>
188             <classifier>jdk15</classifier>
189         </dependency>
190 
191     </dependencies>
192     <build>
193         <finalName>mybatisRedis</finalName>
194     </build>
195 </project>

 

 

最后附上幾個鏈接

http://www.tuicool.com/articles/quqmy2

 

http://blog.csdn.net/yjl33/article/details/50401211

 

這個也不錯

http://www.cnblogs.com/wcyBlog/p/4402567.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM