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

posted @ 2016-08-31 08:13 奋斗,坚持 阅读(...) 评论(...)  编辑 收藏