mirror of https://github.com/elunez/eladmin
Merge branch 'elunez:master' into master
commit
2ea5e539db
|
@ -23,10 +23,11 @@ import me.zhengjie.utils.ThrowableUtil;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
import org.springframework.validation.FieldError;
|
||||||
|
import org.springframework.validation.ObjectError;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import java.util.Objects;
|
|
||||||
import static org.springframework.http.HttpStatus.*;
|
import static org.springframework.http.HttpStatus.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,11 +96,10 @@ public class GlobalExceptionHandler {
|
||||||
public ResponseEntity<ApiError> handleMethodArgumentNotValidException(MethodArgumentNotValidException e){
|
public ResponseEntity<ApiError> handleMethodArgumentNotValidException(MethodArgumentNotValidException e){
|
||||||
// 打印堆栈信息
|
// 打印堆栈信息
|
||||||
log.error(ThrowableUtil.getStackTrace(e));
|
log.error(ThrowableUtil.getStackTrace(e));
|
||||||
String[] str = Objects.requireNonNull(e.getBindingResult().getAllErrors().get(0).getCodes())[1].split("\\.");
|
ObjectError objectError = e.getBindingResult().getAllErrors().get(0);
|
||||||
String message = e.getBindingResult().getAllErrors().get(0).getDefaultMessage();
|
String message = objectError.getDefaultMessage();
|
||||||
String msg = "不能为空";
|
if (objectError instanceof FieldError) {
|
||||||
if(msg.equals(message)){
|
message = ((FieldError) objectError).getField() + ": " + message;
|
||||||
message = str[1] + ":" + message;
|
|
||||||
}
|
}
|
||||||
return buildResponseEntity(ApiError.error(message));
|
return buildResponseEntity(ApiError.error(message));
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
|
|
||||||
private final ColumnInfoRepository columnInfoRepository;
|
private final ColumnInfoRepository columnInfoRepository;
|
||||||
|
|
||||||
|
private final String CONFIG_MESSAGE = "请先配置生成器";
|
||||||
@Override
|
@Override
|
||||||
public Object getTables() {
|
public Object getTables() {
|
||||||
// 使用预编译防止sql注入
|
// 使用预编译防止sql注入
|
||||||
|
@ -169,7 +170,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
@Override
|
@Override
|
||||||
public void generator(GenConfig genConfig, List<ColumnInfo> columns) {
|
public void generator(GenConfig genConfig, List<ColumnInfo> columns) {
|
||||||
if (genConfig.getId() == null) {
|
if (genConfig.getId() == null) {
|
||||||
throw new BadRequestException("请先配置生成器");
|
throw new BadRequestException(CONFIG_MESSAGE);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
GenUtil.generatorCode(columns, genConfig);
|
GenUtil.generatorCode(columns, genConfig);
|
||||||
|
@ -182,7 +183,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns) {
|
public ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns) {
|
||||||
if (genConfig.getId() == null) {
|
if (genConfig.getId() == null) {
|
||||||
throw new BadRequestException("请先配置生成器");
|
throw new BadRequestException(CONFIG_MESSAGE);
|
||||||
}
|
}
|
||||||
List<Map<String, Object>> genList = GenUtil.preview(columns, genConfig);
|
List<Map<String, Object>> genList = GenUtil.preview(columns, genConfig);
|
||||||
return new ResponseEntity<>(genList, HttpStatus.OK);
|
return new ResponseEntity<>(genList, HttpStatus.OK);
|
||||||
|
@ -191,7 +192,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
@Override
|
@Override
|
||||||
public void download(GenConfig genConfig, List<ColumnInfo> columns, HttpServletRequest request, HttpServletResponse response) {
|
public void download(GenConfig genConfig, List<ColumnInfo> columns, HttpServletRequest request, HttpServletResponse response) {
|
||||||
if (genConfig.getId() == null) {
|
if (genConfig.getId() == null) {
|
||||||
throw new BadRequestException("请先配置生成器");
|
throw new BadRequestException(CONFIG_MESSAGE);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
File file = new File(GenUtil.download(columns, genConfig));
|
File file = new File(GenUtil.download(columns, genConfig));
|
||||||
|
|
|
@ -56,13 +56,6 @@ public class AppRun {
|
||||||
return new SpringContextHolder();
|
return new SpringContextHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ServletWebServerFactory webServerFactory() {
|
|
||||||
TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
|
|
||||||
fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
|
|
||||||
return fa;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问首页提示
|
* 访问首页提示
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package me.zhengjie.config;
|
||||||
|
|
||||||
|
import org.apache.catalina.connector.Connector;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author bearBoy80
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
public class RelaxedQueryCharsConnectorCustomizer implements TomcatConnectorCustomizer {
|
||||||
|
@Override
|
||||||
|
public void customize(Connector connector) {
|
||||||
|
connector.setProperty("relaxedQueryChars", "[]{}");
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,6 +59,12 @@ public class MenuServiceImpl implements MenuService {
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
private static final String HTTP_PRE = "http://";
|
||||||
|
private static final String HTTPS_PRE = "https://";
|
||||||
|
private static final String YES_STR = "是";
|
||||||
|
private static final String NO_STR = "否";
|
||||||
|
private static final String BAD_REQUEST = "外链必须以http://或者https://开头";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
|
public List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
|
||||||
Sort sort = Sort.by(Sort.Direction.ASC, "menuSort");
|
Sort sort = Sort.by(Sort.Direction.ASC, "menuSort");
|
||||||
|
@ -114,13 +120,12 @@ public class MenuServiceImpl implements MenuService {
|
||||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(resources.getPid().equals(0L)){
|
if (Long.valueOf(0L).equals(resources.getPid())) {
|
||||||
resources.setPid(null);
|
resources.setPid(null);
|
||||||
}
|
}
|
||||||
if(resources.getIFrame()){
|
if(resources.getIFrame()){
|
||||||
String http = "http://", https = "https://";
|
if (!(resources.getPath().toLowerCase().startsWith(HTTP_PRE)||resources.getPath().toLowerCase().startsWith(HTTPS_PRE))) {
|
||||||
if (!(resources.getPath().toLowerCase().startsWith(http)||resources.getPath().toLowerCase().startsWith(https))) {
|
throw new BadRequestException(BAD_REQUEST);
|
||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuRepository.save(resources);
|
menuRepository.save(resources);
|
||||||
|
@ -140,9 +145,8 @@ public class MenuServiceImpl implements MenuService {
|
||||||
ValidationUtil.isNull(menu.getId(),"Permission","id",resources.getId());
|
ValidationUtil.isNull(menu.getId(),"Permission","id",resources.getId());
|
||||||
|
|
||||||
if(resources.getIFrame()){
|
if(resources.getIFrame()){
|
||||||
String http = "http://", https = "https://";
|
if (!(resources.getPath().toLowerCase().startsWith(HTTP_PRE)||resources.getPath().toLowerCase().startsWith(HTTPS_PRE))) {
|
||||||
if (!(resources.getPath().toLowerCase().startsWith(http)||resources.getPath().toLowerCase().startsWith(https))) {
|
throw new BadRequestException(BAD_REQUEST);
|
||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Menu menu1 = menuRepository.findByTitle(resources.getTitle());
|
Menu menu1 = menuRepository.findByTitle(resources.getTitle());
|
||||||
|
@ -322,9 +326,9 @@ public class MenuServiceImpl implements MenuService {
|
||||||
map.put("菜单标题", menuDTO.getTitle());
|
map.put("菜单标题", menuDTO.getTitle());
|
||||||
map.put("菜单类型", menuDTO.getType() == null ? "目录" : menuDTO.getType() == 1 ? "菜单" : "按钮");
|
map.put("菜单类型", menuDTO.getType() == null ? "目录" : menuDTO.getType() == 1 ? "菜单" : "按钮");
|
||||||
map.put("权限标识", menuDTO.getPermission());
|
map.put("权限标识", menuDTO.getPermission());
|
||||||
map.put("外链菜单", menuDTO.getIFrame() ? "是" : "否");
|
map.put("外链菜单", menuDTO.getIFrame() ? YES_STR : NO_STR);
|
||||||
map.put("菜单可见", menuDTO.getHidden() ? "否" : "是");
|
map.put("菜单可见", menuDTO.getHidden() ? NO_STR : YES_STR);
|
||||||
map.put("是否缓存", menuDTO.getCache() ? "是" : "否");
|
map.put("是否缓存", menuDTO.getCache() ? YES_STR : NO_STR);
|
||||||
map.put("创建日期", menuDTO.getCreateTime());
|
map.put("创建日期", menuDTO.getCreateTime());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -185,6 +185,12 @@
|
||||||
<version>1.6.2</version>
|
<version>1.6.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-text</artifactId>
|
||||||
|
<version>1.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 解析客户端操作系统、浏览器信息 -->
|
<!-- 解析客户端操作系统、浏览器信息 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>nl.basjes.parse.useragent</groupId>
|
<groupId>nl.basjes.parse.useragent</groupId>
|
||||||
|
|
Loading…
Reference in New Issue