parent
6b3d62878d
commit
b10df15e0e
@ -0,0 +1,33 @@
|
||||
package com.yuxue.config;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
/**
|
||||
* 配置自动启动浏览器
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CommandRunner implements CommandLineRunner {
|
||||
|
||||
@Value("${server.port}")
|
||||
private String port;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
try {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
if(os.contains("windows")) {
|
||||
// 默认浏览器打开
|
||||
// Runtime.getRuntime().exec("cmd /c start http://localhost:" + port + "/index");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
log.error("打开默认浏览器异常", ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.yuxue.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 跨域通配
|
||||
* 支持 @CrossOrigin 注解局部声明
|
||||
* @author yuxue
|
||||
* @date 2018-09-07
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
/** * 至少需要addMapping *** */
|
||||
registry
|
||||
.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("PUT", "DELETE", "GET", "POST", "OPTIONS", "HEAD")
|
||||
.allowedHeaders("Content-Type", "X-Requested-With", "accept", "Authorization", "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers")
|
||||
.allowCredentials(true)//是否带上cookie
|
||||
.maxAge(3600)
|
||||
.exposedHeaders(
|
||||
"access-control-allow-headers",
|
||||
"access-control-allow-methods",
|
||||
"access-control-allow-origin",
|
||||
"access-Control-allow-credentials",
|
||||
"access-control-max-age",
|
||||
"X-Frame-Options");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.yuxue.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 自定义配置
|
||||
* @author yuxue
|
||||
* @date 2019-06-13
|
||||
*/
|
||||
@Configuration
|
||||
public class DefaultMvcConfig {
|
||||
|
||||
/**
|
||||
* 国际化配置
|
||||
* 设置区域信息
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public LocaleResolver localeResolver(){
|
||||
return new MyLocaleResolver();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.yuxue.config;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
|
||||
@Configuration
|
||||
public class LocalDateTimeSerializerConfig {
|
||||
|
||||
@Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
|
||||
private String pattern;
|
||||
|
||||
@Bean
|
||||
public LocalDateTimeSerializer localDateTimeDeserializer() {
|
||||
return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||
return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.yuxue.config;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 配置多语言
|
||||
* @author yuxue
|
||||
* @date 2019-06-13
|
||||
*/
|
||||
public class MyLocaleResolver implements LocaleResolver {
|
||||
|
||||
@Override
|
||||
public Locale resolveLocale(HttpServletRequest request) {
|
||||
String l = request.getParameter("i18n");
|
||||
Locale locale = Locale.getDefault();
|
||||
if(!StringUtils.isEmpty(l)){
|
||||
String[] split = l.split("_");
|
||||
locale = new Locale(split[0],split[1]);
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.yuxue.config;
|
||||
|
||||
import com.github.pagehelper.PageInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询控制
|
||||
* @author yuxue
|
||||
* @date 2018-09-07
|
||||
*/
|
||||
@Configuration
|
||||
public class PageHelperConfig {
|
||||
|
||||
@Value("${pagehelper.helperDialect}")
|
||||
private String helperDialect;
|
||||
|
||||
@Bean
|
||||
public PageInterceptor pageInterceptor() {
|
||||
PageInterceptor pageInterceptor = new PageInterceptor();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("helperDialect", helperDialect);
|
||||
pageInterceptor.setProperties(properties);
|
||||
return pageInterceptor;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.yuxue.config;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.yuxue.auth.service.impl")
|
||||
@EnableAsync
|
||||
public class ThreadPoolConfig implements AsyncConfigurer {
|
||||
|
||||
@Bean(name = "taskExecutor")
|
||||
public TaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
|
||||
// 设置核心线程数
|
||||
executor.setCorePoolSize(4);
|
||||
// 设置最大线程数
|
||||
executor.setMaxPoolSize(8);
|
||||
// 设置队列容量
|
||||
executor.setQueueCapacity(100);
|
||||
// 设置线程活跃时间(秒)
|
||||
executor.setKeepAliveSeconds(60);
|
||||
// 设置默认线程名称
|
||||
executor.setThreadNamePrefix("localThread:");
|
||||
// 设置拒绝策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
// 等待所有任务结束后再关闭线程池
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
return taskExecutor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.yuxue.enumtype;
|
||||
|
||||
public enum Direction {
|
||||
|
||||
VERTICAL("VERTICAL","垂直"),
|
||||
HORIZONTAL("HORIZONTAL","水平"),
|
||||
UNKNOWN("UNKNOWN","未知");
|
||||
|
||||
public final String code;
|
||||
public final String desc;
|
||||
|
||||
Direction(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public static String getDesc(String code) {
|
||||
Direction[] enums = values();
|
||||
for (Direction type : enums) {
|
||||
if (type.code().equals(code)) {
|
||||
return type.desc();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCode(String desc) {
|
||||
Direction[] enums = values();
|
||||
for (Direction type : enums) {
|
||||
if (type.desc().equals(desc)) {
|
||||
return type.code();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String code() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String desc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue