forked from doufuplus/springboot-master
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,534 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Example user template template | ||
### Example user template | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/** | ||
!**/src/test/** | ||
|
||
# IntelliJ project files | ||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
out | ||
gen | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/** | ||
!**/src/test/** | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>springboot-master</artifactId> | ||
<groupId>com.doufuplus</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>springboot-common</artifactId> | ||
<version>${doufuplus.version}</version> | ||
<name>springboot-common</name> | ||
<description>common project for doufuplus</description> | ||
|
||
<dependencies> | ||
|
||
<!-- 健康检查 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
|
||
<!-- ali json --> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<version>${fastjson.version}</version> | ||
</dependency> | ||
|
||
<!-- commons-lang3 --> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${commons-lang3.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
40 changes: 40 additions & 0 deletions
40
springboot-core/src/main/java/com/doufuplus/config/MybatisPlusConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.doufuplus.config; | ||
|
||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; | ||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** | ||
* mybatisPlus配置 | ||
* 转载请注明出处,更多技术文章欢迎大家访问我的个人博客站点:https://www.doufuplus.com | ||
* | ||
* @author 丶doufu | ||
* @date 2019/7/27 | ||
*/ | ||
@Configuration | ||
public class MybatisPlusConfig { | ||
|
||
/** | ||
* mybatis-plus分页插件 | ||
*/ | ||
@Bean | ||
public PaginationInterceptor paginationInterceptor() { | ||
return new PaginationInterceptor(); | ||
} | ||
|
||
|
||
/** | ||
* druid注入 | ||
*/ | ||
@Bean | ||
@ConfigurationProperties("spring.datasource.druid") | ||
public DataSource dataSource() { | ||
return DruidDataSourceBuilder | ||
.create() | ||
.build(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
springboot-core/src/main/java/com/doufuplus/config/redis/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.doufuplus.config.redis; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.springframework.cache.annotation.CachingConfigurerSupport; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.cache.interceptor.KeyGenerator; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* Redis缓存配置 | ||
* | ||
* @author lwx | ||
*/ | ||
@Configuration | ||
@EnableCaching | ||
public class RedisConfig extends CachingConfigurerSupport { | ||
|
||
@Bean | ||
public KeyGenerator keyGenerator() { | ||
return new KeyGenerator() { | ||
@Override | ||
public Object generate(Object target, Method method, Object... params) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(target.getClass().getName()); | ||
sb.append(method.getName()); | ||
if (params != null && params.length > 0 && params[0] != null) { | ||
for (Object obj : params) { | ||
sb.append(obj.toString()); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* RedisTemplate | ||
*/ | ||
@Bean | ||
@SuppressWarnings("all") | ||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { | ||
|
||
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); | ||
template.setConnectionFactory(factory); | ||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); | ||
|
||
ObjectMapper om = new ObjectMapper(); | ||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); | ||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); | ||
|
||
jackson2JsonRedisSerializer.setObjectMapper(om); | ||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); | ||
|
||
// key采用String的序列化方式 | ||
template.setKeySerializer(stringRedisSerializer); | ||
// hash的key也采用String的序列化方式 | ||
template.setHashKeySerializer(stringRedisSerializer); | ||
// value序列化方式采用jackson | ||
template.setValueSerializer(jackson2JsonRedisSerializer); | ||
// hash的value序列化方式采用jackson | ||
template.setHashValueSerializer(jackson2JsonRedisSerializer); | ||
template.afterPropertiesSet(); | ||
|
||
return template; | ||
|
||
} | ||
} |
Oops, something went wrong.