完成10个工程的代码
This commit is contained in:
@ -2,6 +2,14 @@
|
||||
|
||||
SpringBoot中通过RedisTemplate来直接操作Redis缓存数据库
|
||||
|
||||
## 运行
|
||||
|
||||
初始化sql文件在`resources/sql/t_user.sql`中
|
||||
|
||||
另外还需要安装Redis,配置好`application.yml`文件中的redis地址
|
||||
|
||||
测试用例:`com.xncoding.service.UserServiceTest.java`
|
||||
|
||||
## 许可证
|
||||
|
||||
Copyright (c) 2018 Xiong Neng
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.enzhico</groupId>
|
||||
<groupId>com.xncoding</groupId>
|
||||
<artifactId>springboot-redis</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.enzhico.trans;
|
||||
package com.xncoding.pos;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.enzhico.trans.config;
|
||||
package com.xncoding.pos.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
@ -1,10 +1,8 @@
|
||||
package com.enzhico.trans.config;
|
||||
package com.xncoding.pos.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
|
||||
import com.enzhico.trans.config.DruidProperties;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@ -19,7 +17,7 @@ import javax.annotation.Resource;
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement(order = 2)
|
||||
@MapperScan(basePackages = {"com.enzhico.trans.dao.repository"})
|
||||
@MapperScan(basePackages = {"com.xncoding.pos.dao.repository"})
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Resource
|
||||
@ -1,4 +1,4 @@
|
||||
package com.enzhico.trans.config;
|
||||
package com.xncoding.pos.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.enzhico.trans.dao.entity;
|
||||
package com.xncoding.pos.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
@ -1,7 +1,7 @@
|
||||
package com.enzhico.trans.dao.repository;
|
||||
package com.xncoding.pos.dao.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.enzhico.trans.dao.entity.User;
|
||||
import com.xncoding.pos.dao.entity.User;
|
||||
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
||||
@ -1,14 +1,9 @@
|
||||
package com.enzhico.trans.service;
|
||||
package com.xncoding.pos.service;
|
||||
|
||||
import com.enzhico.trans.dao.entity.User;
|
||||
import com.enzhico.trans.dao.repository.UserMapper;
|
||||
import com.xncoding.pos.dao.entity.User;
|
||||
import com.xncoding.pos.dao.repository.UserMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -2,14 +2,6 @@
|
||||
################## 所有profile共有的配置 #################
|
||||
##########################################################
|
||||
|
||||
################### 自定义项目配置 ###################
|
||||
enzhico:
|
||||
kaptcha-open: true #是否开启登录时验证码 (true/false)
|
||||
session-open: false #是否开启session验证 (true/false)
|
||||
|
||||
################### 项目启动端口 ###################
|
||||
server.port: 8092
|
||||
|
||||
################### spring配置 ###################
|
||||
spring:
|
||||
profiles:
|
||||
@ -17,13 +9,13 @@ spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://123.207.66.156:3306/test?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
|
||||
username: root
|
||||
password: _EnZhi123
|
||||
password: ******
|
||||
|
||||
################### mybatis-plus配置 ###################
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:com/enzhico/trans/dao/repository/mapping/*.xml
|
||||
mapper-locations: classpath*:com/xncoding/pos/dao/repository/mapping/*.xml
|
||||
typeAliasesPackage: >
|
||||
com.enzhico.trans.dao.entity
|
||||
com.xncoding.pos.dao.entity
|
||||
global-config:
|
||||
id-type: 0 # 0:数据库ID自增 1:用户输入id 2:全局唯一id(IdWorker) 3:全局唯一ID(uuid)
|
||||
db-column-underline: false
|
||||
@ -62,6 +54,6 @@ logging:
|
||||
level:
|
||||
ROOT: INFO
|
||||
com:
|
||||
enzhico: DEBUG
|
||||
file: E:/logs/trans.log
|
||||
xncoding: DEBUG
|
||||
file: E:/logs/app.log
|
||||
|
||||
|
||||
32
springboot-redis/src/main/resources/sql/t_user.sql
Normal file
32
springboot-redis/src/main/resources/sql/t_user.sql
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : 123.207.66.156-mysql
|
||||
Source Server Version : 50718
|
||||
Source Host : 123.207.66.156:3306
|
||||
Source Database : test
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50718
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2018-02-27 16:12:19
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_user
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `t_user`;
|
||||
CREATE TABLE `t_user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(255) DEFAULT NULL,
|
||||
`password` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_user
|
||||
-- ----------------------------
|
||||
INSERT INTO `t_user` VALUES ('52', 'admin', 'admin');
|
||||
@ -1,8 +1,8 @@
|
||||
package com.enzhico.service;
|
||||
package com.xncoding.service;
|
||||
|
||||
import com.enzhico.trans.Application;
|
||||
import com.enzhico.trans.dao.entity.User;
|
||||
import com.enzhico.trans.service.UserService;
|
||||
import com.xncoding.pos.Application;
|
||||
import com.xncoding.pos.dao.entity.User;
|
||||
import com.xncoding.pos.service.UserService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
Reference in New Issue
Block a user