基于SSM的单点登陆03

TbUser.java和TbUserExample.java,TbUserMapper.java,TbUserMapper.xml由mybatis框架生成。

generatorConfig.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration
 3         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 <generatorConfiguration>
 6     <!-- 引入配置文件 -->
 7     <!--<properties resource="jdbc.properties"/>-->
 8     <properties url="file:///D:\IDEASpace\market\market-dao\src\main\resources\jdbc.properties"/>
 9     <context id="marketTables" targetRuntime="MyBatis3">
10         <commentGenerator>
11             <!-- 是否去除自动生成的注释 true:是 : false:否 -->
12             <property name="suppressAllComments" value="true" />
13         </commentGenerator>
14         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
15         <jdbcConnection driverClass="${JDBC_DRIVER}"
16                         connectionURL="${JDBC_URL}"
17                         userId="${JDBC_USERNAME}" password="${JDBC_PASSWORD}">
18         </jdbcConnection>
19         <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL
20             和 NUMERIC 类型解析为java.math.BigDecimal -->
21         <javaTypeResolver>
22             <property name="forceBigDecimals" value="false" />
23         </javaTypeResolver>
24         <!-- targetProject:生成PO类的位置 -->
25         <javaModelGenerator targetPackage="io.guangsoft.market.bean"
26                             targetProject="src/main/java">
27             <!-- enableSubPackages:是否让schema作为包的后缀 -->
28             <property name="enableSubPackages" value="false" />
29             <!-- 从数据库返回的值被清理前后的空格 -->
30             <property name="trimStrings" value="true" />
31         </javaModelGenerator>
32         <!-- targetProject:mapper映射文件生成的位置 -->
33         <sqlMapGenerator targetPackage="io.guangsoft.market.mapper"
34                          targetProject="src/main/java">
35             <!-- enableSubPackages:是否让schema作为包的后缀 -->
36             <property name="enableSubPackages" value="false" />
37         </sqlMapGenerator>
38         <!-- targetPackage:mapper接口生成的位置 -->
39         <javaClientGenerator type="XMLMAPPER" targetPackage="io.guangsoft.market.dao"
40                              targetProject="src/main/java">
41             <!-- enableSubPackages:是否让schema作为包的后缀 -->
42             <property name="enableSubPackages" value="false" />
43         </javaClientGenerator>
44         <!-- 指定数据库表 -->
45         <table schema="" tableName="tb_content"></table>
46         <table schema="" tableName="tb_content_category"></table>
47         <table schema="" tableName="tb_item"></table>
48         <table schema="" tableName="tb_item_cat"></table>
49         <table schema="" tableName="tb_item_desc"></table>
50         <table schema="" tableName="tb_item_param"></table>
51         <table schema="" tableName="tb_item_param_item"></table>
52         <table schema="" tableName="tb_order"></table>
53         <table schema="" tableName="tb_order_item"></table>
54         <table schema="" tableName="tb_order_shipping"></table>
55         <table schema="" tableName="tb_user"></table>
56     </context>
57 </generatorConfiguration>

spring-jedis.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 7     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
 8     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
 9     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
10     <!-- 解析properties文件的工具类 -->
11     <context:property-placeholder location="classpath:*.properties"/>
12     <!-- 连接池配置 -->
13     <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
14         <!-- 最大连接数 -->
15         <property name="maxTotal" value="30" />
16         <!-- 最大空闲连接数 -->
17         <property name="maxIdle" value="10" />
18         <!-- 每次释放连接的最大数目 -->
19         <property name="numTestsPerEvictionRun" value="1024" />
20         <!-- 释放连接的扫描间隔(毫秒) -->
21         <property name="timeBetweenEvictionRunsMillis" value="30000" />
22         <!-- 连接最小空闲时间 -->
23         <property name="minEvictableIdleTimeMillis" value="1800000" />
24         <!-- 连接空闲多久后释放, 当空闲时间>该值 且 空闲连接>最大空闲连接数 时直接释放 -->
25         <property name="softMinEvictableIdleTimeMillis" value="10000" />
26         <!-- 获取连接时的最大等待毫秒数,小于零:阻塞不确定的时间,默认-1 -->
27         <property name="maxWaitMillis" value="1500" />
28         <!-- 在获取连接的时候检查有效性, 默认false -->
29         <property name="testOnBorrow" value="true" />
30         <!-- 在空闲时检查有效性, 默认false -->
31         <property name="testWhileIdle" value="true" />
32         <!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
33         <property name="blockWhenExhausted" value="false" />
34     </bean>
35     
36     <!-- 配置jedisPool对象 -->
37     <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
38         <constructor-arg name="host" value="${JEDIS_URL}" />
39         <constructor-arg name="port" value="${JEDIS_PORT}" />
40         <constructor-arg name="poolConfig">
41             <ref bean="jedisPoolConfig"/>
42         </constructor-arg>
43     </bean>
44     
45     <bean id="jedisDaoPool" class="io.guangsoft.market.dao.jedis.JedisDaoImpl">
46         <property name="pool">
47             <ref bean="jedisPool"/>
48         </property>
49     </bean>
50 </beans>

jedis.properties

1 JEDIS_URL=127.0.0.1
2 JEDIS_PORT=6379

JedisDao.java

 1 package io.guangsoft.market.dao.jedis;
 2 
 3 public interface JedisDao {
 4     public String set(String key,String value);
 5     public String get(String key);
 6     public Long expire(String key, int seconds);
 7     public Long ttl(String key);
 8     public Long hset(String key,String hkey,String value);
 9     public String hgetI(String key,String hkey);
10     public Long del(String key);
11     public Long hdel(String key,String hkey);
12 }

JedisDaoImpl.java

 1 package io.guangsoft.market.dao.jedis;
 2 
 3 import redis.clients.jedis.Jedis;
 4 import redis.clients.jedis.JedisPool;
 5 
 6 public class JedisDaoImpl implements JedisDao {
 7 
 8     private JedisPool pool;
 9 
10     public JedisPool getPool() {
11         return pool;
12     }
13 
14     public void setPool(JedisPool pool) {
15         this.pool = pool;
16     }
17 
18     @Override
19     public String set(String key, String value) {
20         Jedis jedis = pool.getResource();
21         String val = jedis.set(key, value);
22         jedis.close();
23         return val;
24     }
25 
26     @Override
27     public String get(String key) {
28         Jedis jedis = pool.getResource();
29         String val = jedis.get(key);
30         jedis.close();
31         return val;
32     }
33 
34     @Override
35     public Long expire(String key, int seconds) {
36         Jedis jedis = pool.getResource();
37         Long val = jedis.expire(key, seconds);
38         jedis.close();
39         return val;
40     }
41 
42     @Override
43     public Long ttl(String key) {
44         Jedis jedis = pool.getResource();
45         Long val = jedis.ttl(key);
46         jedis.close();
47         return val;
48     }
49 
50     @Override
51     public Long hset(String key, String hkey, String value) {
52         Jedis jedis = pool.getResource();
53         Long val = jedis.hset(key, hkey, value);
54         jedis.close();
55         return val;
56     }
57 
58     @Override
59     public String hgetI(String key, String hkey) {
60         Jedis jedis = pool.getResource();
61         String val = jedis.hget(key, hkey);
62         jedis.close();
63         return val;
64     }
65 
66     @Override
67     public Long del(String key) {
68         Jedis jedis = pool.getResource();
69         Long val = jedis.del(key);
70         jedis.close();
71         return val;
72     }
73 
74     @Override
75     public Long hdel(String key, String hkey) {
76         Jedis jedis = pool.getResource();
77         Long val = jedis.hdel(key, hkey);
78         jedis.close();
79         return val;
80     }
81 }

 

posted @ 2018-06-18 20:02  光何  阅读(785)  评论(0编辑  收藏  举报