Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ef200dcb8 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +0,0 @@
|
|||||||
.toco
|
|
||||||
.idea/
|
|
||||||
.vscode/
|
|
||||||
.DS_Store
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package {{ .package }}.common.redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import redis.clients.jedis.HostAndPort;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import redis.clients.jedis.JedisCluster;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties({RedisPoolProperties.class})
|
||||||
|
@ConditionalOnProperty(name = "redis-config.pool.hostAndPort")
|
||||||
|
public class RedisPoolConfig {
|
||||||
|
@Autowired
|
||||||
|
private RedisPoolProperties redisPoolProperties;
|
||||||
|
@Value("${redis-config.pool.password:}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private JedisPoolConfig initPoolConfig() {
|
||||||
|
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||||
|
poolConfig.setMaxTotal(redisPoolProperties.getMaxTotal());
|
||||||
|
poolConfig.setMaxIdle(redisPoolProperties.getMaxIdle());
|
||||||
|
poolConfig.setMinIdle(redisPoolProperties.getMinIdle());
|
||||||
|
poolConfig.setNumTestsPerEvictionRun(redisPoolProperties.getNumTestsPerEvictionRun());
|
||||||
|
poolConfig.setTestOnBorrow(redisPoolProperties.isTestOnBorrow());
|
||||||
|
poolConfig.setTestOnReturn(redisPoolProperties.isTestOnReturn());
|
||||||
|
poolConfig.setTestWhileIdle(redisPoolProperties.isTestWhileIdle());
|
||||||
|
poolConfig.setBlockWhenExhausted(redisPoolProperties.isBlockWhenExhausted());
|
||||||
|
poolConfig.setJmxEnabled(redisPoolProperties.isJmxEnabled());
|
||||||
|
poolConfig.setLifo(redisPoolProperties.isLifo());
|
||||||
|
poolConfig.setNumTestsPerEvictionRun(redisPoolProperties.getNumTestsPerEvictionRun());
|
||||||
|
poolConfig.setTestOnBorrow(false);
|
||||||
|
return poolConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create jedis poll
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public JedisPool getRedisPool() {
|
||||||
|
String host = StrUtil.subBefore(redisPoolProperties.getHostAndPort(), ":", false);
|
||||||
|
int port = Integer.parseInt(StrUtil.subAfter(redisPoolProperties.getHostAndPort(), ":", false));
|
||||||
|
if(StrUtil.isNotEmpty(this.password)) {
|
||||||
|
return new JedisPool(initPoolConfig(),host,port ,1000, password);
|
||||||
|
}else{
|
||||||
|
return new JedisPool(initPoolConfig(),host,port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package {{ .package }}.common.redis;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "redis-config.pool")
|
||||||
|
public class RedisPoolProperties {
|
||||||
|
private String hostAndPort;
|
||||||
|
private int maxTotal;
|
||||||
|
private int maxIdle;
|
||||||
|
private int minIdle;
|
||||||
|
private Long maxWaitMillis;
|
||||||
|
private Long timeBetweenEvictionRunsMillis;
|
||||||
|
private Long minEvictableIdleTimeMillis;
|
||||||
|
private Long softMinEvictableIdleTimeMillis;
|
||||||
|
private boolean testOnBorrow;
|
||||||
|
private boolean testOnReturn;
|
||||||
|
private boolean testWhileIdle;
|
||||||
|
private boolean blockWhenExhausted;
|
||||||
|
private boolean jmxEnabled;
|
||||||
|
private boolean lifo;
|
||||||
|
private int numTestsPerEvictionRun;
|
||||||
|
|
||||||
|
public String getHostAndPort() {
|
||||||
|
return hostAndPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostAndPort(String hostAndPort) {
|
||||||
|
this.hostAndPort = hostAndPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxTotal() {
|
||||||
|
return maxTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxTotal(int maxTotal) {
|
||||||
|
this.maxTotal = maxTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxIdle() {
|
||||||
|
return maxIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxIdle(int maxIdle) {
|
||||||
|
this.maxIdle = maxIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinIdle() {
|
||||||
|
return minIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinIdle(int minIdle) {
|
||||||
|
this.minIdle = minIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getMaxWaitMillis() {
|
||||||
|
return maxWaitMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxWaitMillis(Long maxWaitMillis) {
|
||||||
|
this.maxWaitMillis = maxWaitMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTimeBetweenEvictionRunsMillis() {
|
||||||
|
return timeBetweenEvictionRunsMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeBetweenEvictionRunsMillis(Long timeBetweenEvictionRunsMillis) {
|
||||||
|
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getMinEvictableIdleTimeMillis() {
|
||||||
|
return minEvictableIdleTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinEvictableIdleTimeMillis(Long minEvictableIdleTimeMillis) {
|
||||||
|
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getSoftMinEvictableIdleTimeMillis() {
|
||||||
|
return softMinEvictableIdleTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSoftMinEvictableIdleTimeMillis(Long softMinEvictableIdleTimeMillis) {
|
||||||
|
this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTestOnBorrow() {
|
||||||
|
return testOnBorrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestOnBorrow(boolean testOnBorrow) {
|
||||||
|
this.testOnBorrow = testOnBorrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTestOnReturn() {
|
||||||
|
return testOnReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestOnReturn(boolean testOnReturn) {
|
||||||
|
this.testOnReturn = testOnReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTestWhileIdle() {
|
||||||
|
return testWhileIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestWhileIdle(boolean testWhileIdle) {
|
||||||
|
this.testWhileIdle = testWhileIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBlockWhenExhausted() {
|
||||||
|
return blockWhenExhausted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockWhenExhausted(boolean blockWhenExhausted) {
|
||||||
|
this.blockWhenExhausted = blockWhenExhausted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isJmxEnabled() {
|
||||||
|
return jmxEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJmxEnabled(boolean jmxEnabled) {
|
||||||
|
this.jmxEnabled = jmxEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLifo() {
|
||||||
|
return lifo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLifo(boolean lifo) {
|
||||||
|
this.lifo = lifo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumTestsPerEvictionRun() {
|
||||||
|
return numTestsPerEvictionRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
|
||||||
|
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package {{ .package }}.common.response;public class FailData {
|
|
||||||
private int code = 500;
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public FailData() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
package {{ .package }}.common.response;
|
package {{ .package }}.common.response;
|
||||||
|
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class MyDateFormat extends DateFormat {
|
public class MyDateFormat extends DateFormat {
|
||||||
private static final long serialVersionUID = -4580955831439573829L;
|
private static final long serialVersionUID = -4580955831439573829L;
|
||||||
|
private static final String customDateFormat = "yyyy-MM-dd HH:mm:ss";
|
||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
public MyDateFormat() {
|
|
||||||
this.calendar = Calendar.getInstance();
|
|
||||||
this.dateFormat = simpleDateFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public MyDateFormat(DateFormat dateFormat) {
|
public MyDateFormat(DateFormat dateFormat) {
|
||||||
this.calendar = Calendar.getInstance();
|
this.calendar = Calendar.getInstance();
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package {{ .package }}.common.response;
|
|
||||||
import com.fasterxml.jackson.core.JsonParser.Feature;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
public class ObjectMapperFactory {
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
public ObjectMapperFactory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ObjectMapper getDefaultObjectMapper() {
|
|
||||||
return objectMapper.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).configure(Feature.ALLOW_SINGLE_QUOTES, true);
|
|
||||||
SimpleModule bigDecimalModule = new SimpleModule();
|
|
||||||
bigDecimalModule.addSerializer(BigDecimal.class, new ToStringSerializer());
|
|
||||||
objectMapper.registerModule(bigDecimalModule);
|
|
||||||
objectMapper.setDateFormat(new MyDateFormat());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
package {{ .package }}.common.response;
|
package {{ .package }}.common.response;
|
||||||
import com.vs.ex.BizException;
|
|
||||||
|
import com.vs.common.util.rpc.pub.FailData;
|
||||||
|
import com.vs.ox.common.exception.ErrorCode;
|
||||||
|
import com.vs.ox.common.exception.IgnoredException;
|
||||||
|
import com.vs.ox.common.utils.ObjectMapperFactory;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.ConstraintViolation;
|
import jakarta.validation.ConstraintViolation;
|
||||||
import jakarta.validation.ConstraintViolationException;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
import jakarta.validation.Path;
|
import jakarta.validation.Path;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
@@ -17,42 +24,65 @@ import org.springframework.web.servlet.ModelAndView;
|
|||||||
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ResponseJsonExceptionResolver extends AbstractHandlerExceptionResolver implements InitializingBean {
|
public class ResponseJsonExceptionResolver extends AbstractHandlerExceptionResolver
|
||||||
|
implements InitializingBean {
|
||||||
private HttpMessageConverter messageConverter;
|
private HttpMessageConverter messageConverter;
|
||||||
|
|
||||||
public ResponseJsonExceptionResolver() {
|
public ResponseJsonExceptionResolver() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
if (messageConverter == null) {
|
if (messageConverter == null) {
|
||||||
messageConverter = new MappingJackson2HttpMessageConverter(ObjectMapperFactory.getDefaultObjectMapper());
|
messageConverter =
|
||||||
|
new MappingJackson2HttpMessageConverter(
|
||||||
|
ObjectMapperFactory.getDefaultObjectMapper());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getErrorInfoFromException(Exception e) {
|
||||||
|
try {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
e.printStackTrace(pw);
|
||||||
|
return "\r\n" + sw.toString() + "\r\n";
|
||||||
|
} catch (Exception e2) {
|
||||||
|
return "bad getErrorInfoFromException";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
protected ModelAndView doResolveException(
|
||||||
|
HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
Object handler,
|
||||||
|
Exception ex) {
|
||||||
|
/** web请求分页单独处理,应对antd框架 */
|
||||||
FailData failData = new FailData();
|
FailData failData = new FailData();
|
||||||
failData.setMessage(ex.getMessage());
|
failData.setMessage(ex.getMessage());
|
||||||
if (ex instanceof BizException) {
|
if (ex instanceof IgnoredException) {
|
||||||
BizException realEx = (BizException) ex;
|
IgnoredException realEx = (IgnoredException) ex;
|
||||||
failData.setCode(realEx.getCode());
|
failData.setCode(realEx.getErrorCode());
|
||||||
failData.setMessage(realEx.getMessage());
|
failData.setData(realEx.getData());
|
||||||
log.error("execute {} failed with exception", request.getRequestURL(), ex);
|
log.error("execute {} failed with exception", request.getRequestURL(), ex);
|
||||||
} else if (ex instanceof ConstraintViolationException) {
|
} else if (ex instanceof ConstraintViolationException) {
|
||||||
failData.setCode(400);
|
failData.setCode(ErrorCode.WRONG_PARAMETER);
|
||||||
failData.setMessage(getMessage((ConstraintViolationException) ex));
|
failData.setMessage(getMessage((ConstraintViolationException) ex));
|
||||||
|
} else if (ex instanceof ErrorCode) {
|
||||||
|
failData.setCode(((ErrorCode) ex).getErrorCode());
|
||||||
} else {
|
} else {
|
||||||
log.error("execute {} failed with exception", request.getRequestURL(), ex);
|
log.error("execute {} failed with exception", request.getRequestURL(), ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
messageConverter.write(failData, MediaType.APPLICATION_JSON, new ServletServerHttpResponse(response));
|
messageConverter.write(
|
||||||
|
failData, MediaType.APPLICATION_JSON, new ServletServerHttpResponse(response));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@@ -69,7 +99,9 @@ public class ResponseJsonExceptionResolver extends AbstractHandlerExceptionResol
|
|||||||
for (ConstraintViolation<?> constraintViolation : e.getConstraintViolations()) {
|
for (ConstraintViolation<?> constraintViolation : e.getConstraintViolations()) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
StringBuilder param = new StringBuilder();
|
StringBuilder param = new StringBuilder();
|
||||||
for (Iterator<Path.Node> iterator = constraintViolation.getPropertyPath().iterator(); iterator.hasNext(); i++) {
|
for (Iterator<Path.Node> iterator = constraintViolation.getPropertyPath().iterator();
|
||||||
|
iterator.hasNext();
|
||||||
|
i++) {
|
||||||
Path.Node node = iterator.next();
|
Path.Node node = iterator.next();
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
continue;
|
continue;
|
||||||
@@ -79,9 +111,8 @@ public class ResponseJsonExceptionResolver extends AbstractHandlerExceptionResol
|
|||||||
}
|
}
|
||||||
param.append(node.getName());
|
param.append(node.getName());
|
||||||
}
|
}
|
||||||
msgList.add("Param [ " + param + " ] " + constraintViolation.getMessage());
|
msgList.add("参数 [ " + param + " ] " + constraintViolation.getMessage());
|
||||||
}
|
}
|
||||||
return StringUtils.join(msgList.toArray(), ";");
|
return StringUtils.join(msgList.toArray(), ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package {{ .package }}.common.response;
|
package {{ .package }}.common.response;
|
||||||
|
|
||||||
|
import com.vs.common.util.rpc.pub.SuccessData;
|
||||||
|
import com.vs.ox.common.utils.ObjectMapperFactory;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
@@ -22,7 +25,9 @@ public class ResponseJsonMethodReturnValueHandler
|
|||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
if (messageConverter == null) {
|
if (messageConverter == null) {
|
||||||
messageConverter = new MappingJackson2HttpMessageConverter(ObjectMapperFactory.getDefaultObjectMapper());
|
messageConverter =
|
||||||
|
new MappingJackson2HttpMessageConverter(
|
||||||
|
ObjectMapperFactory.getDefaultObjectMapper());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,17 +37,26 @@ public class ResponseJsonMethodReturnValueHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
public void handleReturnValue(
|
||||||
try {
|
Object returnValue,
|
||||||
mavContainer.setRequestHandled(true);
|
MethodParameter returnType,
|
||||||
String customMessage = ResponseMessageHolder.getMessage();
|
ModelAndViewContainer mavContainer,
|
||||||
int code = ResponseMessageHolder.getCode();
|
NativeWebRequest webRequest)
|
||||||
Object result = new SuccessData(code, returnValue, customMessage);
|
throws Exception {
|
||||||
|
mavContainer.setRequestHandled(true);
|
||||||
ServletServerHttpResponse response = new ServletServerHttpResponse(webRequest.getNativeResponse(HttpServletResponse.class));
|
Object result = returnValue;
|
||||||
messageConverter.write(result, new MediaType(MediaType.APPLICATION_JSON, Collections.singletonMap("charset", "utf-8")), response);
|
/** Web分页请求的返回按照antd框架要求的格式,不转为SuccessData */
|
||||||
} finally {
|
result =
|
||||||
ResponseMessageHolder.clear();
|
result == null
|
||||||
}
|
? new SuccessData(Collections.emptyMap())
|
||||||
|
: new SuccessData(returnValue);
|
||||||
|
ServletServerHttpResponse response =
|
||||||
|
new ServletServerHttpResponse(
|
||||||
|
webRequest.getNativeResponse(HttpServletResponse.class));
|
||||||
|
messageConverter.write(
|
||||||
|
result,
|
||||||
|
new MediaType(
|
||||||
|
MediaType.APPLICATION_JSON, Collections.singletonMap("charset", "utf-8")),
|
||||||
|
response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package {{ .package }}.common.response;
|
|
||||||
public class ResponseMessageHolder {
|
|
||||||
private static final ThreadLocal<String> MESSAGE_HOLDER = new InheritableThreadLocal<>();
|
|
||||||
|
|
||||||
public static void setMessage(String message) {
|
|
||||||
MESSAGE_HOLDER.set(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMessage() {
|
|
||||||
return MESSAGE_HOLDER.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clear() {
|
|
||||||
MESSAGE_HOLDER.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final ThreadLocal<Integer> CODE_HOLDER = new InheritableThreadLocal<>();
|
|
||||||
|
|
||||||
public static void setCode(Integer code) {
|
|
||||||
CODE_HOLDER.set(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Integer getCode() {
|
|
||||||
Integer code = CODE_HOLDER.get();
|
|
||||||
return code == null ? 200 : code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearCode() {
|
|
||||||
CODE_HOLDER.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setCodeAndMessage(Integer code, String message) {
|
|
||||||
setCode(code);
|
|
||||||
setMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearAll() {
|
|
||||||
MESSAGE_HOLDER.remove();
|
|
||||||
CODE_HOLDER.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package {{ .package }}.common.response;
|
|
||||||
public class SuccessData {
|
|
||||||
private int code = 200;
|
|
||||||
private Object data;
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public SuccessData() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuccessData(Object data){
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuccessData(int code, Object data) {
|
|
||||||
this.code = code;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuccessData(int code, Object data, String message) {
|
|
||||||
this.code = code;
|
|
||||||
this.data = data;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(Object data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
package {{ .package }}.common.response;
|
package {{ .package }}.common.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package {{ .package }}.entrance.web;
|
package {{ .package }}.entrance.web;
|
||||||
|
|
||||||
|
import com.vs.sqlmapper.spring.DataSourceConfig;
|
||||||
|
import com.vs.sqlmapper.spring.scan.VSDaoBeanScan;
|
||||||
|
import com.vs.agent.TocoAgentInitializer;
|
||||||
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@@ -9,6 +13,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
|
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"{{.groupId}}", "com.vs"})
|
@SpringBootApplication(scanBasePackages = {"{{.groupId}}", "com.vs"})
|
||||||
|
@VSDaoBeanScan(basePackages = {"com.vs","{{.groupId}}"})
|
||||||
|
@Import(DataSourceConfig.class)
|
||||||
@MapperScan("{{.groupId}}.**.persist.mapper.mybatis")
|
@MapperScan("{{.groupId}}.**.persist.mapper.mybatis")
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class AppApplication{
|
public class AppApplication{
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
server.port=8082
|
server.port=8082
|
||||||
|
|
||||||
|
mock.enabled=true
|
||||||
#datasource
|
#datasource
|
||||||
{{- if eq .dbType "oracle" }}
|
{{- if eq .dbType "oracle" }}
|
||||||
spring.datasource.url=jdbc:oracle:thin:@//{{ .dbHost }}:{{ .dbPort }}/ORCLCDB
|
spring.datasource.url=jdbc:oracle:thin:@//{{ .dbHost }}:1521/ORCLCDB
|
||||||
{{- else if eq .dbType "postgresql" }}
|
{{- else if eq .dbType "postgresql" }}
|
||||||
spring.datasource.url=jdbc:postgresql://{{ .dbHost }}:{{ .dbPort }}/{{ .dbDatabase }}?useUnicode=true&characterEncoding=utf8&autoReconnect=true&stringtype=unspecified
|
spring.datasource.url=jdbc:postgresql://{{ .dbHost }}:5432/{{ .dbDatabase }}?useUnicode=true&characterEncoding=utf8&autoReconnect=true&stringtype=unspecified
|
||||||
{{- else if eq .dbType "mysql" }}
|
{{- else if eq .dbType "mysql" }}
|
||||||
spring.datasource.url=jdbc:mysql://${DB_HOST:10.0.2.201:3306}/${DB_DATABASE:hande_test}?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
spring.datasource.url=jdbc:mysql://${DB_HOST:10.0.2.201:3306}/${DB_DATABASE:hande_test}?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||||
{{- else if eq .dbType "dm"}}
|
{{- else if eq .dbType "dm"}}
|
||||||
spring.datasource.url=jdbc:dm://${ .dbHost }/${ .dbPort }/SYSDBA?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
spring.datasource.url=jdbc:dm://${ .dbHost }/5236/SYSDBA?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||||
{{- end }}
|
{{- end }}
|
||||||
spring.datasource.username=${DB_USER:hande_test_user}
|
spring.datasource.username=${DB_USER:hande_test_user}
|
||||||
spring.datasource.password=${DB_PASSWORD:Yu0FvhjUQDGdnmm5}
|
spring.datasource.password=${DB_PASSWORD:Yu0FvhjUQDGdnmm5}
|
||||||
|
|||||||
@@ -1,44 +1,72 @@
|
|||||||
spring.profiles.active=local
|
spring.profiles.active=local
|
||||||
envs=local,remote,online,custom
|
envs=local,remote,online,custom
|
||||||
|
check=true
|
||||||
spring.main.allow-bean-definition-overriding=true
|
spring.main.allow-bean-definition-overriding=true
|
||||||
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
|
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
|
||||||
|
spring.jpa.open-in-view=false
|
||||||
spring.main.allow-circular-references=true
|
spring.main.allow-circular-references=true
|
||||||
|
spring.login.security.csrf=false
|
||||||
|
application.name={{ .projectName }}
|
||||||
mybatis.configuration.map-underscore-to-camel-case=true
|
mybatis.configuration.map-underscore-to-camel-case=true
|
||||||
|
project_id={{ .projectId }}
|
||||||
|
project_name={{ .projectName }}
|
||||||
base.package={{.groupId}}
|
base.package={{.groupId}}
|
||||||
{{- if eq .dbType "mysql" }}
|
{{- if eq .dbType "mysql" }}
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
#mysql | oracle | postgresql
|
hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
||||||
db.type=mysql
|
|
||||||
{{- else if eq .dbType "postgresql" }}
|
{{- else if eq .dbType "postgresql" }}
|
||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
#mysql | oracle | postgresql
|
vs.sqlmapper.dialect=postgresql
|
||||||
db.type=postgresql
|
|
||||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
{{- else if eq .dbType "oracle" }}
|
{{- else if eq .dbType "oracle" }}
|
||||||
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
|
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
|
||||||
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
|
hibernate.dialect=org.hibernate.dialect.OracleDialect
|
||||||
#mysql | oracle | postgresql
|
vs.sqlmapper.dialect=oracle
|
||||||
db.type=oracle
|
|
||||||
{{- else if eq .dbType "dm" }}
|
{{- else if eq .dbType "dm" }}
|
||||||
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
|
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
|
||||||
hibernate.dialect=org.hibernate.dialect.DmDialect
|
hibernate.dialect=org.hibernate.dialect.DmDialect
|
||||||
#mysql | oracle | postgresql
|
vs.sqlmapper.dialect=dm
|
||||||
db.type=dm
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
#create default table
|
com.toco.agent.attach=false
|
||||||
db.basetable.create=true
|
|
||||||
#hibernate.show_sql=true
|
|
||||||
|
|
||||||
|
#create default table
|
||||||
|
vs.db.basetable.create=true
|
||||||
|
server.ssl.enabled=false
|
||||||
|
server.forward-headers-strategy=framework
|
||||||
|
#request header
|
||||||
|
out.request.headers=
|
||||||
|
#response header
|
||||||
|
out.response.headers=Content-Type
|
||||||
|
#custom corss-domain headers, split by ','
|
||||||
|
cross.domain.headers=
|
||||||
|
#eg:https://vsstudio.teitui.com
|
||||||
|
out.host=
|
||||||
|
#hibernate.show_sql=true
|
||||||
|
#vs.sqlmapper.showSql=true
|
||||||
|
mock.enabled=false
|
||||||
|
|
||||||
## message config , use memory for test, mq.type can be redis/rocketmq/kafka
|
## message config , use memory for test, mq.type can be redis/rocketmq/kafka
|
||||||
mq.type=memory
|
mq.type=memory
|
||||||
spring.autoconfigure.exclude=org.redisson.spring.starter.RedissonAutoConfiguration
|
|
||||||
#redis
|
|
||||||
#spring.redis.host=${REDIS_HOST:localhost}
|
|
||||||
#spring.redis.port=6379
|
|
||||||
#spring.redis.timeout=3000
|
|
||||||
|
|
||||||
#rocketmq.name-server=${ROCKETMQ_HOST:10.0.2.221:9876;10.0.2.222:9876;10.0.2.223:9876}
|
#rocketmq.name-server=${ROCKETMQ_HOST:10.0.2.221:9876;10.0.2.222:9876;10.0.2.223:9876}
|
||||||
|
|
||||||
|
#redis
|
||||||
|
#redis-config.pool.hostAndPort=${REDIS_HOST:redis.byteawake.com:6379}
|
||||||
|
#redis-config.pool.password=${REDIS_PASSWORD:}
|
||||||
|
#redis-config.pool.maxTotal=100
|
||||||
|
#redis-config.pool.maxIdle=10
|
||||||
|
#redis-config.pool.minIdle=10
|
||||||
|
#redis-config.pool.maxWaitMillis=10000
|
||||||
|
#redis-config.pool.softMinEvictableIdleTimeMillis=10000
|
||||||
|
#redis-config.pool.testOnBorrow=true
|
||||||
|
#redis-config.pool.testOnReturn=true
|
||||||
|
#redis-config.pool.testWhileIdle=true
|
||||||
|
#redis-config.pool.timeBetweenEvictionRunsMillis=30000
|
||||||
|
#redis-config.pool.minEvictableIdleTimeMillis=1800000
|
||||||
|
#redis-config.pool.numTestsPerEvictionRun=3
|
||||||
|
#redis-config.pool.blockWhenExhausted=true
|
||||||
|
#redis-config.pool.jmxEnabled=true
|
||||||
|
#redis-config.pool.lifo=true
|
||||||
|
|
||||||
#kafka.bootstrap-servers=localhost:9092
|
#kafka.bootstrap-servers=localhost:9092
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
<?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">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>{{ .groupId }}</groupId>
|
|
||||||
<artifactId>{{ .artifactId }}</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>{{ .artifactId }}-facade</artifactId>
|
|
||||||
</project>
|
|
||||||
@@ -115,11 +115,11 @@
|
|||||||
<artifactId>aspectjrt</artifactId>
|
<artifactId>aspectjrt</artifactId>
|
||||||
<version>1.9.6</version>
|
<version>1.9.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.redisson</groupId>
|
<groupId>org.redisson</groupId>
|
||||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||||
<version>3.23.0</version>
|
<version>3.23.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
@@ -287,8 +287,6 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>entrance</module>
|
<module>entrance</module>
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
<module>public_service</module>
|
|
||||||
<module>facade</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
<?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">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>{{ .groupId }}</groupId>
|
|
||||||
<artifactId>{{ .artifactId }}</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>{{ .artifactId }}-public-service</artifactId>
|
|
||||||
</project>
|
|
||||||
Reference in New Issue
Block a user