1、日志配置

master
wangbing 5 years ago
parent 73edc94e0e
commit a394852b42

@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<version>2.1.2.RELEASE</version>
<relativePath/>
</parent>
<repositories>
@ -32,48 +32,60 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
<commons-io-version>2.6</commons-io-version>
<pagehelper-version>1.2.5</pagehelper-version>
<mybatis-version>1.3.2</mybatis-version>
<ehcache-version>1.1.0</ehcache-version>
<dozer-version>5.5.1</dozer-version>
<spring-cloud.version>Greenwich.RC2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mybatis 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-devtools</artifactId>-->
<!--<scope>provided</scope>-->
<!--<optional>true</optional>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-test</artifactId>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-security</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.poi</groupId>-->
<!--<artifactId>poi-ooxml</artifactId>-->
<!--<version>3.14</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.poi</groupId>-->
<!--<artifactId>poi-ooxml-schemas</artifactId>-->
<!--<version>3.14</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
@ -90,6 +102,43 @@
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper-version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.caches</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>${ehcache-version}</version>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>${dozer-version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<!-- 项目名称 -->
<finalName>dbtool</finalName>

@ -5,7 +5,7 @@ import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
import xyz.wbsite.dbtool.javafx.po.AndroidOption;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.web.framework.utils.ZipUtil;
import xyz.wbsite.dbtool.web.frame.utils.ZipUtil;
import javax.validation.constraints.NotNull;
import java.io.File;

@ -4,7 +4,7 @@ import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.SBMDBOption;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.web.framework.utils.ZipUtil;
import xyz.wbsite.dbtool.web.frame.utils.ZipUtil;
import javax.validation.constraints.NotNull;
import java.io.File;

@ -7,7 +7,6 @@ import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
import xyz.wbsite.dbtool.javafx.manger.XmlManager;
import xyz.wbsite.dbtool.javafx.po.*;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.web.framework.IDgenerator;
import java.io.File;
import java.util.Date;
@ -598,6 +597,7 @@ public class SpringBootCallable implements Callable {
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "Base64Util.java"), option + "/java/frame/utils/Base64Util.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "AESUtil.java"), option + "/java/frame/utils/AESUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "CookieUtil.java"), option + "/java/frame/utils/CookieUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "FileUtil.java"), option + "/java/frame/utils/FileUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "LogUtil.java"), option + "/java/frame/utils/LogUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/frame/utils/MapperUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/frame/utils/MD5Util.java", ctx);

@ -4,7 +4,7 @@ import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.VueOption;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.web.framework.utils.ZipUtil;
import xyz.wbsite.dbtool.web.frame.utils.ZipUtil;
import javax.validation.constraints.NotNull;
import java.io.File;

@ -0,0 +1,340 @@
package xyz.wbsite.dbtool.web.action;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import xyz.wbsite.dbtool.web.config.ActionConfig;
import xyz.wbsite.dbtool.web.frame.base.*;
import xyz.wbsite.dbtool.web.frame.auth.LocalData;
import xyz.wbsite.dbtool.web.frame.utils.FileUtil;
import xyz.wbsite.dbtool.web.frame.utils.MapperUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ControllerController
* htm{@link GlobalController#action(Model, HttpServletRequest, HttpServletResponse)}
* {@link GlobalController#exceptionHandler(HttpServletRequest, HttpServletResponse, Model, Exception)}
* {@link GlobalController#upload(HttpServletRequest)}
* {@link GlobalController#download(String)}
* {@link GlobalController#sse(String)}
* <p>
* Request
* Api#Example#Request ==> ##Request
*
* @author author
* @version 0.0.1
* @since 2019-06-16
*/
@Controller
@ControllerAdvice
public class GlobalController implements ErrorController {
@Value("${web.welcome.page}")
private String homePage;
@Value("${web.login.page}")
private String loginPage;
@Autowired
private FreeMarkerViewResolver viewResolver;
/**
*
*
* @param request
* @param response
* @param exception
* @return
*/
@ExceptionHandler(Exception.class)
public String exceptionHandler(HttpServletRequest request, HttpServletResponse response, Model model, Exception exception) {
StringBuffer msg = new StringBuffer("");
if (exception != null) {
msg = new StringBuffer("");
String message = exception.toString();
int length = exception.getStackTrace().length;
if (length > 0) {
msg.append("<a>").append(message).append("</a><br>");
for (int i = 0; i < length; i++) {
msg.append("<a>").append(exception.getStackTrace()[i]).append("</a><br>");
}
} else {
msg.append(message);
}
}
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
model.addAttribute("msg", msg.toString());
return "500";
}
private final static String ERROR_PATH = "/error";
@Override
public String getErrorPath() {
return ERROR_PATH;
}
@RequestMapping(value = ERROR_PATH)
public String error(HttpServletRequest request, HttpServletResponse response) {
switch (response.getStatus()) {
case 404:
return "404";
case 403:
try {
response.sendRedirect("/login.htm");
} catch (IOException e) {
e.printStackTrace();
}
return "403";
case 500:
return "500";
default:
return "403";
}
}
@RequestMapping("/")
public String home() {
Token token = LocalData.getToken();
if (token == null) {
return "redirect:" + loginPage;
} else {
return "redirect:" + homePage;
}
}
/**
* layoutscreen
* 使layoutViewNameTranslator
*
* @param model
* @param request
*/
@RequestMapping({"/**/*.htm"})
public String action(Model model, HttpServletRequest request, HttpServletResponse response) {
String servletPath = request.getServletPath();// /**/*.htm
String layout = "/layout/default";
String action = LocalData.getAction();// **/*
Pattern compile = Pattern.compile("^/(.+)\\.htm");
Matcher matcher = compile.matcher(servletPath);
if (matcher.find()) {
action = matcher.group(1);
LocalData.setAction(action);
}
try {
LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE);
Locale locale = localeResolver.resolveLocale(request);
{//查询screen
String[] split = action.split("/");
StringBuilder sb = new StringBuilder("");
sb.append("screen");
for (int i = 0; i < split.length; i++) {
sb.append(File.separator);
sb.append(split[i]);
}
layout = sb.toString();
View view = viewResolver.resolveViewName(layout, locale);
if (view == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return error(request, response);
}
// 尝试执行Screen执行器(服务器渲染),并返回视图模板
try {
String beanClassName = (ActionConfig.SCREEN_PREFIX + action).toLowerCase();
Screen screenExec = LocalData.getApplicationContext().getBean(beanClassName, Screen.class);
screenExec.exec(model, request, response);
if (response.getStatus() != HttpServletResponse.SC_OK) {
return error(request, response);
}
} catch (BeansException e) {
}
}
{//查找layout
String[] split = action.split("/");
int lt = split.length;
while (lt > 0) {
StringBuilder sb = new StringBuilder("");
sb.append("layout");
for (int i = 0; i < lt - 1; i++) {
sb.append(File.separator);
sb.append(split[i]);
}
layout = sb.toString() + File.separator + split[split.length - 1];
View view = viewResolver.resolveViewName(layout, locale);
//无法找到对应layout使用默认layout
if (view == null) {
layout = sb.toString() + File.separator + "default";
View defaultView = viewResolver.resolveViewName(layout, locale);
if (null == defaultView && lt == 1) {
System.err.println("can not find layout/default.ftl");
} else if (null == defaultView) {
lt--;
} else {
break;
}
} else {
break;
}
}
}
} catch (Exception e) {
return exceptionHandler(request, response, model, e);
}
//todo 可在此获取共性数据(也可以在全局拦截器GlobalHandlerInterceptor、拦截器作用域比此更高)
//todo 例如用户信息等。其他业务数据在页面渲染后通过Ajax请求
return layout;
}
@RequestMapping("/upload")
@ResponseBody
public BaseResponse upload(HttpServletRequest request) {
FileUploadResponse fileUploadResponse = new FileUploadResponse();
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
MultipartFile target = multipartHttpServletRequest.getFile("file");
String fileName = target.getOriginalFilename();
//========
//处理文件
//========
fileUploadResponse.setId(1L);
fileUploadResponse.setUrl("example.com\\img\\1.jpg");
fileUploadResponse.setDownloadUrl("example.com\\img\\1.jpg");
if (target != null) {
fileUploadResponse.addError(ErrorType.BUSINESS_ERROR, "文件上传成功,但未处理文件[" + fileName + "]!");
} else {
fileUploadResponse.addError(ErrorType.BUSINESS_ERROR, "文件上传失败!");
}
return fileUploadResponse;
}
@RequestMapping("/ajax/{module}/{target}/{method}")
@ResponseBody
public BaseResponse ajax(@PathVariable String module, @PathVariable String target, @PathVariable String method, @RequestBody String param) {
BaseResponse baseResponse = null;
try {
String beanClassName = (ActionConfig.AJAX_PREFIX + module + "/" + target).toLowerCase();
Object ajax = LocalData.getApplicationContext().getBean(beanClassName);
Class ajaxClass = ajax.getClass();
Method methodC = ajaxClass.getMethod(method, String.class);
Object invoke = methodC.invoke(ajax, param);
if (invoke instanceof BaseResponse) {
baseResponse = (BaseResponse) invoke;
} else {
baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "方法返回值错误!");
}
} catch (BeansException e) {
baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "未找到对应的目标!");
} catch (NoSuchMethodException e) {
baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "未找到对应的方法!");
} catch (IllegalAccessException e) {
baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "方法执必须公开!");
} catch (InvocationTargetException e) {
baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "方法执行错误!");
}
return baseResponse;
}
@RequestMapping("/download")
@ResponseBody
public ResponseEntity<byte[]> download(@RequestParam(value = "file", required = false) String file) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//========
//下载DEMO
//========
if (file == null) {
file = "test.txt";
headers.setContentDispositionFormData("attachment", new String(file.getBytes("UTF-8"), "iso-8859-1"));
return new ResponseEntity<byte[]>("test".getBytes(),
headers, HttpStatus.CREATED);
}
return new ResponseEntity<byte[]>(FileUtil.readFileToByteArray(new File(file)),
headers, HttpStatus.CREATED);
}
private static ConcurrentHashMap<String, SseEmitter> sseMap = new ConcurrentHashMap();
/**
* Ssejs
* Sse{@link GlobalController#sseMap}
* Sse{@link GlobalController#pushAll}
*/
@RequestMapping(value = "/sse/{userId}", produces = "text/event-stream;charset=UTF-8")
public SseEmitter sse(@PathVariable String userId) {
SseEmitter sseEmitter = new SseEmitter(10000000L);
if (sseMap.get(userId) != null) {
sseMap.remove(userId);
}
sseMap.put(userId, sseEmitter);
return sseEmitter;
}
/**
* Sse
*
* @param data
*/
public static void pushAll(Object data) {
for (String s : sseMap.keySet()) {
try {
sseMap.get(s).send(MapperUtil.toJson(data), MediaType.APPLICATION_JSON);
} catch (IOException e) {
sseMap.remove(s);
}
}
}
}

@ -0,0 +1,25 @@
package xyz.wbsite.dbtool.web.action.ajax.system;
import xyz.wbsite.dbtool.web.frame.auth.LocalData;
import xyz.wbsite.dbtool.web.frame.base.BaseResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AuthAjax {
public BaseResponse login(String jsonParam) {
BaseResponse baseResponse = new BaseResponse();
// todo 设置cookie
HttpServletRequest request = LocalData.getRequest();
HttpServletResponse response = LocalData.getResponse();
Cookie token = new Cookie("token", "");
token.setDomain(request.getServerName());
token.setPath("/");
response.addCookie(token);
return baseResponse;
}
}

@ -0,0 +1,15 @@
package xyz.wbsite.dbtool.web.action.control;
import xyz.wbsite.dbtool.web.frame.base.Control;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Header extends Control {
@Override
public void exec(Model model, HttpServletRequest request, HttpServletResponse response) {
}
}

@ -0,0 +1,23 @@
package xyz.wbsite.dbtool.web.action.screen;
import xyz.wbsite.dbtool.web.frame.base.Screen;
import org.springframework.ui.Model;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Index extends Screen {
@Override
public void exec(Model model, HttpServletRequest request, HttpServletResponse response) {
model.addAttribute("hello", "Hello world!!!");
model.addAttribute("status", 0);
ArrayList<String> citys = new ArrayList<>();
citys.add("北京");
citys.add("上海");
citys.add("深圳");
model.addAttribute("citys", citys);
}
}

@ -0,0 +1,125 @@
package xyz.wbsite.dbtool.web.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import xyz.wbsite.dbtool.web.frame.base.Control;
import xyz.wbsite.dbtool.web.frame.base.Screen;
import xyz.wbsite.dbtool.web.frame.utils.LogUtil;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ScreenControl
* <p>
* Screen {@link ActionConfig#registryScreen}
* Control {@link ActionConfig#registryControl}
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Configuration
public class ActionConfig implements BeanDefinitionRegistryPostProcessor {
public static String SCREEN_PREFIX = "/screen/";
public static String CONTROL_PREFIX = "/control/";
public static String AJAX_PREFIX = "/ajax/";
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
String aPackage = this.getClass().getPackage().getName();
Pattern compile = Pattern.compile("(.*)\\.config");
Matcher matcher = compile.matcher(aPackage);
if (matcher.find()) {
String basePackage = matcher.group(1);
registryScreen(basePackage + ".action.screen", beanDefinitionRegistry);
registryControl(basePackage + ".action.control", beanDefinitionRegistry);
registryAjax(basePackage + ".action.ajax", beanDefinitionRegistry);
}
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
}
private int registryScreen(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) {
ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
classPathBeanDefinitionScanner.addIncludeFilter(new TypeFilter() {
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
if (metadataReader.getClassMetadata().getSuperClassName().equals(Screen.class.getName())) {
return true;
}
return false;
}
});
classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry) {
String beanClassName = beanDefinition.getBeanClassName();
String beamName = beanClassName.replaceAll(basePackage + ".", SCREEN_PREFIX).replaceAll("\\.","/").toLowerCase();
LogUtil.i("registry screen " + beamName);
return beamName;
}
});
return classPathBeanDefinitionScanner.scan(basePackage);
}
private int registryControl(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) {
ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
classPathBeanDefinitionScanner.addIncludeFilter(new TypeFilter() {
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
if (metadataReader.getClassMetadata().getSuperClassName().equals(Control.class.getName())) {
return true;
}
return false;
}
});
classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry) {
String beanClassName = beanDefinition.getBeanClassName();
String beamName = beanClassName.replaceAll(basePackage + ".", CONTROL_PREFIX).replaceAll("\\.","/").toLowerCase();
LogUtil.i("registry control " + beamName);
return beamName;
}
});
return classPathBeanDefinitionScanner.scan(basePackage);
}
private int registryAjax(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) {
ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
classPathBeanDefinitionScanner.addIncludeFilter(new TypeFilter() {
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
return true;
}
});
classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry) {
String beanClassName = beanDefinition.getBeanClassName();
if (beanClassName != null && beanClassName.endsWith("Ajax")) {
beanClassName = beanClassName.substring(0, beanClassName.length() - 4);
}
String beamName = beanClassName.replaceAll(basePackage + ".", AJAX_PREFIX).replaceAll("\\.","/").toLowerCase();
LogUtil.i("registry ajax " + beamName);
return beamName;
}
});
return classPathBeanDefinitionScanner.scan(basePackage);
}
}

@ -0,0 +1,124 @@
package xyz.wbsite.dbtool.web.config;
import xyz.wbsite.dbtool.web.frame.auth.LocalData;
import xyz.wbsite.dbtool.web.frame.base.Control;
import xyz.wbsite.dbtool.web.frame.utils.UrlUtil;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.support.BindingAwareModelMap;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;
import java.util.Locale;
import static xyz.wbsite.dbtool.web.config.ActionConfig.CONTROL_PREFIX;
import static xyz.wbsite.dbtool.web.config.ActionConfig.SCREEN_PREFIX;
@Configuration
public class FreeMarkerConfig {
@Autowired
private FreeMarkerViewResolver viewResolver;
@Autowired
private freemarker.template.Configuration configuration;
@Value("${server.servlet.context-path}")
private String context;
private String suffix = ".ftl";
@PostConstruct
public void setSharedVariable() throws TemplateModelException {
// 全局共享变量、函数
configuration.setSharedVariable("context", context);
configuration.setSharedVariable("screenHolder", new ScreenHolder());
configuration.setSharedVariable("controlHolder", new ControlHolder());
configuration.setSharedVariable("UrlUtil", new UrlUtil());
}
private class ScreenHolder implements TemplateMethodModelEx {
@Override
public Object exec(List list) throws TemplateModelException {
try {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE);
String servletPath = LocalData.getAction();
servletPath = servletPath.replaceAll("^/", "");
String[] split = servletPath.split("/");
StringBuilder sb = new StringBuilder("");
// 分割组装路径
for (int i = 0; i < split.length; i++) {
sb.append(split[i]);
if (i != split.length - 1) {
sb.append(File.separator);
}
}
Locale locale = localeResolver.resolveLocale(request);
String viewName = "screen" + File.separator + sb.toString();
View view = viewResolver.resolveViewName(viewName, locale);
//无法找到对应screen
if (view == null) {
return "";
} else {
return SCREEN_PREFIX + servletPath + suffix;
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
private class ControlHolder implements TemplateMethodModelEx {
@Override
public Object exec(List list) throws TemplateModelException {
String control = "";
if (list.size() != 1) {
return "";
}
Object o = list.get(0);
if (o instanceof SimpleScalar) {
control = ((SimpleScalar) o).getAsString();
}
// 查找是否存在对应控制面板执行器
Control controlExec = null;
try {
String beanClassName = (CONTROL_PREFIX + control).toLowerCase();
controlExec = LocalData.getApplicationContext().getBean(beanClassName, Control.class);
HttpServletRequest request = LocalData.getRequest();
HttpServletResponse response = LocalData.getResponse();
BindingAwareModelMap modelMap = new BindingAwareModelMap();
controlExec.exec(modelMap, request, response);
for (String key : modelMap.keySet()) {
request.setAttribute(key, modelMap.get(key));
}
} catch (BeansException e) {
}
control = control.replaceAll("/", File.separator);
return CONTROL_PREFIX + control + suffix;
}
}
}

@ -0,0 +1,119 @@
package xyz.wbsite.dbtool.web.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.Authentication;
import xyz.wbsite.dbtool.web.frame.base.Token;
import xyz.wbsite.dbtool.web.frame.utils.CookieUtil;
import xyz.wbsite.dbtool.web.frame.auth.LocalData;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${web.url.auth.included}")
private String[] included;
@Value("${web.url.auth.excluded}")
private String[] excluded;
@Value("${spring.mvc.static-path-pattern}")
private String[] staticPath;
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().mvcMatchers(staticPath);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token
.authorizeRequests()
.antMatchers(excluded).permitAll()// 放行排除的URL
.antMatchers(included).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.and().cors()
.and().headers().frameOptions().disable()
.and().csrf().disable();
}
/**
*
* <p>
* Using generated security password: f6b42a66-71b1-4c31-b6a8-942838c81408
*
* @return
* @throws Exception
*/
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
public static class TokenFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
String token = request.getParameter("token");
if (token == null || token.isEmpty()) {
token = CookieUtil.getCookieValue(request.getCookies(), "token");
}
if (token == null) {
LocalData.setToken(LocalData.getTempToken());
} else {
// 组装Token ~ 这边根据实际的业务组装Token
Token token1 = new Token();
token1.setId(1L);
token1.setUserId(1L);
token1.setUserName("admin");
//继承临时Token
token1.addResourceSet(LocalData.getTempToken());
//管理员特有资源(这边请用正则表达式)
token1.putResource(".*");
LocalData.setToken(token1);
}
// Action
String servletPath = request.getServletPath();
Pattern compile = Pattern.compile("^/(.+)\\.htm");
Matcher matcher = compile.matcher(servletPath);
if (matcher.find()) {
LocalData.setAction(matcher.group(1));
}
filterChain.doFilter(servletRequest, servletResponse);
}
}
@Bean("Authorization")
public Object getAuthorization() {
return new Object() {
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
// 授权
Token token_ = LocalData.getToken();
if (token_.hasResource(request.getServletPath())) {
return true;
}
return false;
}
};
}
}

@ -1,14 +1,16 @@
package xyz.wbsite.dbtool.web.framework.config;
package xyz.wbsite.dbtool.web.config;
import xyz.wbsite.dbtool.web.framework.utils.LogUtil;
import xyz.wbsite.dbtool.web.framework.utils.ProcessUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import xyz.wbsite.dbtool.web.action.GlobalController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.Executors;
/**
@ -22,15 +24,17 @@ public class TaskConfig implements SchedulingConfigurer {
@Scheduled(cron="0/30 * * * * ? ")
public void task(){
LogUtil.i("--------------------Task--------------------");
boolean process = ProcessUtil.findProcess("sunny.exe");
if (!process){
ProcessUtil.execExe("D:/windows_amd64/sunny.exe clientid 201822147996");
}
// todo 自定实现的定时任务
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
HashMap<String, String> data = new HashMap<>();
data.put("time", format.format(new Date()));
GlobalController.pushAll(data);
}
/**
* 线
* Spring Schedule 线
* 线 SchedulingConfigurerconfigureTasks
*
* @param scheduledTaskRegistrar
*/
@Override

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.config;
package xyz.wbsite.dbtool.web.config;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;

@ -0,0 +1,122 @@
package xyz.wbsite.dbtool.web.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import xyz.wbsite.dbtool.web.frame.utils.LogUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Value("${web.welcome.page}")
private String homePage;
@Value("${spring.mvc.static-path-pattern}")
private String[] staticPath;
/**
*
*
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 全局异常收集拦截器
registry.addInterceptor(new HandlerInterceptorAdapter() {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
super.afterCompletion(request, response, handler, ex);
if (ex != null) {
LogUtil.dumpException(ex);
}
}
}).addPathPatterns("/**").excludePathPatterns(staticPath);
}
/**
* Jackson
* <p>
* 1LonglongStringjavascriptNumber
*
* @param converters
*/
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter) converter).getObjectMapper();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
}
}
}
// @Bean
// @Profile("prod")
// public ServletWebServerFactory servletContainer() {
// TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
//
// // 基本参数
// String keyStore = "1754557_www.wbsite.xyz.pfx";
// String keyStorePassword = "s98n7CLd";
// String keyStoreType = "PKCS12";
// int httpsPort = 443;
//
// File keystore = null;
// // 正常开发可以通过getFile()获取打包jar后无法直接获取File对象需将文件考出
// try {
// keystore = new ClassPathResource(keyStore).getFile();
// } catch (IOException ex) {
// try {
// ApplicationHome home = new ApplicationHome(getClass());
// // 当前运行jar文件
// File jarFile = home.getSource();
// //jar同目录
// keystore = new File(jarFile.getParent(), keyStore);
//
// InputStream inputStream = new ClassPathResource(keyStore).getInputStream();
// byte[] bytes = new byte[inputStream.available()];
//
// inputStream.read(bytes);
//
// inputStream.close();
//
// FileOutputStream fileOutputStream = new FileOutputStream(keystore);
// fileOutputStream.write(bytes);
// fileOutputStream.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// // 创建Connector
// Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
// Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
// connector.setScheme("https");
// connector.setSecure(true);
// connector.setPort(httpsPort);
// protocol.setSSLEnabled(true);
// protocol.setKeystoreFile(keystore.getAbsolutePath());
// protocol.setKeystorePass(keyStorePassword);
// protocol.setKeystoreType(keyStoreType);
//
// // 添加
// tomcat.addAdditionalTomcatConnectors(connector);
// return tomcat;
// }
}

@ -1,70 +0,0 @@
package xyz.wbsite.dbtool.web.controller;
import xyz.wbsite.dbtool.web.framework.LocalData;
import xyz.wbsite.dbtool.web.framework.Message;
import xyz.wbsite.dbtool.web.framework.base.BaseResponse;
import xyz.wbsite.dbtool.web.framework.base.Error;
import xyz.wbsite.dbtool.web.framework.base.ErrorType;
import xyz.wbsite.dbtool.web.framework.base.Token;
import xyz.wbsite.dbtool.web.framework.utils.LogUtil;
import xyz.wbsite.dbtool.web.framework.utils.MapperUtil;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class AjaxController {
@RequestMapping("/ajax")
public BaseResponse ajax(@RequestParam("method") String method, HttpServletRequest request, HttpServletResponse response) {
BaseResponse baseResponse = new BaseResponse();
String line = null;
TreeNode treeNode = null;
try {
if (method == null) {
baseResponse.addError(new xyz.wbsite.dbtool.web.framework.base.Error(ErrorType.BUSINESS_ERROR, "请求方法不能为空!"));
return baseResponse;
}
Token token = LocalData.getToken();
if (token == null) {
token = LocalData.getTempToken();
}
if (!token.hasResource(method)) {
baseResponse.addError(new Error(ErrorType.BUSINESS_ERROR, "无权调用该接口!"));
return baseResponse;
}
InputStreamReader isr = new InputStreamReader(request.getInputStream());
BufferedReader in = new BufferedReader(isr);
line = in.readLine();
treeNode = MapperUtil.toTree(line);
switch (method) {
// 创建注释
case "ajax.example.user.create":
// baseResponse = createUser(treeNode, token);
break;
default:
baseResponse.addError(ErrorType.INVALID_PARAMETER, Message.NOT_EXIST_METHOD);
break;
}
} catch (Exception ex) {
baseResponse.addError(ErrorType.SYSTEM_ERROR, Message.ERROR_500);
LogUtil.dumpException(ex);
} finally {
if (baseResponse.hasError()) {
LogUtil.e("请求方法" + method + ", 请求参数:" + line);
LogUtil.e("返回结果包含异常" + MapperUtil.toJson(baseResponse));
}
}
return baseResponse;
}
}

@ -1,77 +0,0 @@
package xyz.wbsite.dbtool.web.controller;
import xyz.wbsite.dbtool.web.framework.utils.LogUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
@Controller
@ControllerAdvice
public class GlobalController {
/**
*
*
* @param request
* @param response
* @param exception
* @return
*/
@ExceptionHandler(Exception.class)
public String excepitonHandler(HttpServletRequest request, HttpServletResponse response, Model model, Exception exception) {
StringBuffer msg = new StringBuffer("");
if (exception != null) {
msg = new StringBuffer("");
String message = exception.toString();
int length = exception.getStackTrace().length;
if (length > 0) {
msg.append("<a>").append(message).append("</a><br>");
for (int i = 0; i < length; i++) {
msg.append("<a>").append(exception.getStackTrace()[i]).append("</a><br>");
}
} else {
msg.append(message);
}
}
model.addAttribute("msg", msg.toString());
return "500";
}
/**
* layoutscreen
*
* @param model
* @param request
*/
@RequestMapping("**^\\.*")
public void hold(HttpServletRequest request, HttpServletResponse response, Model model) {
LogUtil.i("未明确指定控制器访问路径:" + request.getRequestURI());
//todo 可在此获取公共部分数据例如用户信息等。其他业务数据在页面渲染后通过Ajax请求
}
/**
* 使layoutViewNameTranslator
*
* @param model
* @param request
*/
@RequestMapping({"/", "index"})
public void index(Model model, HttpServletRequest request) throws Exception {
model.addAttribute("hello", "Hello world!!!");
model.addAttribute("status", 0);
ArrayList<String> citys = new ArrayList<>();
citys.add("北京");
citys.add("上海");
citys.add("深圳");
model.addAttribute("citys", citys);
}
}

@ -0,0 +1,84 @@
package xyz.wbsite.dbtool.web.frame.auth;
import xyz.wbsite.dbtool.web.frame.base.Token;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* LocalData -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class LocalData {
private static Token temp = null;
private static Token system = null;
static {
// 组装临时Token和系统Token
temp = new Token();
temp.setId(-1);
temp.setUserId(-1);
temp.setUserName("游客");
temp.putResource("ajax.system.admin.login");
system = new Token();
system.setId(0);
system.setUserId(0);
system.setUserName("system");
system.putResource(".*");
}
public static Token getTempToken() {
return temp;
}
public static Token getSysToken() {
return system;
}
/**
* target = '/aa/bb'
*/
private static final ThreadLocal<String> actionHolder = new ThreadLocal();
public static String getAction() {
return actionHolder.get();
}
public static void setAction(String action) {
actionHolder.set(action);
}
/**
*
*/
private static final ThreadLocal<Token> tokenHolder = new ThreadLocal();
public static Token getToken() {
return tokenHolder.get();
}
public static void setToken(Token token) {
tokenHolder.set(token);
}
public static HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
public static HttpServletResponse getResponse() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
}
public static ApplicationContext getApplicationContext() {
return WebApplicationContextUtils.getWebApplicationContext(getRequest().getServletContext());
}
}

@ -0,0 +1,17 @@
package xyz.wbsite.dbtool.web.frame.auth;
import xyz.wbsite.dbtool.web.frame.validation.DictValidator;
import javax.validation.Constraint;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = DictValidator.class)
public @interface Verification {
String name() default "";
}

@ -1,7 +1,7 @@
package xyz.wbsite.dbtool.web.framework.base;
import com.fasterxml.jackson.annotation.JsonProperty;
package xyz.wbsite.dbtool.web.frame.base;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.Date;
/**
@ -12,7 +12,7 @@ import java.util.Date;
* @since 2017-01-01
*/
public class BaseEntity {
public class BaseEntity implements Serializable {
/**
*
@ -22,6 +22,7 @@ public class BaseEntity {
/**
*
*/
@JsonIgnore
private long createBy;
/**
@ -32,17 +33,19 @@ public class BaseEntity {
/**
*
*/
@JsonIgnore
private long lastUpdateBy;
/**
*
*/
@JsonIgnore
private Date lastUpdateTime;
/**
*
*/
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonIgnore
private boolean isDeleted;
public boolean getIsDeleted() {

@ -0,0 +1,29 @@
package xyz.wbsite.dbtool.web.frame.base;
/**
* BaseFindRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseFindRequest extends BaseGetAllRequest {
private int pageNumber = 1;
private int pageSize = 10;
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
import java.util.List;

@ -0,0 +1,32 @@
package xyz.wbsite.dbtool.web.frame.base;
/**
* BaseFindRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseGetAllRequest extends BaseRequest {
private String sortKey;
private SortType sortType;
public String getSortKey() {
return sortKey;
}
public void setSortKey(String sortKey) {
this.sortKey = sortKey;
}
public SortType getSortType() {
return sortType;
}
public void setSortType(SortType sortType) {
this.sortType = sortType;
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
/**
* BaseRequest -

@ -0,0 +1,38 @@
package xyz.wbsite.dbtool.web.frame.base;
import java.util.ArrayList;
import java.util.List;
/**
* BaseResponse -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseResponse {
private List<xyz.wbsite.dbtool.web.frame.base.Error> errors = new ArrayList();
public void addError(xyz.wbsite.dbtool.web.frame.base.Error error) {
this.errors.add(error);
}
public void addError(ErrorType type, String message) {
this.errors.add(new xyz.wbsite.dbtool.web.frame.base.Error(type, message));
}
public void addErrors(List<xyz.wbsite.dbtool.web.frame.base.Error> errors) {
this.errors.addAll(errors);
}
public boolean hasError() {
return this.errors.size() > 0;
}
/**
*
*/
public List<xyz.wbsite.dbtool.web.frame.base.Error> getErrors() {
return new ArrayList<xyz.wbsite.dbtool.web.frame.base.Error>(errors);
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
/**
* BaseSearchRequest -

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
/**
* BaseUpdateRequest -

@ -0,0 +1,10 @@
package xyz.wbsite.dbtool.web.frame.base;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public abstract class Control {
public abstract void exec(Model model, HttpServletRequest request, HttpServletResponse response);
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
/**
* Error -
@ -15,6 +15,9 @@ public class Error {
/*错误内容*/
private String message;
public Error() {
}
public Error(ErrorType type, String message) {
this.type = type;
this.message = message;

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
/**
* ErrorType -

@ -0,0 +1,34 @@
package xyz.wbsite.dbtool.web.frame.base;
public class FileUploadResponse extends BaseResponse {
private Long id;
private String url;
private String downloadUrl;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDownloadUrl() {
return downloadUrl;
}
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}
}

@ -0,0 +1,10 @@
package xyz.wbsite.dbtool.web.frame.base;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public abstract class Screen {
public abstract void exec(Model model, HttpServletRequest request, HttpServletResponse response);
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
/**
* SortTypeEnum -

@ -1,7 +1,6 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.base;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@ -49,10 +48,27 @@ public class Token implements Serializable {
}
public boolean hasResource(String resource){
return resourceSet.contains(resource);
for (String s : resourceSet) {
if (resource.matches(s)){
return true;
}
}
return false;
}
public void putResource(String resource){
resourceSet.add(resource);
}
public Set<String> getResourceSet() {
return resourceSet;
}
public void addResourceSet(Set<String> resourceSet){
this.resourceSet.addAll(resourceSet);
}
public void addResourceSet(Token token){
addResourceSet(token.getResourceSet());
}
}

@ -0,0 +1,110 @@
package xyz.wbsite.dbtool.web.frame.utils;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* AESUtil
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class AESUtil {
private static final String ALGORITHM = "AES";
private static final String ALGORITHM_STR = "AES/ECB/PKCS5Padding";
/**
*
*
* @param data
* @param secret
* @return base64
*/
public static byte[] encrypt(byte[] data, String secret) {
try {
if (secret.length() != 16) {
throw new IllegalArgumentException("secret's length is not 16");
}
SecretKeySpec key = new SecretKeySpec(secret.getBytes(), ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM_STR); // 创建密码器
cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
return cipher.doFinal(data);// 加密
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param data
* @param secret
* @return base64
*/
public static String encrypt2Base64(byte[] data, String secret) {
byte[] encrypt = encrypt(data, secret);
return Base64Util.encodeToString(encrypt, false);
}
/**
*
*
* @param data
* @param secret
* @return
*/
public static byte[] decrypt(byte[] data, String secret) {
try {
if (secret.length() != 16) {
throw new IllegalArgumentException("secret's length is not 16");
}
SecretKeySpec key = new SecretKeySpec(secret.getBytes(), ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM_STR);
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(data);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
public static byte[] decryptBase64(String base64Data, String secret) {
byte[] decode = Base64Util.decode(base64Data);
return decrypt(decode, secret);
}
public static String decrypt2String(String base64Data, String secret) {
byte[] bytes = decryptBase64(base64Data, secret);
try {
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.base;
package xyz.wbsite.dbtool.web.frame.utils;
import java.util.Arrays;
@ -15,15 +15,19 @@ public class Base64Util {
static {
Arrays.fill(IA, -1);
for(int i = 0, iS = CA.length; i < iS; i++)
for (int i = 0, iS = CA.length; i < iS; i++)
IA[CA[i]] = i;
IA['='] = 0;
}
public final static String encodeToString(byte[] sArr) {
return new String(encodeToChar(sArr, false));
}
public final static char[] encodeToChar(byte[] sArr, boolean lineSep) {
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if(sLen == 0)
if (sLen == 0)
return new char[0];
int eLen = (sLen / 3) * 3; // Length of even 24-bits.
@ -32,7 +36,7 @@ public class Base64Util {
char[] dArr = new char[dLen];
// Encode even 24-bits
for(int s = 0, d = 0, cc = 0; s < eLen; ) {
for (int s = 0, d = 0, cc = 0; s < eLen; ) {
// Copy next three bytes into lower 24 bits of int, paying attension to sign.
int i = (sArr[s++] & 0xff) << 16 | (sArr[s++] & 0xff) << 8 | (sArr[s++] & 0xff);
@ -43,7 +47,7 @@ public class Base64Util {
dArr[d++] = CA[i & 0x3f];
// Add optional line separator
if(lineSep && ++cc == 19 && d < dLen - 2) {
if (lineSep && ++cc == 19 && d < dLen - 2) {
dArr[d++] = '\r';
dArr[d++] = '\n';
cc = 0;
@ -52,7 +56,7 @@ public class Base64Util {
// Pad and encode last bits if source isn't even 24 bits.
int left = sLen - eLen; // 0 - 2.
if(left > 0) {
if (left > 0) {
// Prepare the int
int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
@ -65,117 +69,18 @@ public class Base64Util {
return dArr;
}
public final static byte[] decode(char[] sArr) {
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if(sLen == 0)
return new byte[0];
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for(int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if(IA[sArr[i]] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if((sLen - sepCnt) % 4 != 0)
return null;
int pad = 0;
for(int i = sLen; i > 1 && IA[sArr[--i]] <= 0; )
if(sArr[i] == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for(int s = 0, d = 0; d < len; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for(int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[sArr[s++]];
if(c >= 0)
i |= c << (18 - j * 6);
else
j--;
}
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if(d < len) {
dArr[d++] = (byte) (i >> 8);
if(d < len)
dArr[d++] = (byte) i;
}
}
return dArr;
}
/**
* Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as
* fast as {@link #decode(char[])}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
* Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045.
*
* @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0.
* @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned.
* @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br>
* No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
* little faster.
* @return A BASE64 encoded array. Never <code>null</code>.
*/
public final static byte[] decodeFast(char[] sArr) {
// Check special case
int sLen = sArr.length;
if(sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while(sIx < eIx && IA[sArr[sIx]] < 0)
sIx++;
// Trim illegal chars from end
while(eIx > 0 && IA[sArr[eIx]] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
int pad = sArr[eIx] == '=' ? (sArr[eIx - 1] == '=' ? 2 : 1) : 0; // Count '=' at end.
int cCnt = eIx - sIx + 1; // Content count including possible separators
int sepCnt = sLen > 76 ? (sArr[76] == '\r' ? cCnt / 78 : 0) << 1 : 0;
int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
// Decode all but the last 0 - 2 bytes.
int d = 0;
for(int cc = 0, eLen = (len / 3) * 3; d < eLen; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
// Add the bytes
dArr[d++] = (byte) (i >> 16);
dArr[d++] = (byte) (i >> 8);
dArr[d++] = (byte) i;
// If line separator, jump over it.
if(sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if(d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for(int j = 0; sIx <= eIx - pad; j++)
i |= IA[sArr[sIx++]] << (18 - j * 6);
for(int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
public final static String encodeToString(byte[] sArr, boolean lineSep) {
// Reuse char[] since we can't create a String incrementally anyway and StringBuffer/Builder would be slower.
return new String(encodeToChar(sArr, lineSep));
}
/**
@ -190,7 +95,7 @@ public class Base64Util {
public final static byte[] encodeToByte(byte[] sArr, boolean lineSep) {
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if(sLen == 0)
if (sLen == 0)
return new byte[0];
int eLen = (sLen / 3) * 3; // Length of even 24-bits.
@ -199,7 +104,7 @@ public class Base64Util {
byte[] dArr = new byte[dLen];
// Encode even 24-bits
for(int s = 0, d = 0, cc = 0; s < eLen; ) {
for (int s = 0, d = 0, cc = 0; s < eLen; ) {
// Copy next three bytes into lower 24 bits of int, paying attension to sign.
int i = (sArr[s++] & 0xff) << 16 | (sArr[s++] & 0xff) << 8 | (sArr[s++] & 0xff);
@ -210,7 +115,7 @@ public class Base64Util {
dArr[d++] = (byte) CA[i & 0x3f];
// Add optional line separator
if(lineSep && ++cc == 19 && d < dLen - 2) {
if (lineSep && ++cc == 19 && d < dLen - 2) {
dArr[d++] = '\r';
dArr[d++] = '\n';
cc = 0;
@ -219,7 +124,7 @@ public class Base64Util {
// Pad and encode last bits if source isn't an even 24 bits.
int left = sLen - eLen; // 0 - 2.
if(left > 0) {
if (left > 0) {
// Prepare the int
int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
@ -232,6 +137,53 @@ public class Base64Util {
return dArr;
}
public final static byte[] decode(char[] sArr) {
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if (sLen == 0)
return new byte[0];
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if (IA[sArr[i]] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if ((sLen - sepCnt) % 4 != 0)
return null;
int pad = 0;
for (int i = sLen; i > 1 && IA[sArr[--i]] <= 0; )
if (sArr[i] == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for (int s = 0, d = 0; d < len; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[sArr[s++]];
if (c >= 0)
i |= c << (18 - j * 6);
else
j--;
}
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if (d < len) {
dArr[d++] = (byte) (i >> 8);
if (d < len)
dArr[d++] = (byte) i;
}
}
return dArr;
}
/**
* Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with
* and without line separators.
@ -247,29 +199,29 @@ public class Base64Util {
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for(int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if(IA[sArr[i] & 0xff] < 0)
for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if (IA[sArr[i] & 0xff] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if((sLen - sepCnt) % 4 != 0)
if ((sLen - sepCnt) % 4 != 0)
return null;
int pad = 0;
for(int i = sLen; i > 1 && IA[sArr[--i] & 0xff] <= 0; )
if(sArr[i] == '=')
for (int i = sLen; i > 1 && IA[sArr[--i] & 0xff] <= 0; )
if (sArr[i] == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for(int s = 0, d = 0; d < len; ) {
for (int s = 0, d = 0; d < len; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for(int j = 0; j < 4; j++) { // j only increased if a valid char was found.
for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[sArr[s++] & 0xff];
if(c >= 0)
if (c >= 0)
i |= c << (18 - j * 6);
else
j--;
@ -277,9 +229,9 @@ public class Base64Util {
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if(d < len) {
if (d < len) {
dArr[d++] = (byte) (i >> 8);
if(d < len)
if (d < len)
dArr[d++] = (byte) i;
}
}
@ -287,10 +239,9 @@ public class Base64Util {
return dArr;
}
/**
* Decodes a BASE64 encoded byte array that is known to be resonably well formatted. The method is about twice as
* fast as {@link #decode(byte[])}. The preconditions are:<br>
* fast as {@link =#=decode(byte[])}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
@ -302,17 +253,17 @@ public class Base64Util {
public final static byte[] decodeFast(byte[] sArr) {
// Check special case
int sLen = sArr.length;
if(sLen == 0)
if (sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while(sIx < eIx && IA[sArr[sIx] & 0xff] < 0)
while (sIx < eIx && IA[sArr[sIx] & 0xff] < 0)
sIx++;
// Trim illegal chars from end
while(eIx > 0 && IA[sArr[eIx] & 0xff] < 0)
while (eIx > 0 && IA[sArr[eIx] & 0xff] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
@ -325,7 +276,7 @@ public class Base64Util {
// Decode all but the last 0 - 2 bytes.
int d = 0;
for(int cc = 0, eLen = (len / 3) * 3; d < eLen; ) {
for (int cc = 0, eLen = (len / 3) * 3; d < eLen; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
@ -335,41 +286,89 @@ public class Base64Util {
dArr[d++] = (byte) i;
// If line separator, jump over it.
if(sepCnt > 0 && ++cc == 19) {
if (sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if(d < len) {
if (d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for(int j = 0; sIx <= eIx - pad; j++)
for (int j = 0; sIx <= eIx - pad; j++)
i |= IA[sArr[sIx++]] << (18 - j * 6);
for(int r = 16; d < len; r -= 8)
for (int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
}
// ****************************************************************************************
// * String version
// ****************************************************************************************
/**
* Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045.
* Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as
* fast as {@link =#=decode(char[])}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
*
* @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned.
* @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br>
* No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
* little faster.
* @return A BASE64 encoded array. Never <code>null</code>.
* @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0.
*/
public final static String encodeToString(byte[] sArr, boolean lineSep) {
// Reuse char[] since we can't create a String incrementally anyway and StringBuffer/Builder would be slower.
return new String(encodeToChar(sArr, lineSep));
public final static byte[] decodeFast(char[] sArr) {
// Check special case
int sLen = sArr.length;
if (sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while (sIx < eIx && IA[sArr[sIx]] < 0)
sIx++;
// Trim illegal chars from end
while (eIx > 0 && IA[sArr[eIx]] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
int pad = sArr[eIx] == '=' ? (sArr[eIx - 1] == '=' ? 2 : 1) : 0; // Count '=' at end.
int cCnt = eIx - sIx + 1; // Content count including possible separators
int sepCnt = sLen > 76 ? (sArr[76] == '\r' ? cCnt / 78 : 0) << 1 : 0;
int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
// Decode all but the last 0 - 2 bytes.
int d = 0;
for (int cc = 0, eLen = (len / 3) * 3; d < eLen; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
// Add the bytes
dArr[d++] = (byte) (i >> 16);
dArr[d++] = (byte) (i >> 8);
dArr[d++] = (byte) i;
// If line separator, jump over it.
if (sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if (d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for (int j = 0; sIx <= eIx - pad; j++)
i |= IA[sArr[sIx++]] << (18 - j * 6);
for (int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
}
/**
@ -385,45 +384,45 @@ public class Base64Util {
public final static byte[] decode(String str) {
// Check special case
int sLen = str != null ? str.length() : 0;
if(sLen == 0)
if (sLen == 0)
return new byte[0];
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for(int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if(IA[str.charAt(i)] < 0)
for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if (IA[str.charAt(i)] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if((sLen - sepCnt) % 4 != 0)
if ((sLen - sepCnt) % 4 != 0)
return null;
// Count '=' at end
int pad = 0;
for(int i = sLen; i > 1 && IA[str.charAt(--i)] <= 0; )
if(str.charAt(i) == '=')
for (int i = sLen; i > 1 && IA[str.charAt(--i)] <= 0; )
if (str.charAt(i) == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for(int s = 0, d = 0; d < len; ) {
for (int s = 0, d = 0; d < len; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for(int j = 0; j < 4; j++) { // j only increased if a valid char was found.
for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[str.charAt(s++)];
if(c >= 0)
if (c >= 0)
i |= c << (18 - j * 6);
else
j--;
}
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if(d < len) {
if (d < len) {
dArr[d++] = (byte) (i >> 8);
if(d < len)
if (d < len)
dArr[d++] = (byte) i;
}
}
@ -432,44 +431,44 @@ public class Base64Util {
/**
* Decodes a BASE64 encoded string that is known to be resonably well formatted. The method is about twice as
* fast as {@link #decode(String)}. The preconditions are:<br>
* fast as {@link =#=decode(String)}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
*
* @param s The source string. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @param str The source string. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0.
*/
public final static byte[] decodeFast(String s) {
public final static byte[] decodeFast(String str) {
// Check special case
int sLen = s.length();
if(sLen == 0)
int sLen = str.length();
if (sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while(sIx < eIx && IA[s.charAt(sIx) & 0xff] < 0)
while (sIx < eIx && IA[str.charAt(sIx) & 0xff] < 0)
sIx++;
// Trim illegal chars from end
while(eIx > 0 && IA[s.charAt(eIx) & 0xff] < 0)
while (eIx > 0 && IA[str.charAt(eIx) & 0xff] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
int pad = s.charAt(eIx) == '=' ? (s.charAt(eIx - 1) == '=' ? 2 : 1) : 0; // Count '=' at end.
int pad = str.charAt(eIx) == '=' ? (str.charAt(eIx - 1) == '=' ? 2 : 1) : 0; // Count '=' at end.
int cCnt = eIx - sIx + 1; // Content count including possible separators
int sepCnt = sLen > 76 ? (s.charAt(76) == '\r' ? cCnt / 78 : 0) << 1 : 0;
int sepCnt = sLen > 76 ? (str.charAt(76) == '\r' ? cCnt / 78 : 0) << 1 : 0;
int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
// Decode all but the last 0 - 2 bytes.
int d = 0;
for(int cc = 0, eLen = (len / 3) * 3; d < eLen; ) {
for (int cc = 0, eLen = (len / 3) * 3; d < eLen; ) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[s.charAt(sIx++)] << 18 | IA[s.charAt(sIx++)] << 12 | IA[s.charAt(sIx++)] << 6 | IA[s.charAt(sIx++)];
int i = IA[str.charAt(sIx++)] << 18 | IA[str.charAt(sIx++)] << 12 | IA[str.charAt(sIx++)] << 6 | IA[str.charAt(sIx++)];
// Add the bytes
dArr[d++] = (byte) (i >> 16);
@ -477,31 +476,22 @@ public class Base64Util {
dArr[d++] = (byte) i;
// If line separator, jump over it.
if(sepCnt > 0 && ++cc == 19) {
if (sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if(d < len) {
if (d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for(int j = 0; sIx <= eIx - pad; j++)
i |= IA[s.charAt(sIx++)] << (18 - j * 6);
for (int j = 0; sIx <= eIx - pad; j++)
i |= IA[str.charAt(sIx++)] << (18 - j * 6);
for(int r = 16; d < len; r -= 8)
for (int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
}
public static void main(String[] args) {
String s = Base64Util.encodeToString("我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1".getBytes(), false);
System.out.println(s);
byte[] decode = Base64Util.decode(s);
System.out.println(new String(decode));
}
}

@ -0,0 +1,50 @@
package xyz.wbsite.dbtool.web.frame.utils;
import xyz.wbsite.dbtool.web.frame.auth.LocalData;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
/**
* CookieUtil
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class CookieUtil {
/**
* Cookies
*
* @param cookies Cookies
* @return passportID
*/
public static String getCookieValue(Cookie[] cookies, String key) {
if (cookies != null) {
for (Cookie cookie : cookies) {
// Cookie中存放的为passport的id Cookie名称通过ConfigToolObject获取
if (cookie != null && cookie.getName().equals(key)) {
try {
return cookie.getValue();
} catch (Exception ignored) {
}
}
}
}
return null;
}
/**
* Cookie
*
* @param cookies Cookies
* @return passportID
*/
public static Cookie newCookie(String key, String value) {
HttpServletRequest request = LocalData.getRequest();
Cookie cookie = new Cookie(key, value);
cookie.setDomain(request.getServerName());
cookie.setPath(request.getContextPath());
return cookie;
}
}

@ -0,0 +1,110 @@
package xyz.wbsite.dbtool.web.frame.utils;
import java.io.*;
public class FileUtil {
public static byte[] readFileToByteArray(File file) throws IOException {
InputStream in = openInputStream(file);
Throwable var2 = null;
byte[] var5;
try {
long fileLength = file.length();
var5 = fileLength > 0L ? toByteArray(in, fileLength) : toByteArray(in);
} catch (Throwable var14) {
var2 = var14;
throw var14;
} finally {
if (in != null) {
if (var2 != null) {
try {
in.close();
} catch (Throwable var13) {
var2.addSuppressed(var13);
}
} else {
in.close();
}
}
}
return var5;
}
public static FileInputStream openInputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
} else if (!file.canRead()) {
throw new IOException("File '" + file + "' cannot be read");
} else {
return new FileInputStream(file);
}
} else {
throw new FileNotFoundException("File '" + file + "' does not exist");
}
}
public static byte[] toByteArray(InputStream input, long size) throws IOException {
if (size > 2147483647L) {
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);
} else {
return toByteArray(input, (int) size);
}
}
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Throwable var2 = null;
byte[] var3;
try {
copy((InputStream) input, (OutputStream) output);
var3 = output.toByteArray();
} catch (Throwable var12) {
var2 = var12;
throw var12;
} finally {
if (output != null) {
if (var2 != null) {
try {
output.close();
} catch (Throwable var11) {
var2.addSuppressed(var11);
}
} else {
output.close();
}
}
}
return var3;
}
public static int copy(InputStream input, OutputStream output) throws IOException {
long count = copyLarge(input, output);
return count > 2147483647L ? -1 : (int) count;
}
public static long copyLarge(InputStream input, OutputStream output) throws IOException {
return copy(input, output, 4096);
}
public static long copy(InputStream input, OutputStream output, int bufferSize) throws IOException {
return copyLarge(input, output, new byte[bufferSize]);
}
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {
long count;
int n;
for (count = 0L; -1 != (n = input.read(buffer)); count += (long) n) {
output.write(buffer, 0, n);
}
return count;
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework;
package xyz.wbsite.dbtool.web.frame.utils;
import java.io.BufferedReader;
import java.io.IOException;
@ -70,25 +70,4 @@ public class IDgenerator {
protected static long timeGen() {
return System.currentTimeMillis();
}
public static void main(String[] args) {
Process p;
try {
p = Runtime.getRuntime().exec("E:\\windows_amd64\\sunny.exe clientid 213609147996,201822147996");
System.out.println(":::::::::::::::::::开始在控制台打印日志::::::::::::::::::::::>>>>>>");
//p.waitFor();
BufferedReader bReader=new BufferedReader(new InputStreamReader(p.getInputStream(),"gbk"));
String line=null;
while((line=bReader.readLine())!=null)
System.out.println(line);
} catch (IOException e) {
e.printStackTrace();
}
//
// for (int i = 0; i < 10; i++) {
// long l = IDgenerator.nextId();
// System.out.println(l);
// }
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.utils;
package xyz.wbsite.dbtool.web.frame.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ -0,0 +1,58 @@
package xyz.wbsite.dbtool.web.frame.utils;
import com.fasterxml.jackson.core.TreeNode;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
/**
* MD5Util - MD5
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class MD5Util {
/**
*
*
* @param value
* @return
*/
public static String encode(String value) {
try {
MessageDigest md = MessageDigest.getInstance("md5");
byte[] e = md.digest(value.getBytes());
return toHexString(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return value;
}
}
public static String encode(byte[] bytes) {
try {
MessageDigest md = MessageDigest.getInstance("md5");
byte[] e = md.digest(bytes);
return toHexString(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
private static String toHexString(byte bytes[]) {
StringBuilder hs = new StringBuilder();
String stmp = "";
for (int n = 0; n < bytes.length; n++) {
stmp = Integer.toHexString(bytes[n] & 0xff);
if (stmp.length() == 1)
hs.append("0").append(stmp);
else
hs.append(stmp);
}
return hs.toString();
}
}

@ -1,18 +1,15 @@
package xyz.wbsite.dbtool.web.framework.utils;
package xyz.wbsite.dbtool.web.frame.utils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.core.Converter;
import com.fasterxml.jackson.databind.*;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* MapUtil -
@ -23,6 +20,7 @@ import java.io.IOException;
*/
public class MapperUtil {
private static ObjectMapper om;
private static Mapper mapper;
static {
//初始化
@ -31,6 +29,12 @@ public class MapperUtil {
om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//序列化时排序
om.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
//反序列化是忽略多余字段
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//支持空类序列化时出错InvalidDefinitionException
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
mapper = new DozerBeanMapper();
}
public static TreeNode toTree(String json) {
@ -83,7 +87,16 @@ public class MapperUtil {
return null;
}
public static <T> T toJava(String json, TypeReference valueTypeRef) {
public static <T> T toJava(TreeNode treeNode, Class<T> cls) {
try {
return om.treeToValue(treeNode, cls);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
public static <T> T toJava(String json, TypeReference<T> valueTypeRef) {
try {
return om.readValue(json, valueTypeRef);
} catch (IOException e) {
@ -92,26 +105,29 @@ public class MapperUtil {
return null;
}
public static <T> T map(Object object, Class<T> tClass) {
public static <T> List<T> toJavaList(String json, TypeReference<List<T>> reference) {
try {
T t = tClass.newInstance();
map(object, t);
return t;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
return om.readValue(json, reference);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void map(Object object, Object target) {
map(object, target, null);
public static <T> List<T> toJavaList(InputStream json, TypeReference<List<T>> reference) {
try {
return om.readValue(json, reference);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void map(Object object, Object target, Converter converter) {
BeanCopier copier = BeanCopier.create(object.getClass(), target.getClass(), converter != null);
copier.copy(object, target, converter);
public static <T> T map(Object o, Class<T> aClass) {
return mapper.map(o, aClass);
}
public static void map(Object o, Object o1) {
mapper.map(o, o1);
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework;
package xyz.wbsite.dbtool.web.frame.utils;
/**

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.utils;
package xyz.wbsite.dbtool.web.frame.utils;
import java.awt.*;
import java.io.BufferedReader;
@ -9,7 +9,7 @@ import java.io.InputStreamReader;
/**
*
*
* @author
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@ -114,22 +114,4 @@ public class ProcessUtil {
}
}
}
public static void main(String[] args) {
// try {//调用bat文件出现黑窗口
// executeCmd("cmd /k start E:\\windows_amd64\\sunny.bat");
// } catch (IOException e) {
// e.printStackTrace();
// }
// try {
// executeCmd("E:\\windows_amd64\\sunny.exe clientid 213609147996,201822147996");
// } catch (IOException e) {
// e.printStackTrace();
// }
// execExe("D:\\windows_amd64\\sunny.exe clientid 213609147996,201822147996");
// execBat("D:\\windows_amd64\\exec.bat");
// System.out.println("===================");
// System.out.println(s);
// System.out.println("===================");
}
}

@ -0,0 +1,308 @@
package xyz.wbsite.dbtool.web.frame.utils;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
/**
* RSAUtil - RSA
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class RSAUtil {
private static String cryptPublicKeyBase64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTrwfsrJjCF+pP4S3A/wrD4U1txg53EuBC1mPt" +
"3vGXvSK2U0YNRVR3Q65ooHnPKmk4LwI8v+7+ATTxUg3qkuRiDuzBa5zLkYKM50LOgEWSdOKzbnbx" +
"a5FnE7IXawNt1p8+MVN1TTI7J/fZy6g1x0WBy1odE5Osru4WfZNOqQtjHwIDAQAB";
private static String cryptPrivateKeyBase64 = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJOvB+ysmMIX6k/hLcD/CsPhTW3G" +
"DncS4ELWY+3e8Ze9IrZTRg1FVHdDrmigec8qaTgvAjy/7v4BNPFSDeqS5GIO7MFrnMuRgoznQs6A" +
"RZJ04rNudvFrkWcTshdrA23Wnz4xU3VNMjsn99nLqDXHRYHLWh0Tk6yu7hZ9k06pC2MfAgMBAAEC" +
"gYBjLRjKRMI1HfBZgmPChsPI9YWU4XuXVVLLL8Rd2uktOHOWM2gIw3VMvmPimVoT2GxesZr0BwTN" +
"CSxvnuX/kHPTqtsIu1r5Iup3mGbvlj3sn8RvG0yvUDglDN7QVDqqN7XWvHJSBVfBzDXeExA/WGnE" +
"6BOocNT9qkqA/UWNbCXGKQJBAN0Fd/P2D6EvCd2RztHhzVE6V8s/LwOTDnGn/YhdMpddy9TwZpBi" +
"r7I6lzcLWQ1HfDUive3t+DGXqPqr/4FfkG0CQQCrDlZKf216QrXOmJ70LQSbflgvGYU+b6kLFyEh" +
"+15HcIBfKUQCU+XUK4UzLMQDYxdngTNMNyq4AQ9Sh0tUTUI7AkEAtkq9XayzxWhLhcCtyTOoqPcq" +
"1Aqf1x3iCuHYXTEo+ek1pcJFhY6vhJuIfrDQWQB9tEGcTvI4A4cnquBTkzvjnQJAYid58ImqYmuB" +
"M6l0HJzwdeFL7MryIF+mWozNIFjDQq8VmoVtVwCZcuP+LN1VJLRpq6UBsIw/YRKKnkqwORGUHQJA" +
"UuR0G/3Hai+vKDA14tIYIH6C4zNmbULxAEuQVh9thfafWNmiDcifApvkxQ2ewXwEGeJtz44zv6iY" +
"3f3yq+a2OQ==";
private static String signPublicKeyBase64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTrwfsrJjCF+pP4S3A/wrD4U1txg53EuBC1mPt" +
"3vGXvSK2U0YNRVR3Q65ooHnPKmk4LwI8v+7+ATTxUg3qkuRiDuzBa5zLkYKM50LOgEWSdOKzbnbx" +
"a5FnE7IXawNt1p8+MVN1TTI7J/fZy6g1x0WBy1odE5Osru4WfZNOqQtjHwIDAQAB";
private static String signPrivateKeyBase64 = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJOvB+ysmMIX6k/hLcD/CsPhTW3G" +
"DncS4ELWY+3e8Ze9IrZTRg1FVHdDrmigec8qaTgvAjy/7v4BNPFSDeqS5GIO7MFrnMuRgoznQs6A" +
"RZJ04rNudvFrkWcTshdrA23Wnz4xU3VNMjsn99nLqDXHRYHLWh0Tk6yu7hZ9k06pC2MfAgMBAAEC" +
"gYBjLRjKRMI1HfBZgmPChsPI9YWU4XuXVVLLL8Rd2uktOHOWM2gIw3VMvmPimVoT2GxesZr0BwTN" +
"CSxvnuX/kHPTqtsIu1r5Iup3mGbvlj3sn8RvG0yvUDglDN7QVDqqN7XWvHJSBVfBzDXeExA/WGnE" +
"6BOocNT9qkqA/UWNbCXGKQJBAN0Fd/P2D6EvCd2RztHhzVE6V8s/LwOTDnGn/YhdMpddy9TwZpBi" +
"r7I6lzcLWQ1HfDUive3t+DGXqPqr/4FfkG0CQQCrDlZKf216QrXOmJ70LQSbflgvGYU+b6kLFyEh" +
"+15HcIBfKUQCU+XUK4UzLMQDYxdngTNMNyq4AQ9Sh0tUTUI7AkEAtkq9XayzxWhLhcCtyTOoqPcq" +
"1Aqf1x3iCuHYXTEo+ek1pcJFhY6vhJuIfrDQWQB9tEGcTvI4A4cnquBTkzvjnQJAYid58ImqYmuB" +
"M6l0HJzwdeFL7MryIF+mWozNIFjDQq8VmoVtVwCZcuP+LN1VJLRpq6UBsIw/YRKKnkqwORGUHQJA" +
"UuR0G/3Hai+vKDA14tIYIH6C4zNmbULxAEuQVh9thfafWNmiDcifApvkxQ2ewXwEGeJtz44zv6iY" +
"3f3yq+a2OQ==";
/**
*
*/
public static void createKey() {
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
//公钥
RSAPublicKey aPublic = (RSAPublicKey) keyPair.getPublic();
//私钥
RSAPrivateKey aPrivate = (RSAPrivateKey) keyPair.getPrivate();
//把密钥对象对应的字节转为Base64字符存储
System.err.println("publicKeyBase64-->" + Base64Util.encodeToString(aPublic.getEncoded()));
System.err.println("privateKeyBase64-->" + Base64Util.encodeToString(aPrivate.getEncoded()));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
public static String encrypt2Base64(byte[] data) {
byte[] encrypt = encrypt(data);
return Base64Util.encodeToString(encrypt);
}
public static byte[] encrypt(String data) {
return encrypt(data.getBytes());
}
/**
*
*
* @param data
*/
public static byte[] encrypt(byte[] data) {
try {
//生成公钥对象
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(Base64Util.decode(cryptPublicKeyBase64));
PublicKey aPublic = keyFactory.generatePublic(x509EncodedKeySpec);
//分段加密开始
ByteArrayOutputStream bs = new ByteArrayOutputStream();
Cipher rsa = Cipher.getInstance("RSA");
rsa.init(Cipher.ENCRYPT_MODE, aPublic);
int offset = 0;
while (offset < data.length) {
byte[] bytes = rsa.doFinal(Arrays.copyOfRange(data, offset, Math.min(offset + 117, data.length)));
bs.write(bytes);
offset += 117;
}
return bs.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param data
*/
public static byte[] encrypt(String data, PublicKey aPublic) {
try {
if (aPublic == null) {
System.err.println("PublicKey can not be null");
return null;
}
//分段加密开始
ByteArrayOutputStream bs = new ByteArrayOutputStream();
Cipher rsa = Cipher.getInstance("RSA");
rsa.init(Cipher.ENCRYPT_MODE, aPublic);
int offset = 0;
byte[] b = data.getBytes();
while (offset < b.length) {
byte[] bytes = rsa.doFinal(Arrays.copyOfRange(b, offset, Math.min(offset + 117, b.length)));
bs.write(bytes);
offset += 117;
}
return bs.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* @param base64String base64
* @return
*/
public static byte[] decrypt(String base64String) {
return decrypt(Base64Util.decode(base64String));
}
public static String decrypt2String(String base64String) {
byte[] decrypt = decrypt(Base64Util.decode(base64String));
try {
return new String(decrypt, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param data
*/
public static byte[] decrypt(byte[] data) {
try {
//生成私钥对象
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(Base64Util.decode(cryptPrivateKeyBase64));
PrivateKey aPrivate = keyFactory.generatePrivate(pkcs8EncodedKeySpec);
Cipher rsa = Cipher.getInstance("RSA");
rsa.init(Cipher.DECRYPT_MODE, aPrivate);
//获得密文字节
ByteArrayOutputStream bs = new ByteArrayOutputStream();
int offset = 0;
while (offset < data.length) {
byte[] bytes = rsa.doFinal(Arrays.copyOfRange(data, offset, Math.min(offset + 128, data.length)));
bs.write(bytes);
offset += 128;
}
return bs.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param data
* @param aPrivate
* @return
*/
public static byte[] decrypt(byte[] data, PublicKey aPrivate) {
try {
if (aPrivate == null) {
System.err.println("PublicKey can not be null");
return null;
}
Cipher rsa = Cipher.getInstance("RSA");
rsa.init(Cipher.DECRYPT_MODE, aPrivate);
//获得密文字节
ByteArrayOutputStream bs = new ByteArrayOutputStream();
int offset = 0;
while (offset < data.length) {
byte[] bytes = rsa.doFinal(Arrays.copyOfRange(data, offset, Math.min(offset + 128, data.length)));
bs.write(bytes);
offset += 128;
}
return bs.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String sign2Base64(byte[] data) {
return sign2Base64(data, signPrivateKeyBase64);
}
public static String sign2Base64(byte[] data, String privateKey) {
byte[] sign = sign(data, privateKey);
return Base64Util.encodeToString(sign);
}
/**
* RSA
*
* @param data
* @param privateKey
* @return
*/
public static byte[] sign(byte[] data, String privateKey) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64Util.decode(privateKey));
PrivateKey aPrivate = keyFactory.generatePrivate(priPKCS8);
Signature signature = Signature.getInstance("SHA1WithRSA");
signature.initSign(aPrivate);
signature.update(data);
return signature.sign();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* RSA
*
* @param data
* @param sign base64
* @param publicKey
* @return
*/
public static boolean doCheck(byte[] data, String sign, String publicKey) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
byte[] encodedKey = Base64Util.decode(publicKey);
PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
Signature signature = Signature.getInstance("SHA1WithRSA");
signature.initVerify(pubKey);
signature.update(data);
return signature.verify(Base64Util.decode(sign));
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean doCheck(byte[] data, String sign) {
return doCheck(data, sign, signPublicKeyBase64);
}
public static PublicKey parsePublicKey(String cryptPublicKeyBase64) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(Base64Util.decode(cryptPublicKeyBase64));
return keyFactory.generatePublic(x509EncodedKeySpec);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return null;
}
public static PrivateKey parsePrivateKey(String cryptPrivateKeyBase64) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64Util.decode(cryptPrivateKeyBase64));
return keyFactory.generatePrivate(priPKCS8);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return null;
}
}

@ -1,34 +1,41 @@
package xyz.wbsite.dbtool.web.framework.freemarker;
package xyz.wbsite.dbtool.web.frame.utils;
import freemarker.template.TemplateModelException;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Locale;
/**
* Url
* Url
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Component
public class Url {
public class UrlUtil {
public String setUrl(String url) throws TemplateModelException {
public String getUrl(String url) {
if (url == null) {
return "";
}
if (!url.startsWith("/")) {
return "/" + url;
}
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// 协议
String scheme = request.getScheme();
// 域名
String serverName = request.getServerName();
// 端口
int serverPort = request.getServerPort();
// 上下文路径
String contextPath = request.getContextPath();
if (url.startsWith("/")) {
return contextPath + url;
} else {
return contextPath + "/" + url;
}
return String.format(Locale.CHINA, "%s://%s:%d%s%s", scheme, serverName, serverPort, contextPath, url);
}
}

@ -0,0 +1,54 @@
package xyz.wbsite.dbtool.web.frame.utils;
import xyz.wbsite.dbtool.web.frame.base.BaseRequest;
import xyz.wbsite.dbtool.web.frame.base.BaseResponse;
import xyz.wbsite.dbtool.web.frame.base.ErrorType;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class ValidationUtil {
private static ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
public static <T extends BaseResponse> T validate(BaseRequest req, T response) {
if (req == null) {
response.addError(ErrorType.EXPECTATION_NULL, "请求对象不能为空");
return response;
}
try {
Validator validator = factory.getValidator();
Set<ConstraintViolation<BaseRequest>> constraintViolations = validator.validate(req);
if (constraintViolations.size() > 0) {
for (ConstraintViolation<BaseRequest> violation : constraintViolations) {
response.addError(ErrorType.INVALID_PARAMETER, violation.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.dumpException(e);
response.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return response;
}
}

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.utils;
package xyz.wbsite.dbtool.web.frame.utils;
import javax.net.ssl.*;
import java.io.*;

@ -1,4 +1,4 @@
package xyz.wbsite.dbtool.web.framework.utils;
package xyz.wbsite.dbtool.web.frame.utils;
import java.io.*;
import java.util.Enumeration;

@ -0,0 +1,18 @@
package xyz.wbsite.dbtool.web.frame.validation;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = DictValidator.class)
public @interface Dict {
String message() default "字典项错误";
String name() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}

@ -0,0 +1,36 @@
package xyz.wbsite.dbtool.web.frame.validation;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
public class DictValidator implements ConstraintValidator<Dict, String> {
private String name;
@Override
public void initialize(Dict constraint) {
name = constraint.name();
}
@Override
public boolean isValid(String o, ConstraintValidatorContext constraintValidatorContext) {
if (null == o) {
return true;
} else if (name == null) {
constraintValidatorContext.disableDefaultConstraintViolation();
constraintValidatorContext.buildConstraintViolationWithTemplate("字典名称为空").addConstraintViolation();
return false;
} else {
// name 字典名称
HashSet<String> codeSet = new HashSet<>();
if (codeSet.contains(o)) {
return true;
} else {
constraintValidatorContext.disableDefaultConstraintViolation();
constraintValidatorContext.buildConstraintViolationWithTemplate("非法的字典[" + name + "]值").addConstraintViolation();
return false;
}
}
}
}

@ -1,48 +0,0 @@
package xyz.wbsite.dbtool.web.framework;
import xyz.wbsite.dbtool.web.framework.base.Token;
import java.io.Serializable;
/**
* LocalData -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class LocalData implements Serializable{
private static final long serialVersionUID = 1L;
private static Token temp = null;
static {
temp = new Token();
temp.setId(-1);
temp.setUserId(-1);
temp.setUserName("游客");
temp.putResource("/");
temp.putResource("/index");
temp.putResource("/login");
temp.putResource("/ajax");
temp.putResource("ajax.example.example");
}
public static Token getTempToken(){
return temp;
}
/**
*
*/
private static final ThreadLocal<Token> tokenHolder = new ThreadLocal();
public static Token getToken() {
return tokenHolder.get();
}
public static void setToken(Token token) {
tokenHolder.set(token);
}
}

@ -1,75 +0,0 @@
package xyz.wbsite.dbtool.web.framework.base;
/**
* BaseFindRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseFindRequest extends BaseRequest {
private long pageNumber = 1L;
private long pageSize = 10L;
private long beginIndex = 0;
private long endIndex = 10;
private String sortKey;
private SortType sortType;
public String getSortKey() {
return sortKey;
}
public void setSortKey(String sortKey) {
this.sortKey = sortKey;
}
public SortType getSortType() {
return sortType;
}
public void setSortType(SortType sortType) {
this.sortType = sortType;
}
public long getPageNumber() {
return pageNumber;
}
public void setPageNumber(long pageNumber) {
this.pageNumber = pageNumber;
}
public long getPageSize() {
return pageSize;
}
public void setPageSize(long pageSize) {
this.pageSize = pageSize;
}
public long getBeginIndex() {
beginIndex = pageSize * (pageNumber - 1);
return beginIndex;
}
public void setBeginIndex(long beginIndex) {
this.beginIndex = beginIndex;
}
public long getEndIndex() {
endIndex = pageSize * (pageNumber - 1) + pageSize;
return endIndex;
}
public void setEndIndex(long endIndex) {
this.endIndex = endIndex;
}
public void updatePageNumber(Long totalCount){
long maxPage = totalCount / pageSize + (totalCount % pageSize > 0 ? 1 : 0);
if (pageNumber > maxPage){
pageNumber = maxPage;
}
}
}

@ -1,38 +0,0 @@
package xyz.wbsite.dbtool.web.framework.base;
import java.util.ArrayList;
import java.util.List;
/**
* BaseResponse -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseResponse {
private List<Error> errors = new ArrayList();
public void addError(Error error){
this.errors.add(error);
}
public void addError(ErrorType type,String message){
this.errors.add(new Error(type,message));
}
public void addErrors(List<Error> errors){
this.errors.addAll(errors);
}
public boolean hasError(){
return this.errors.size() > 0;
}
/**
*
*/
public List<Error> getErrors() {
return new ArrayList<Error>(errors);
}
}

@ -1,57 +0,0 @@
package xyz.wbsite.dbtool.web.framework.config;
import xyz.wbsite.dbtool.web.framework.freemarker.FreemarkerViewNameTranslator;
import xyz.wbsite.dbtool.web.framework.freemarker.Layout;
import xyz.wbsite.dbtool.web.framework.freemarker.Url;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import javax.annotation.PostConstruct;
import java.util.Map;
/**
* FreemarkerViewName
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Configuration
public class FreeMarkerConfig {
@Autowired
private Layout layout;
@Autowired
private Url url;
@Autowired
protected FreeMarkerViewResolver resolver;
@Autowired
protected FreeMarkerConfigurer freeMarkerConfigurer;
@PostConstruct
public void setSharedVariable() {
//设置基本工具类
Map<String, Object> attributesMap = resolver.getAttributesMap();
attributesMap.put("Layout", layout);
attributesMap.put("Url", url);
}
/**
*
*
* @return
*/
@Bean(name = "viewNameTranslator")
public DefaultRequestToViewNameTranslator getViewNameTranslator() {
FreemarkerViewNameTranslator nameTranslator = new FreemarkerViewNameTranslator();
nameTranslator.setViewResolver(resolver);
return nameTranslator;
}
}

@ -1,44 +0,0 @@
package xyz.wbsite.dbtool.web.framework.config;
import xyz.wbsite.dbtool.web.framework.interceptor.GlobalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.*;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private CharacterEncodingFilter characterEncodingFilter;
@Override
public void addInterceptors(InterceptorRegistry registry) {
//增加全局拦截器
registry.addInterceptor(new GlobalInterceptor()).addPathPatterns("/*");
}
@Bean
public FilterRegistrationBean characterEncodingFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
//注入过滤器
registration.setFilter(characterEncodingFilter);
//拦截规则
registration.addUrlPatterns("/*");
//过滤器名称
registration.setName("CharacterEncodingFilter");
//过滤器顺序
registration.setOrder(1);
return registration;
}
@Bean
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
return characterEncodingFilter;
}
}

@ -1,75 +0,0 @@
package xyz.wbsite.dbtool.web.framework.freemarker;
import xyz.wbsite.dbtool.web.framework.utils.LogUtil;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Locale;
/**
* FreemarkerViewName
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class FreemarkerViewNameTranslator extends DefaultRequestToViewNameTranslator {
private FreeMarkerViewResolver viewResolver;
@Override
public String getViewName(HttpServletRequest request) {
String viewName = "";
try {
LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE);
String servletPath = request.getServletPath();
if (servletPath != null && "/".equals(servletPath)) {
servletPath = "index";
}else {
servletPath = servletPath.replaceAll("^/","");
}
Locale locale = localeResolver.resolveLocale(request);
{//查询View
viewName = "screen" + File.separator + servletPath;
View view = viewResolver.resolveViewName(viewName, locale);
if (view == null) {
LogUtil.e("can not find screen.");
return "404";
}
}
{//查找layout
viewName = "layout" + File.separator + servletPath;
View view = viewResolver.resolveViewName(viewName, locale);
//无法找到对应layout使用默认layout
if (view == null) {
viewName = "layout" + File.separator + "default";
View defaultView = viewResolver.resolveViewName(viewName, locale);
if (defaultView == null) {
System.err.println("can not find layout/default.ftl");
viewName = "";
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return viewName;
}
public FreeMarkerViewResolver getViewResolver() {
return viewResolver;
}
public void setViewResolver(FreeMarkerViewResolver viewResolver) {
this.viewResolver = viewResolver;
}
}

@ -1,66 +0,0 @@
package xyz.wbsite.dbtool.web.framework.freemarker;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Locale;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Component
public class Layout {
@Value("${web.welcome.page}")
private String homePage;
@Autowired
private FreeMarkerViewResolver viewResolver;
private String screenPrefix = "/screen/";
private String controlPrefix = "/control/";
private String suffix = ".ftl";
public String setScreen() throws TemplateModelException {
try {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE);
String servletPath = request.getServletPath();
if ("/".equals(servletPath)) {
servletPath = this.homePage;
}
servletPath = servletPath.replaceAll("^/", "");
Locale locale = localeResolver.resolveLocale(request);
String viewName = "screen" + File.separator + servletPath;
View view = viewResolver.resolveViewName(viewName, locale);
//无法找到对应screen
if (view == null) {
return "";
} else {
return screenPrefix + servletPath + suffix;
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public String setControl(String control) {
return controlPrefix + control + suffix;
}
}

@ -1,31 +0,0 @@
package xyz.wbsite.dbtool.web.framework.interceptor;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GlobalInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// todo do something
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
}
}

@ -1,54 +0,0 @@
package xyz.wbsite.dbtool.web.framework.springmvc;
import xyz.wbsite.dbtool.web.framework.LocalData;
import xyz.wbsite.dbtool.web.framework.base.Token;
import xyz.wbsite.dbtool.web.framework.utils.LogUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* SpringMVC
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class GlobalHandlerInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return super.preHandle(request, response, handler);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
super.postHandle(request, response, handler, modelAndView);
//当请求为@ResponseBodymodelAndView为null
if (modelAndView == null){
return;
}
//获取当前用户信息
Token token = LocalData.getToken();
modelAndView.addObject("token", token);
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
super.afterCompletion(request, response, handler, ex);
LogUtil.i("请求地址" + request.getServletPath());
if (ex != null) {
LogUtil.dumpException(ex);
}
}
@Override
public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
super.afterConcurrentHandlingStarted(request, response, handler);
}
}

@ -1,27 +0,0 @@
package xyz.wbsite.dbtool.web.framework.springmvc;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
/**
* SpringMVC JSON
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class GlobalObjectMapper extends ObjectMapper {
/**
* @ResponseBody JSON
*/
public GlobalObjectMapper() {
super();
// 将所有的Long变成String以兼容js
SimpleModule simpleModule = new SimpleModule("LongModule");
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
registerModule(simpleModule);
}
}

@ -1,60 +0,0 @@
package xyz.wbsite.dbtool.web.framework.utils;
import javax.servlet.http.Cookie;
/**
* Created on 2017-04-25
*
* @author
*/
public class CookieUtil {
public static String getTokenCookieName(String deployMode){
if (deployMode.equals("production")) {
return "TOKEN_ID";
} else {
return "TOKEN_ID_" + deployMode.toUpperCase();
}
}
/**
* CookiespassportID
* @param cookies Cookies
* @return passportID
*/
public static Long getTokenId(Cookie[] cookies, String deployMode) {
if(cookies != null) {
for (Cookie cookie : cookies) {
// Cookie中存放的为Token的id Cookie名称通过ConfigToolObject获取
if (cookie != null && cookie.getName().equals(getTokenCookieName(deployMode))) {
try {
// 将cookie中的passportId转换为Long型
return Long.parseLong(cookie.getValue());
} catch (Exception ignored) {
}
}
}
}
return null;
}
/**
* Cookies
* @param cookies Cookies
* @return passportID
*/
public static String getCookieValue(Cookie[] cookies, String key) {
if(cookies != null) {
for (Cookie cookie : cookies) {
// Cookie中存放的为passport的id Cookie名称通过ConfigToolObject获取
if (cookie != null && cookie.getName().equals(key)) {
try {
return cookie.getValue();
} catch (Exception ignored) {
}
}
}
}
return null;
}
}

@ -1,897 +0,0 @@
package xyz.wbsite.dbtool.web.framework.utils;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class FileUtil {
/**
*
*/
private FileUtil() {
}
/**
* 访
*
* <b></b>
*
* @param file 访
* @since 1.0
*/
public static void touch(File file) {
long currentTime = System.currentTimeMillis();
if (!file.exists()) {
System.err.println("file not found:" + file.getName());
System.err.println("Create a new file:" + file.getName());
try {
if (file.createNewFile()) {
System.out.println("Succeeded!");
} else {
System.err.println("Create file failed!");
}
} catch (IOException e) {
System.err.println("Create file failed!");
e.printStackTrace();
}
}
boolean result = file.setLastModified(currentTime);
if (!result) {
System.err.println("touch failed: " + file.getName());
}
}
/**
* 访
*
* <b></b>
*
* @param fileName 访
* @since 1.0
*/
public static void touch(String fileName) {
File file = new File(fileName);
touch(file);
}
/**
* 访
*
* <b></b>
*
* @param files 访
* @since 1.0
*/
public static void touch(File[] files) {
for (int i = 0; i < files.length; i++) {
touch(files[i]);
}
}
/**
* 访
*
* <b></b>
*
* @param fileNames 访
* @since 1.0
*/
public static void touch(String[] fileNames) {
File[] files = new File[fileNames.length];
for (int i = 0; i < fileNames.length; i++) {
files[i] = new File(fileNames[i]);
}
touch(files);
}
/**
*
*
* @param fileName
* @return truefalse
* @since 1.0
*/
public static boolean isFileExist(String fileName) {
return new File(fileName).isFile();
}
/**
*
*
* <b>false</b>
*
* @param file
* @return truefalse
* @since 1.0
*/
public static boolean makeDirectory(File file) {
File parent = file.getParentFile();
if (parent != null) {
return parent.mkdirs();
}
return false;
}
/**
*
*
* <b>false</b>
*
* @param fileName
* @return truefalse
* @since 1.0
*/
public static boolean makeDirectory(String fileName) {
File file = new File(fileName);
return makeDirectory(file);
}
/**
*
* false
*
*
* @param directory
* @return truefalse.
* @since 1.0
*/
public static boolean emptyDirectory(File directory) {
boolean result = true;
File[] entries = directory.listFiles();
for (int i = 0; i < entries.length; i++) {
if (!entries[i].delete()) {
result = false;
}
}
return result;
}
/**
*
* false
*
*
* @param directoryName
* @return truefalse
* @since 1.0
*/
public static boolean emptyDirectory(String directoryName) {
File dir = new File(directoryName);
return emptyDirectory(dir);
}
/**
*
*
* @param dirName
* @return truefalse
* @since 1.0
*/
public static boolean deleteDirectory(String dirName) {
return deleteDirectory(new File(dirName));
}
/**
*
*
* @param dir
* @return truefalse
* @since 1.0
*/
public static boolean deleteDirectory(File dir) {
if ((dir == null) || !dir.isDirectory()) {
throw new IllegalArgumentException("Argument " + dir +
" is not a directory. ");
}
File[] entries = dir.listFiles();
int sz = entries.length;
for (int i = 0; i < sz; i++) {
if (entries[i].isDirectory()) {
if (!deleteDirectory(entries[i])) {
return false;
}
} else {
if (!entries[i].delete()) {
return false;
}
}
}
if (!dir.delete()) {
return false;
}
return true;
}
/**
*
*
* @param file
* @param filter
* @return
* @since 1.0
*/
public static File[] listAll(File file,
javax.swing.filechooser.FileFilter filter) {
ArrayList list = new ArrayList();
File[] files;
if (!file.exists() || file.isFile()) {
return null;
}
list(list, file, filter);
files = new File[list.size()];
list.toArray(files);
return files;
}
/**
*
*
* @param list
* @param filter
* @param file
*/
private static void list(ArrayList list, File file,
javax.swing.filechooser.FileFilter filter) {
if (filter.accept(file)) {
list.add(file);
if (file.isFile()) {
return;
}
}
if (file.isDirectory()) {
File files[] = file.listFiles();
for (int i = 0; i < files.length; i++) {
list(list, files[i], filter);
}
}
}
/**
* URL
*
* @param file
* @return URL
* @throws MalformedURLException
* @since 1.0
* @deprecated FiletoURLURL
* 使File.toURL
*/
public static URL getURL(File file) throws MalformedURLException {
String fileURL = "file:/" + file.getAbsolutePath();
URL url = new URL(fileURL);
return url;
}
/**
*
*
* @param filePath
* @return
* @since 1.0
*/
public static String getFileName(String filePath) {
File file = new File(filePath);
return file.getName();
}
/**
*
*
* @param fileName
* @return
* @since 1.0
*/
public static String getFilePath(String fileName) {
File file = new File(fileName);
return file.getAbsolutePath();
}
/**
* DOS/WindowsUNIX/Linux
* "\"全部换为"/"便
* "/""\"DOS/Windows
*
* @param filePath
* @return
* @since 1.0
*/
public static String toUNIXpath(String filePath) {
return filePath.replace('\\', '/');
}
/**
* UNIX
*
* @param fileName
* @return UNIX
* @see #toUNIXpath(String filePath) toUNIXpath
* @since 1.0
*/
public static String getUNIXfilePath(String fileName) {
File file = new File(fileName);
return toUNIXpath(file.getAbsolutePath());
}
/**
*
* .
*
* @param fileName
* @return
* @since 1.0
*/
public static String getTypePart(String fileName) {
int point = fileName.lastIndexOf('.');
int length = fileName.length();
if (point == -1 || point == length - 1) {
return "";
} else {
return fileName.substring(point + 1, length);
}
}
/**
*
* .
*
* @param file
* @return
* @since 1.0
*/
public static String getFileType(File file) {
return getTypePart(file.getName());
}
/**
*
*
*
* @param fileName
* @return
* @since 1.0
*/
public static String getNamePart(String fileName) {
int point = getPathLsatIndex(fileName);
int length = fileName.length();
if (point == -1) {
return fileName;
} else if (point == length - 1) {
int secondPoint = getPathLsatIndex(fileName, point - 1);
if (secondPoint == -1) {
if (length == 1) {
return fileName;
} else {
return fileName.substring(0, point);
}
} else {
return fileName.substring(secondPoint + 1, point);
}
} else {
return fileName.substring(point + 1);
}
}
/**
*
*
* ""
* "/path/"""
*
* @param fileName
* @return ""
* @since 1.0
*/
public static String getPathPart(String fileName) {
int point = getPathLsatIndex(fileName);
int length = fileName.length();
if (point == -1) {
return "";
} else if (point == length - 1) {
int secondPoint = getPathLsatIndex(fileName, point - 1);
if (secondPoint == -1) {
return "";
} else {
return fileName.substring(0, secondPoint);
}
} else {
return fileName.substring(0, point);
}
}
/**
*
* DOSUNIX
*
* @param fileName
* @return -1
* @since 1.0
*/
public static int getPathIndex(String fileName) {
int point = fileName.indexOf('/');
if (point == -1) {
point = fileName.indexOf('\\');
}
return point;
}
/**
*
* DOSUNIX
*
* @param fileName
* @param fromIndex
* @return -1
* @since 1.0
*/
public static int getPathIndex(String fileName, int fromIndex) {
int point = fileName.indexOf('/', fromIndex);
if (point == -1) {
point = fileName.indexOf('\\', fromIndex);
}
return point;
}
/**
*
* DOSUNIX
*
* @param fileName
* @return -1
* @since 1.0
*/
public static int getPathLsatIndex(String fileName) {
int point = fileName.lastIndexOf('/');
if (point == -1) {
point = fileName.lastIndexOf('\\');
}
return point;
}
/**
*
* DOSUNIX
*
* @param fileName
* @param fromIndex
* @return -1
* @since 1.0
*/
public static int getPathLsatIndex(String fileName, int fromIndex) {
int point = fileName.lastIndexOf('/', fromIndex);
if (point == -1) {
point = fileName.lastIndexOf('\\', fromIndex);
}
return point;
}
/**
*
*
* @param filename
* @return
* @since 1.0
*/
public static String trimType(String filename) {
int index = filename.lastIndexOf(".");
if (index != -1) {
return filename.substring(0, index);
} else {
return filename;
}
}
/**
*
*
*
* @param pathName
* @param fileName
* @return
* @since 1.0
*/
public static String getSubpath(String pathName, String fileName) {
int index = fileName.indexOf(pathName);
if (index != -1) {
return fileName.substring(index + pathName.length() + 1);
} else {
return fileName;
}
}
/**
*
*
*
* @param path
* @return
* @since 1.0
*/
public static final boolean pathValidate(String path) {
//String path="d:/web/www/sub";
//System.out.println(path);
//path = getUNIXfilePath(path);
//path = ereg_replace("^\\/+", "", path);
//path = ereg_replace("\\/+$", "", path);
String[] arraypath = path.split("/");
String tmppath = "";
for (int i = 0; i < arraypath.length; i++) {
tmppath += "/" + arraypath[i];
File d = new File(tmppath.substring(1));
if (!d.exists()) { //检查Sub目录是否存在
System.out.println(tmppath.substring(1));
if (!d.mkdir()) {
return false;
}
}
}
return true;
}
/**
*
*
*
* @param path
* @return
* @since 1.0
*/
public static final String getFileContent(String path) throws IOException {
String filecontent = "";
try {
File f = new File(path);
if (f.exists()) {
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr); //建立BufferedReader对象并实例化为br
String line = br.readLine(); //从文件读取一行字符串
//判断读取到的字符串是否不为空
while (line != null) {
filecontent += line + "\n";
line = br.readLine(); //从文件中继续读取一行数据
}
br.close(); //关闭BufferedReader对象
fr.close(); //关闭文件
}
} catch (IOException e) {
throw e;
}
return filecontent;
}
/**
*
*
* @param path
* @param modulecontent
* @return
* @since 1.0
*/
public static final boolean genModuleTpl(String path, String modulecontent) throws IOException {
path = getUNIXfilePath(path);
String[] patharray = path.split("\\/");
String modulepath = "";
for (int i = 0; i < patharray.length - 1; i++) {
modulepath += "/" + patharray[i];
}
File d = new File(modulepath.substring(1));
if (!d.exists()) {
if (!pathValidate(modulepath.substring(1))) {
return false;
}
}
try {
FileWriter fw = new FileWriter(path); //建立FileWriter对象并实例化fw
//将字符串写入文件
fw.write(modulecontent);
fw.close();
} catch (IOException e) {
throw e;
}
return true;
}
/**
*
*
* @param pic_path
* @return
* @since 1.0
*/
public static final String getPicExtendName(String pic_path) {
pic_path = getUNIXfilePath(pic_path);
String pic_extend = "";
if (isFileExist(pic_path + ".gif")) {
pic_extend = ".gif";
}
if (isFileExist(pic_path + ".jpeg")) {
pic_extend = ".jpeg";
}
if (isFileExist(pic_path + ".jpg")) {
pic_extend = ".jpg";
}
if (isFileExist(pic_path + ".png")) {
pic_extend = ".png";
}
return pic_extend; //返回图片扩展名
}
/**
*
*
* @param in
* @param out
* @return
* @throws Exception
*/
public static final boolean CopyFile(File in, File out) throws Exception {
try {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
return true;
} catch (IOException ie) {
ie.printStackTrace();
return false;
}
}
/**
*
*
* @param infile
* @param outfile
* @return
* @throws Exception
*/
public static final boolean CopyFile(String infile, String outfile) throws Exception {
try {
File in = new File(infile);
File out = new File(outfile);
return CopyFile(in, out);
} catch (IOException ie) {
ie.printStackTrace();
return false;
}
}
/**
* contentpath
*
* @param content
* @param path
* @return
*/
public static boolean SaveFileAs(String content, String path) {
FileWriter fw = null;
try {
fw = new FileWriter(new File(path), false);
if (content != null) {
fw.write(content);
}
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
if (fw != null) {
try {
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
/**
*
*/
public static byte[] readFileByBytes(String fileName) throws IOException {
FileInputStream in = new FileInputStream(fileName);
byte[] bytes = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
in.close();
bytes = out.toByteArray();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (in != null) {
in.close();
}
}
return bytes;
}
/**
*
*/
public static void readFileByChars(String fileName) {
File file = new File(fileName);
Reader reader = null;
try {
System.out.println("以字符为单位读取文件内容,一次读一个字节:");
// 一次读一个字符
reader = new InputStreamReader(new FileInputStream(file));
int tempchar;
while ((tempchar = reader.read()) != -1) {
// 对于windows下\r\n这两个字符在一起时表示一个换行。
// 但如果这两个字符分开显示时,会换两次行。
// 因此,屏蔽掉\r或者屏蔽\n。否则将会多出很多空行。
if (((char) tempchar) != '\r') {
System.out.print((char) tempchar);
}
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("以字符为单位读取文件内容,一次读多个字节:");
// 一次读多个字符
char[] tempchars = new char[30];
int charread = 0;
reader = new InputStreamReader(new FileInputStream(fileName));
// 读入多个字符到字符数组中charread为一次读取字符数
while ((charread = reader.read(tempchars)) != -1) {
// 同样屏蔽掉\r不显示
if ((charread == tempchars.length)
&& (tempchars[tempchars.length - 1] != '\r')) {
System.out.print(tempchars);
} else {
for (int i = 0; i < charread; i++) {
if (tempchars[i] == '\r') {
continue;
} else {
System.out.print(tempchars[i]);
}
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
/**
*
*/
public static List<String> readFileByLines(String fileName) {
List<String> returnString = new ArrayList<String>();
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
// 一次读入一行直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
returnString.add(tempString);
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
return returnString;
}
/**
*
*/
public static void readFileByRandomAccess(String fileName) {
RandomAccessFile randomFile = null;
try {
System.out.println("随机读取一段文件内容:");
// 打开一个随机访问文件流,按只读方式
randomFile = new RandomAccessFile(fileName, "r");
// 文件长度,字节数
long fileLength = randomFile.length();
// 读文件的起始位置
int beginIndex = (fileLength > 4) ? 4 : 0;
// 将读文件的开始位置移到beginIndex位置。
randomFile.seek(beginIndex);
byte[] bytes = new byte[10];
int byteread = 0;
// 一次读10个字节如果文件内容不足10个字节则读剩下的字节。
// 将一次读取的字节数赋给byteread
while ((byteread = randomFile.read(bytes)) != -1) {
System.out.write(bytes, 0, byteread);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (randomFile != null) {
try {
randomFile.close();
} catch (IOException e1) {
}
}
}
}
/**
*
*
* @param fileName
* @return
*/
public static String readFileAll(String fileName) {
String encoding = "UTF-8";
File file = new File(fileName);
Long filelength = file.length();
byte[] filecontent = new byte[filelength.intValue()];
try {
FileInputStream in = new FileInputStream(file);
in.read(filecontent);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
return new String(filecontent, encoding);
} catch (UnsupportedEncodingException e) {
System.err.println("The OS does not support " + encoding);
e.printStackTrace();
return "";
}
}
/**
*
*/
private static void showAvailableBytes(InputStream in) {
try {
System.out.println("当前字节输入流中的字节数为:" + in.available());
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -1,114 +0,0 @@
package xyz.wbsite.dbtool.web.framework.utils;//package com.example.demo.frame.utils;
import com.fasterxml.jackson.core.TreeNode;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
/**
* MD5Util - MD5
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class MD5Util {
/**
*
*
* @param value
* @return
*/
public static String encode(String value) {
try {
MessageDigest md = MessageDigest.getInstance("md5");
byte[] e = md.digest(value.getBytes());
return toHexString(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return value;
}
}
public static String encode(byte[] bytes) {
try {
MessageDigest md = MessageDigest.getInstance("md5");
byte[] e = md.digest(bytes);
return toHexString(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
private static String toHexString(byte bytes[]) {
StringBuilder hs = new StringBuilder();
String stmp = "";
for (int n = 0; n < bytes.length; n++) {
stmp = Integer.toHexString(bytes[n] & 0xff);
if (stmp.length() == 1)
hs.append("0").append(stmp);
else
hs.append(stmp);
}
return hs.toString();
}
/**
* json
* @param appSecret
* @param currentTime
* @return
*/
public static String toSign(TreeNode treeNode, String appSecret, String currentTime) {
String typesetting = sortAndJson(treeNode);
System.out.println(typesetting);
return MD5Util.encode(appSecret + typesetting + currentTime);
}
private static String sortAndJson(TreeNode treeNode) {
StringBuffer sb = new StringBuffer();
Iterator<String> keyIterator = treeNode.fieldNames();
while (keyIterator.hasNext()){
String next = keyIterator.next();
sb.append(next).append(treeNode.get(next));
}
return sb.toString();
}
//
// private static String sortAndJson(JSONObject jsonObject) {
// List<String> data = new ArrayList(jsonObject.keySet());
// Collections.sort(data);
// StringBuffer sb = new StringBuffer();
//
// for (String s : data) {
// sb.append(s);
// Object o = jsonObject.get(s);
// if (o == null) {
// sb.append("");
// } else if (o instanceof JSONArray) {
// sb.append(sortAndJson((JSONArray) o));
// } else if (o instanceof JSONObject) {
// sb.append(sortAndJson((JSONObject) o));
// } else {
// sb.append(o.toString());
// }
// }
// return sb.toString();
// }
/**
*
*
* @param args
*/
public static void main(String[] args) {
}
}

@ -1,270 +0,0 @@
package xyz.wbsite.dbtool.web.framework.utils;
import xyz.wbsite.dbtool.web.framework.base.BaseRequest;
import xyz.wbsite.dbtool.web.framework.base.BaseResponse;
import xyz.wbsite.dbtool.web.framework.base.ErrorType;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
public class ValidationUtil {
private static Validator validator;
/**
* ID
*
* @param id ID
* @return true, ID
*/
public static Boolean checkId(Long id) {
return !(null == id || id < 1);
}
public static Boolean checkDate(String value) {
try {
Double.valueOf(value);
} catch (Exception e) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
sdf.parse(value);
return true;
} catch (ParseException e1) {
e1.printStackTrace();
}
return false;
}
return true;
}
public static Boolean checkDatetime(String value) {
try {
Double.valueOf(value);
} catch (Exception e) {
List<String> sdfList = new ArrayList<>();
sdfList.add("yyyy-MM-dd HH:mm:ss");
sdfList.add("yyyy-MM-dd hh:mm:ss");
sdfList.add("yyyy/MM/dd HH:mm:ss");
sdfList.add("yyyy/MM/dd hh:mm:ss");
for (int i = 0; i < sdfList.size(); i++) {
String sdfValue = sdfList.get(i);
SimpleDateFormat sdf = new SimpleDateFormat(sdfValue);
try {
sdf.parse(value);
return true;
} catch (ParseException ignored) {
}
}
return false;
}
return true;
}
public static Boolean checkDouble(String value) {
try {
Double.parseDouble(value);
} catch (Exception e) {
return false;
}
return true;
}
/**
*
*
* @param value
* @return true || false
*/
public static Boolean checkInteger(String value) {
try {
Double d = Double.parseDouble(value);
int i = d.intValue();
return d == i;
} catch (Exception e) {
return false;
}
}
/**
*
*
* @param value
* @return true || false
*/
public static boolean checkLong(String value) {
try {
Double d = Double.parseDouble(value);
long l = d.longValue();
return d == l;
} catch (Exception e) {
return false;
}
}
/**
* ID
*
* @param ids ID
* @return true, ID
*/
public static Boolean checkIdList(List<Long> ids) {
return !(null == ids || ids.size() == 0);
}
/**
* truefalse<br/>
* <b></b>
*
* @param str
* @return true,false,
*/
public static Boolean checkString(String str) {
return !(null == str || 0 == str.trim().length());
}
/**
* <br><b></b>
*
* @param str
* @param minLength
* @param maxLength
* @return 250"aa"true"a"false
*/
public static Boolean checkStringLength(String str, int minLength, int maxLength) {
if (null == str) {
return false;
} else {
if (str.length() >= minLength && str.length() <= maxLength) {
return true;
}
}
return false;
}
/**
* <br/>
*
* @param email
* @return true, false<br/>
* <br/>
* 0123-abcd_ABCD@0123-abcd_ABCD.00aaBB--__.cc <b>true</b><br/>
* a@a.a <b>true</b><br/>
* tony@sina@qq.com <b>false</b>
*/
public static Boolean checkEmail(String email) {
//验证邮箱地址的正则表达式
Pattern p;
p = Pattern.compile(
"^([a-zA-Z0-9]+[_|_|-|-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|-|-|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,3}$");
Matcher m = p.matcher(email);
return m.matches();
}
/**
* <br/>
*
* @param filePath
* @return true, false<br/>
* <br/>
* C:\b.txt <b>true</b><br/>
* C:\abc\a.txt <b>true</b><br/>
* C:\windows\sys<\mfc.dll <b>false</b>
*/
public static Boolean checkFilePath(String filePath) {
//验证文件路径格式的正则表达式
Pattern p = Pattern.compile("^(?<path>(?:[a-zA-Z]:)?\\\\(?:[^\\\\\\?\\/\\*\\|<>:\"]+\\\\)+)(?<filename>(?<name>[^\\\\\\?\\/\\*\\|<>:\"]+?)\\.(?<ext>[^.\\\\\\?\\/\\*\\|<>:\"]+))$");
Matcher m = p.matcher(filePath);
return m.matches();
}
/**
*
*
* @param phone
* @return true, false<br>
* <br>
* 13345661234 <b>true</b> <br>
* 16812341234 <b>false</b> <br>
* 0512-123456 <b>false</b> <br>
* 0512-2345678 <b>true</b> <br>
* 12345678 <b>false</b> <br>
* 22345678 <b>true</b>
*/
public static Boolean checkPhone(String phone) {
List<Pattern> list = new LinkedList<>();
list.add(Pattern.compile("^[1][3,4,5,8][0-9]{9}$")); //验证手机号
list.add(Pattern.compile("^[0][1-9]{1,2}[0-9]-[2-9][0-9]{6,7}$")); //验证带区号固定电话,区号后加“-”
list.add(Pattern.compile("^[2-9][0-9]{6,7}$")); //验证不带区号的固定电话
list.add(Pattern.compile("([0][1-9]{1,2}[0-9])[2-9][0-9]{6,7}$"));
Matcher matcher;
Boolean result = false;
for (Pattern pattern : list) {
matcher = pattern.matcher(phone); //遍历匹配
result |= matcher.matches(); //对所有的匹配结果做或运算。
}
return result;
}
/**
* URL
*
* @param url
* @return
*/
public static Boolean checkUrl(String url) {
List<Pattern> list = new LinkedList<>();
list.add(Pattern.compile("^(http|www|ftp|)?(://)?(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*((:\\d+)?)(/(\\w+(-\\w+)*))*(\\.?(\\w)*)(\\?)?(((\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*(\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*)*(\\w*)*)$"));
Matcher matcher;
Boolean result = false;
for (Pattern pattern : list) {
matcher = pattern.matcher(url); //遍历匹配
result |= matcher.matches(); //对所有的匹配结果做或运算。
}
return result;
}
public static <T extends BaseResponse> T validate(BaseRequest req, T response) {
if (req == null) {
response.addError(ErrorType.EXPECTATION_NULL, "请求对象不能为空");
return response;
}
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Set<ConstraintViolation<BaseRequest>> constraintViolations = validator.validate(req);
if (constraintViolations.size() > 0) {
for (ConstraintViolation<BaseRequest> violation : constraintViolations) {
response.addError(ErrorType.INVALID_PARAMETER, violation.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.dumpException(e);
response.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return response;
}
}

@ -1,19 +1,37 @@
# 开发环境
server.port=80
server.servlet.context-path=/
server.servlet.context-path=
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources
spring.application.name=SpringBoot
# 根路径、欢迎页
web.welcome.page = index
# 排除的不需要验证的URL
web.url.excluded = /static/**,/open/**,/api,/index,/,/login
# 默认的登录URL
web.url.login = /login
# 日志配置
logging.config=classpath:logback-config.xml
# 热部署生效
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:/file-upload
spring.application.name=EXAMPLE-WEB
spring.main.banner-mode=CONSOLE
spring.devtools.restart.enabled=true
# 编码配置
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
# 日志配置
logging.path=D://
logging.levels=DEBUG
# mysql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=test
spring.datasource.password=123456
# mybatis
mybatis.mapper-locations=classpath:**/mpr/*.xml
# pagehelper
pagehelper.autoRuntimeDialect=true
pagehelper.reasonable=false
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
# jackson 相关配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.jackson.default-property-inclusion=use_defaults
spring.jackson.mapper.sort-properties-alphabetically=true
spring.jackson.deserialization.fail-on-unknown-properties=false
# freemarker
spring.freemarker.enabled=true
spring.freemarker.allow-request-override=false
@ -26,9 +44,23 @@ spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
spring.freemarker.settings.template_update_delay=1
spring.freemarker.settings.locale=zh_CN
spring.freemarker.settings.datetime_format=yyyy-MM-dd
spring.freemarker.settings.datetime_format=yyyy-MM-dd HH:mm:ss
spring.freemarker.settings.date_format=yyyy-MM-dd
spring.freemarker.settings.number_format=#.##
spring.freemarker.settings.classic_compatible=true
spring.freemarker.settings.whitespace_stripping=true
spring.freemarker.settings.url_escaping_charset=utf-8
# 文件上传配置
spring.servlet.multipart.resolveLazily=false
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
# 自定义配置
# 根路径默认页,'/'跳转至该页
web.welcome.page=/index.htm
# 登录页
web.login.page=/login.htm
# 拦截验证
web.url.auth.included=/,/**/*.htm
# 直接放行
web.url.auth.excluded=/login.htm

@ -1,26 +0,0 @@
${AnsiColor.BRIGHT_YELLOW}
/////////////////////////////////////////////////////////
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
/////////////////////////////////////////////////////////
佛祖保佑 永无BUG
:: Spring Boot :: ${spring-boot.formatted-version} (${spring.profiles.active})

@ -1,8 +1,10 @@
<?xml version="1.0"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志根目录(可以随平台修改)-->
<property name="root" value="D:/"></property>
<!-- 日志根目录 -->
<springProperty scope="context" name="root" source="logging.path"/>
<!-- 日志等级 -->
<springProperty scope="context" name="level" source="logging.levels"/>
<!-- 迭代日志All级别文件 -->
<appender name="RollingFile_ALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
@ -93,18 +95,15 @@
</encoder>
</appender>
<logger name="java.sql" level="INFO"></logger>
<logger name="org.apache.velocity" level="OFF"></logger>
<logger name="org.springframework.ui.freemarker" level="OFF"></logger>
<!-- 日志总入口 -->
<root level="INFO">
<root level="${level}">
<appender-ref ref="RollingFile_ALL"/>
<appender-ref ref="RollingFile_ERROR"/>
<appender-ref ref="RollingFile_WARN"/>
<appender-ref ref="RollingFile_INFO"/>
<!--<appender-ref ref="Console"/>-->
<appender-ref ref="Console"/>
</root>
</configuration>

@ -4,8 +4,8 @@ import ${basePackage}.frame.base.*;
import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.config.ActionConfig;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.FileUtil;
import org.springframework.beans.BeansException;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpHeaders;
@ -300,7 +300,7 @@ public class GlobalController implements ErrorController {
headers, HttpStatus.CREATED);
}
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(file)),
return new ResponseEntity<byte[]>(FileUtil.readFileToByteArray(new File(file)),
headers, HttpStatus.CREATED);
}

@ -1,8 +1,8 @@
package ${basePackage}.frame.utils;
import ${basePackage}.frame.auth.LocalData;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import ${basePackage}.frame.auth.LocalData;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
/**
* CookieUtil

@ -0,0 +1,110 @@
package ${basePackage}.frame.utils;
import java.io.*;
public class FileUtil {
public static byte[] readFileToByteArray(File file) throws IOException {
InputStream in = openInputStream(file);
Throwable var2 = null;
byte[] var5;
try {
long fileLength = file.length();
var5 = fileLength > 0L ? toByteArray(in, fileLength) : toByteArray(in);
} catch (Throwable var14) {
var2 = var14;
throw var14;
} finally {
if (in != null) {
if (var2 != null) {
try {
in.close();
} catch (Throwable var13) {
var2.addSuppressed(var13);
}
} else {
in.close();
}
}
}
return var5;
}
public static FileInputStream openInputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
} else if (!file.canRead()) {
throw new IOException("File '" + file + "' cannot be read");
} else {
return new FileInputStream(file);
}
} else {
throw new FileNotFoundException("File '" + file + "' does not exist");
}
}
public static byte[] toByteArray(InputStream input, long size) throws IOException {
if (size > 2147483647L) {
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);
} else {
return toByteArray(input, (int) size);
}
}
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Throwable var2 = null;
byte[] var3;
try {
copy((InputStream) input, (OutputStream) output);
var3 = output.toByteArray();
} catch (Throwable var12) {
var2 = var12;
throw var12;
} finally {
if (output != null) {
if (var2 != null) {
try {
output.close();
} catch (Throwable var11) {
var2.addSuppressed(var11);
}
} else {
output.close();
}
}
}
return var3;
}
public static int copy(InputStream input, OutputStream output) throws IOException {
long count = copyLarge(input, output);
return count > 2147483647L ? -1 : (int) count;
}
public static long copyLarge(InputStream input, OutputStream output) throws IOException {
return copy(input, output, 4096);
}
public static long copy(InputStream input, OutputStream output, int bufferSize) throws IOException {
return copyLarge(input, output, new byte[bufferSize]);
}
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {
long count;
int n;
for (count = 0L; -1 != (n = input.read(buffer)); count += (long) n) {
output.write(buffer, 0, n);
}
return count;
}
}

@ -48,11 +48,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- mybatis 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
@ -154,11 +149,6 @@
<artifactId>dozer</artifactId>
<version>${r'${dozer-version}'}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${r'${commons-io-version}'}</version>
</dependency>
</dependencies>
</dependencyManagement>

@ -0,0 +1,110 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>403-对不起!您访问的页面未授权</title>
<style type="text/css">
* {
box-sizing: border-box;
}
body {
background-color: #dfdfdf;
}
.box {
margin: 50px auto;
background-color: #ffffff;
width: 920px;
height: 320px;
overflow: hidden;
border: 10px solid #0000002b;
position: relative;
}
.box div.img {
width: 300px;
height: 300px;
margin-top: 50px;
margin-left: 50px;
}
.box div.info {
width: 600px;
position: absolute;
right: 0;
top: 50px;
height: 200px;
overflow: auto;
}
.box div.info {
font-size: 14px;
}
.control {
position: absolute;
bottom: 0;
right: 0;
margin-right: 20px;
margin-bottom: 20px;
}
.control a {
margin-top: 50px;
text-decoration: none;
background: #f2f2f2;
cursor: pointer;
border: 3px solid #0000002b;
padding: 5px;
}
.control a:hover {
background: #e6e6e6;
border: 3px solid #0000002b
}
</style>
</head>
<body>
<div class="box">
<div class="img">
<svg t="1571239589656" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
p-id="3448" width="200" height="200">
<path d="M512 928C282.25 928 96 741.75 96 512S282.25 96 512 96s416 186.25 416 416-186.25 416-416 416zM288 448c-17.673 0-32 14.327-32 32v96h480c17.673 0 32-14.327 32-32v-96H288z"
p-id="3449"></path>
</svg>
</div>
<div class="info">
<p>抱歉!您尚未登录或登录信息已失效,或尚未授权!</p>
</div>
<div class="control">
<a onclick="history.back()">返回上页</a> <a id="login" href="${context}/login.htm"">登录</a>
</div>
<script>
window.onload = function () {
var count = 3;
function go() {
if (count > 0) {
var e = document.getElementById("login");
e.innerHTML = "登录(" + count + " 秒后自动跳转)"
count--;
} else {
location.href = "${context}/login.htm";
}
}
setInterval(go, 1000);
};
</script>
</div>
</body>
</html>

@ -0,0 +1,90 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>404-对不起!您访问的页面不存在</title>
<style type="text/css">
* {
box-sizing: border-box;
}
body {
background-color: #dfdfdf;
}
.box {
margin: 50px auto;
background-color: #ffffff;
width: 920px;
height: 320px;
overflow: hidden;
border: 10px solid #0000002b;
position: relative;
}
.box div.img {
width: 300px;
height: 300px;
margin-top: 50px;
margin-left: 50px;
}
.box div.info {
width: 600px;
position: absolute;
right: 0;
top: 50px;
height: 200px;
overflow: auto;
}
.box div.info {
font-size: 14px;
}
.control {
position: absolute;
bottom: 0;
right: 0;
margin-right: 20px;
margin-bottom: 20px;
}
.control a {
margin-top: 50px;
text-decoration: none;
background: #f2f2f2;
cursor: pointer;
border: 3px solid #0000002b;
padding: 5px;
}
.control a:hover {
background: #e6e6e6;
border: 3px solid #0000002b
}
</style>
</head>
<body>
<div class="box">
<div class="img">
<svg t="1571230949474" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
p-id="793" width="200" height="200">
<path d="M931.6 585.6v79c28.6-60.2 44.8-127.4 44.8-198.4C976.4 211 769.4 4 514.2 4S52 211 52 466.2c0 3.2 0.2 6.4 0.2 9.6l166-206h96.4L171.8 485.6h46.4v-54.8l99.2-154.6V668h-99.2v-82.4H67.6c43 161 170.6 287.4 332.4 328.6-10.4 26.2-40.6 89.4-90.8 100.6-62.2 14 168.8 3.4 333.6-104.6C769.4 873.6 873.6 784.4 930.2 668h-97.6v-82.4H666.4V476l166.2-206.2h94L786.2 485.6h46.4v-59l99.2-154v313zM366.2 608c-4.8-11.2-7.2-23.2-7.2-36V357.6c0-12.8 2.4-24.8 7.2-36 4.8-11.2 11.4-21 19.6-29.2 8.2-8.2 18-14.8 29.2-19.6 11.2-4.8 23.2-7.2 36-7.2h81.6c12.8 0 24.8 2.4 36 7.2 11 4.8 20.6 11.2 28.8 19.2l-88.6 129.4v-23c0-4.8-1.6-8.8-4.8-12-3.2-3.2-7.2-4.8-12-4.8s-8.8 1.6-12 4.8c-3.2 3.2-4.8 7.2-4.8 12v72L372.6 620c-2.4-3.8-4.6-7.8-6.4-12z m258.2-36c0 12.8-2.4 24.8-7.2 36-4.8 11.2-11.4 21-19.6 29.2-8.2 8.2-18 14.8-29.2 19.6-11.2 4.8-23.2 7.2-36 7.2h-81.6c-12.8 0-24.8-2.4-36-7.2-11.2-4.8-21-11.4-29.2-19.6-3.6-3.6-7-7.8-10-12l99.2-144.6v50.6c0 4.8 1.6 8.8 4.8 12 3.2 3.2 7.2 4.8 12 4.8s8.8-1.6 12-4.8c3.2-3.2 4.8-7.2 4.8-12v-99.6L601 296.4c6.6 7.4 12 15.8 16 25.2 4.8 11.2 7.2 23.2 7.2 36V572z"
p-id="794"></path>
</svg>
</div>
<div class="info">
<p>抱歉,您所请求的页面不存在或暂时不可用、也可能已被永久移除!</p>
</div>
<div class="control">
<a onclick="history.back()">返回上页</a> <a href="/">返回首页</a>
</div>
</div>
</body>
</html>

@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>500-服务器走了下神!</title>
<style type="text/css">
* {
box-sizing: border-box;
}
body {
background-color: #dfdfdf;
}
.box {
margin: 50px auto;
background-color: #ffffff;
width: 920px;
height: 320px;
overflow: hidden;
border: 10px solid #0000002b;
position: relative;
}
.box div.img {
width: 300px;
height: 300px;
margin-top: 50px;
margin-left: 50px;
}
.box div.info {
width: 600px;
position: absolute;
right: 0;
top: 50px;
height: 200px;
overflow: auto;
}
.box div.info {
font-size: 14px;
}
.control {
position: absolute;
bottom: 0;
right: 0;
margin-right: 20px;
margin-bottom: 20px;
}
.control a {
margin-top: 50px;
text-decoration: none;
background: #f2f2f2;
cursor: pointer;
border: 3px solid #0000002b;
padding: 5px;
}
.control a:hover {
background: #e6e6e6;
border: 3px solid #0000002b
}
</style>
</head>
<body>
<div class="box">
<div class="img">
<svg t="1571230949474" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
p-id="793" width="200" height="200">
<path d="M931.6 585.6v79c28.6-60.2 44.8-127.4 44.8-198.4C976.4 211 769.4 4 514.2 4S52 211 52 466.2c0 3.2 0.2 6.4 0.2 9.6l166-206h96.4L171.8 485.6h46.4v-54.8l99.2-154.6V668h-99.2v-82.4H67.6c43 161 170.6 287.4 332.4 328.6-10.4 26.2-40.6 89.4-90.8 100.6-62.2 14 168.8 3.4 333.6-104.6C769.4 873.6 873.6 784.4 930.2 668h-97.6v-82.4H666.4V476l166.2-206.2h94L786.2 485.6h46.4v-59l99.2-154v313zM366.2 608c-4.8-11.2-7.2-23.2-7.2-36V357.6c0-12.8 2.4-24.8 7.2-36 4.8-11.2 11.4-21 19.6-29.2 8.2-8.2 18-14.8 29.2-19.6 11.2-4.8 23.2-7.2 36-7.2h81.6c12.8 0 24.8 2.4 36 7.2 11 4.8 20.6 11.2 28.8 19.2l-88.6 129.4v-23c0-4.8-1.6-8.8-4.8-12-3.2-3.2-7.2-4.8-12-4.8s-8.8 1.6-12 4.8c-3.2 3.2-4.8 7.2-4.8 12v72L372.6 620c-2.4-3.8-4.6-7.8-6.4-12z m258.2-36c0 12.8-2.4 24.8-7.2 36-4.8 11.2-11.4 21-19.6 29.2-8.2 8.2-18 14.8-29.2 19.6-11.2 4.8-23.2 7.2-36 7.2h-81.6c-12.8 0-24.8-2.4-36-7.2-11.2-4.8-21-11.4-29.2-19.6-3.6-3.6-7-7.8-10-12l99.2-144.6v50.6c0 4.8 1.6 8.8 4.8 12 3.2 3.2 7.2 4.8 12 4.8s8.8-1.6 12-4.8c3.2-3.2 4.8-7.2 4.8-12v-99.6L601 296.4c6.6 7.4 12 15.8 16 25.2 4.8 11.2 7.2 23.2 7.2 36V572z"
p-id="794"></path>
</svg>
</div>
<div class="info">
<p style="font-size: 18px;font-weight: bold">服务器内部错误,错误信息如下:</p>
<p style="color: red">${msg}</p>
</div>
<div class="control">
<a onclick="history.back()">返回上页</a> <a href="/">返回首页</a>
</div>
</div>
</body>
</html>

@ -0,0 +1,119 @@
<div id="header">
<div class="logo">
<img @click="this.nav.toHome()" src="${context}/static/img/logo.png">
</div>
<a class="home" href="${context}">Home</a>
<div class="menu">
<ul>
<li>
<a href="${context}/1">首页</a>
</li>
<li>
<a href="${context}/2">工作台</a>
</li>
<li>
<a href="${context}/3">消息中心</a>
</li>
<li>
<a href="${context}/4">关于我</a>
</li>
</ul>
</div>
</div>
<style>
#header {
width: 100%;
height: 50px;
line-height: 50px;
overflow: hidden;
background: #2a2a2a;
box-shadow: 0px 2px 8px 0px;
}
#header .logo {
display: inline-block;
height: 50px;
width: 50px;
margin-left: 10px;
text-align: center;
}
#header .logo img {
width: 50%;
height: 50%;
vertical-align: middle;
}
.home {
display: inline-block;
color: #ffffff;
font-weight: bold;
transition: all 0.3s;
}
.home:hover {
color: #ffffff;
transform: translate(2px);
}
#header .menu {
display: inline-block;
float: right;
}
#header .menu ul {
display: inline-block;
}
#header .menu ul li {
display: inline-block;
vertical-align: top;
}
#header .menu ul li a {
color: #ffffff;
display: inline-block;
text-align: center;
position: relative;
margin: 0px 15px;
height: 50px;
}
#header .menu ul li a:after {
content: "";
display: inline-block;
background: #ffffff;
width: 0%;
height: 2px;
position: absolute;
bottom: 2px;
left: 50%;
transition: all 0.3s;
}
#header .menu ul li a img {
margin-top: 8px;
height: 32px;
}
#header .menu ul li a:hover:after {
width: 100%;
left: 0%;
}
#header .tx {
display: inline-block;
float: right;
height: 50px;
width: 50px;
margin-left: 20px;
}
#header .tx img {
width: 50%;
height: 50%;
vertical-align: middle;
}
</style>

@ -0,0 +1,63 @@
<#macro print items >
<#nested>:
<#list items as item>
<a>${item}</a>
</#list>
</#macro>
<#--
参数说明:
pageNumber当前的页码
pageSize页码大小
totalCount总数
showPages显示的页码个数
callback回调函数
-->
<#macro page pageNumber pageSize totalCount showPages callback>
<#if totalCount gt 0>
<div class="page_list">
<#assign totalPage = 0/>
<#assign totalPage = (totalCount/pageSize)?ceiling/>
<#if pageNumber==1>
<a href="javascript:;" class="top_page disabled">首页</a>
<a href="javascript:;" class="page_prev disabled">上一页</a>
</#if>
<#if pageNumber!=1>
<a href="javascript:${callback+'('+1+')'};" class="top_page">首页</a>
<a href="javascript:${callback+'('+(pageNumber-1)+')'};" class="page_prev">上一页</a>
</#if>
<#if pageNumber-showPages/2 gt 0>
<#assign start = pageNumber-(showPages-1)/2/>
<#if showPages gt totalPage>
<#assign start = 1/>
</#if>
<#else>
<#assign start = 1/>
</#if>
<#if totalPage gt showPages>
<#assign end = (start+showPages-1)/>
<#if end gt totalPage>
<#assign start = totalPage-showPages+1/>
<#assign end = totalPage/>
</#if>
<#else>
<#assign end = totalPage/>
</#if>
<#assign pages=start..end/>
<#list pages as page>
<#if page==pageNumber>
<a href="javascript:${callback+'('+page+')'};" class="current">${page}</a>
<#else>
<a href="javascript:${callback+'('+page+')'};">${page}</a>
</#if>
</#list>
<#if pageNumber==totalPage>
<a href="javascript:;" class="page_next disabled">下一页</a>
<a href="javascript:;" class="end_page disabled">尾页</a>
</#if>
<#if pageNumber!=totalPage>
<a href="javascript:${callback+'('+(pageNumber+1)+')'};" class="page_next">下一页</a>
<a href="javascript:${callback+'('+totalPage+')'};" class="end_page">尾页</a>
</#if>
</div>
</#if>
</#macro>

@ -0,0 +1,160 @@
<script>
window.nav = new Vue({
data: {
activeIndex: 'home',
contextPath: '${contextPath?default("")}',
homePath: '${homePath?default("")}',
loadingTip: '',
loadingBar: '',
tip: {
show: function (msg) {
var message = "<i class='el-icon-loading'></i> 正在加载 ..."
if (msg) {
message = "<i class='el-icon-loading'></i> " + msg
}
if (!nav.loadingTip) {
nav.loadingTip = nav.$message({
type: '',
duration: 0,
dangerouslyUseHTMLString: true,
message: message
});
} else {
nav.loadingTip.message = message;
}
},
close: function () {
if (nav.loadingTip) {
nav.loadingTip.close();
nav.loadingTip = '';
}
}
},
bar: {
show: function () {
if (!nav.loadingBar) {
nav.loadingBar = nav.$message({
type: '',
duration: 0,
customClass: 'loading-bar',
dangerouslyUseHTMLString: true,
message: '<i class="bar" style="width: 90%"></i>'
});
} else {
nav.loadingBar.message = '<i class="bar" style="width: 90%"></i>'
}
},
finish: function () {
if (nav.loadingBar) {
nav.loadingBar.message = '<i class="bar" style="width: 100%"></i>'
setTimeout(function(){
if (nav.loadingBar) {
nav.loadingBar.close();
nav.loadingBar = '';
}
},500);
}
},
error: function () {
if (nav.loadingBar) {
nav.loadingBar.message = '<i class="bar error" style="width: 100%"></i>'
setTimeout(function(){
if(nav.loadingBar){
nav.loadingBar.close();
nav.loadingBar = '';
}
},500);
}
}
}
},
methods: {
i: function (message, callback) {
this.$message({
type: "info",
showClose: true,
message: message,
duration: 1500,
onClose: callback
});
},
e: function (message, callback) {
this.$message({
type: "error",
showClose: true,
message: message,
duration: 1500,
onClose: callback
});
},
w: function (message, callback) {
this.$message({
type: "warning",
showClose: true,
message: message,
duration: 1500,
onClose: callback
});
},
s: function (message, callback) {
this.$message({
type: "success",
showClose: true,
message: message,
duration: 1500,
onClose: callback
});
},
toOpen: function (url) {
nav.tip.show();
var url = url.substring(0, 1) == "/" ? url.substring(1) : url;
$("body").append($("<a id='wb-open' href='" + this.contextPath + "/" + url + "' target='_self' style='dispaly:none;'></a>"))
document.getElementById("wb-open").click();
$("#wb-open").remove();
},
toOpenNew: function (url) {
var url = url.substring(0, 1) == "/" ? url.substring(1) : url;
$("body").append($("<a id='wb-open' href='" + this.contextPath + "/" + url + "' target='_blank' style='dispaly:none;'></a>"))
document.getElementById("wb-open").click();
$("#wb-open").remove();
},
toHome: function () {
nav.tip.show();
location.href = this.contextPath + "/"
},
/**
* 滚动屏蔽至顶部
*/
scrollToTop: function () {
var distance = document.documentElement.scrollTop || document.body.scrollTop;
var step = distance / 10;
(function jump() {
if (distance > 0) {
distance -= step;
window.scrollTo(0, distance);
setTimeout(jump, 10)
}
})();
},
/**
* 控制任一目标滚动到顶部
* select jquery对象
*/
scrollToTop: function (select) {
var distance = $(select).scrollTop();
var step = distance / 10;
(function jump() {
if (distance > 0) {
distance -= step;
$(select).scrollTop(distance);
setTimeout(jump, 10)
} else {
$(select).scrollTop(distance);
}
})();
}
}
});
</script>

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="${context}/static/dist/lib.min.js" type="text/javascript"></script>
<script src="${context}/static/dist/index.min.js" type="text/javascript"></script>
<link href="${context}/static/dist/index.min.css" rel="stylesheet"/>
<script src="${context}/static/js/ajax.js" type="text/javascript"></script>
<link href="${context}/static/css/base.css" rel="stylesheet"/>
</head>
<body>
<#include controlHolder("nav")/>
<#include screenHolder()/>
</body>
</html>

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="${context}/static/favicon.ico" rel="icon" type="image/x-icon"/>
<script src="${context}/static/dist/lib.min.js" type="text/javascript"></script>
<script src="${context}/static/dist/index.min.js" type="text/javascript"></script>
<link href="${context}/static/dist/index.min.css" rel="stylesheet"/>
</head>
<body>
<#include screenHolder()/>
</body>
</html>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,337 @@
<div id="index" v-cloak>
<div id="aside">
<el-menu
:style="{width:(properties.isCollapse?'64px':'200px')}"
:default-active="properties.defaultActive"
@open="handleOpen"
@close="handleClose"
@select="handleSelect"
:unique-opened="properties.uniqueOpened"
:collapse="properties.isCollapse"
:collapse-transition="properties.transition"
background-color="#252a2f"
text-color="#d6d6d6"
active-text-color="#ffd04b">
<el-submenu index="2bd1dc9b-9444-4923-a186-7b420497b9e8" >
<template slot="title">
<i class="el-icon-setting"></i>
<span slot="title">系统设置</span>
</template>
<el-menu-item index="23975e43-cc83-4eb7-b0ec-7b4b5fa8e334" @click="addTab({title: '字典管理', name: 'dict', url: '${context}/system/dict.htm'})">字典管理</el-menu-item>
</el-submenu>
<el-submenu index="188f8373-c8f3-4ef8-85d8-19269609935b">
<template slot="title">
<i class="el-icon-time"></i>
<span slot="title">用户系统</span>
</template>
<el-menu-item index="1101dd41-b05b-4589-a40b-64436e1c9836" @click="addTab({title: '用户1', name: 'USER1', url: '${context}/user/user1.htm'})">用户1</el-menu-item>
</el-submenu>
</el-menu>
</div>
<div id="main">
<div id="head">
<div class="collapseSwitch" @click="collapseSwitch">
<a :class="properties.isCollapse?'reversal':''"><i class="el-icon-s-grid"></i></a>
</div>
<el-link :underline="false" @click="onHome" icon="el-icon-s-home">首页</el-link>
<div class="menu">
<ul>
<li>
<el-input
size="mini"
placeholder="请输入搜索内容">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</li>
<li>
<el-link :underline="false" @click="onHome" icon="el-icon-message-solid"><span
style="line-height: 20px;"><el-badge is-dot class="item">消息</el-badge></span></el-link>
</li>
<li>
<el-dropdown>
<el-link :underline="false" @click="onHome" icon="el-icon-user-solid">账户信息</el-link>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>个人信息</el-dropdown-item>
<el-dropdown-item>修改密码</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</li>
<li>
<el-link :underline="false" @click="onHome" icon="el-icon-warning-outline">系统版本</el-link>
</li>
<li>
<el-link :underline="false" icon="el-icon-switch-button"></el-link>
</li>
</ul>
</div>
</div>
<div id="content">
<el-tabs v-model="activeTabName" type="border-card" closable @tab-remove="removeTab">
<el-tab-pane
v-for="(item, index) in tabs"
:key="item.name"
:label="item.title"
:name="item.name">
<iframe :src="item.url" style="width: 100%;height: 100%;border: 0;"></iframe>
</el-tab-pane>
</el-tabs>
</div>
</div>
</div>
<style>
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
margin: 0;
padding: 0;
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
}
html, body, #index, #main, #content {
width: 100%;
height: 100%;
}
a {
text-decoration: none;
outline: 0;
cursor: pointer;
-webkit-transition: color .2s ease;
transition: color .2s ease;
-webkit-text-decoration-skip: objects;
color: #757575;
}
a:active, a:hover {
outline-width: 0
}
a:hover {
opacity: 0.7;
}
a:active {
opacity: 0.9;
}
a:active, a:hover {
outline: 0;
text-decoration: none
}
a[disabled] {
color: #ccc;
cursor: not-allowed;
pointer-events: none
}
body {
overflow: hidden;
}
#index {
display: flex;
}
#aside {
background: #252a2f;
}
#aside .el-menu {
transition: all .5s;
border-right: 0
}
#aside .el-menu-item, .el-submenu__title {
height: 40px;
line-height: 40px;
}
#main {
flex-grow: 1;
}
#head {
width: 100%;
height: 40px;
line-height: 40px;
overflow: hidden;
background: #252a2f;
}
#head .collapseSwitch {
display: inline-block;
height: 40px;
width: 40px;
text-align: center;
font-size: 24px;
border-left: 1px solid #424242;
border-right: 1px solid #424242;
}
#head .collapseSwitch a {
display: inline-block;
transition: all 1s;
}
#head .collapseSwitch a.reversal {
transform: rotate(90deg);
}
#head a {
color: #d6d6d6;
vertical-align: top;
}
#head a:hover {
color: #409EFF;
opacity: 1;
}
#head .collapseSwitch:hover {
background: #3b4146;
}
#head .menu {
display: inline-block;
float: right;
}
#head .menu ul {
display: inline-block;
}
#head .menu ul li {
display: inline-block;
vertical-align: top;
}
#head .menu ul li a {
display: inline-block;
text-align: center;
position: relative;
margin: 0 10px;
height: 40px;
vertical-align: top;
}
#head .menu ul li a:after {
content: "";
display: inline-block;
background: #409EFF;
width: 0;
height: 2px;
position: absolute;
bottom: 2px;
left: 50%;
transition: all 0.3s;
}
#head .menu ul li a:hover:after {
width: 100%;
left: 0%;
}
#content {
height: calc(100% - 35px);
}
#content > div {
height: 100%;
}
#content > div > .el-tabs__content {
padding: 0;
height: calc(100% - 43px);
}
#content .el-tabs__item {
padding: 0 10px;
}
#content .el-tabs__nav {
white-space: normal !important;
}
#content > div > .el-tabs__content .el-tab-pane {
height: 100%;
background: #f0f2f5;
}
</style>
<script>
window.index = new Vue({
el: "#index",
data: {
tabs: [],//所有Tabs
activeTabName: '',
properties: {
uniqueOpened: true,//是否保持一个子菜单展开
isCollapse: false,//左侧菜单是否收缩
transition:false,
}
},
methods: {
onHome: function () {
this.addTab({
title: '首页',
name: 'home',
url: '${contextPath}/home.htm'
})
},
collapseSwitch: function () {
this.properties.isCollapse = !this.properties.isCollapse;
},
handleOpen: function () {
},
handleClose: function () {
},
handleSelect: function (index) {
},
addTab: function (tab) {
//查找是否存在该tab
var tempTabs = this.tabs.filter(function (tab_) {
return tab_.name === tab.name;
})
//不存在则添加
if (tempTabs.length <= 0) {
this.tabs.push(tab)
}
this.activeTabName = tab.name;
},
removeTab: function (tabName) {
var activeName = this.activeTabName;
var tempTabs = this.tabs;
if (activeName === tabName) {
tempTabs.forEach(function (tab, index) {
if (tab.name === tabName) {
var nextTab = tempTabs[index + 1] || tempTabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.activeTabName = activeName;
this.tabs = tempTabs.filter(function (tab) {
return tab.name !== tabName
})
}
},
created: function () {
},
mounted: function () {
this.onHome();//页面初始好后打开首页
},
watch: {}
})
</script>

@ -0,0 +1,139 @@
<div id="app" v-cloak>
<div class="frame">
<div class="login-box">
<div class="login-title">系统登录</div>
<el-form :model="form" :rules="rules" ref="form" class="form">
<el-form-item prop="username">
<el-input placeholder="用户名" v-model="form.username">
<template slot="prepend"><i class="icon iconfont el-icon-user"></i></template>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input placeholder="密码" v-model="form.password" type="password">
<template slot="prepend"><i class="icon iconfont el-icon-lock"></i></template>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" style="width: 100%" :loading="isLogin" :disabled="isLogin"
@click="submitForm('form')">登录
</el-button>
</el-form-item>
</el-form>
<a class="tip">系统登录</a>
</div>
</div>
</div>
<style>
#app {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
display: flex;
background: #001d3a;
justify-content: center;
align-items: center;
}
.frame {
width: 600px;
height: 500px;
background: #42424263;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 0 10px 0 #afafaf52;
}
.login-box {
display: inline-block;
background: #fff;
border-radius: 5px;
text-align: left;
}
.login-title {
line-height: 50px;
border-bottom: 1px solid #e8e8e8;
font-weight: bold;
text-align: left;
padding-left: 20px;
font-size: 15px;
height: 50px;
color: #757575;
}
.form {
width: 300px;
margin-top: 20px;
margin-left: 20px;
margin-right: 20px;
}
.form .el-input-group__prepend {
padding: 10px;
}
.tip {
padding: 5px;
display: inline-block;
text-align: center;
color: #b7b7b7;
width: 100%;
margin-bottom: 10px;
}
</style>
<script type="text/javascript">
var app = new Vue({
el: "#app",
data: {
form: {
username: '',
password: ''
},
rules: {
username: [
{required: true, message: '请输入用户名', trigger: 'blur'}
],
password: [
{required: true, message: '请输入密码', trigger: 'change'}
],
},
isLogin: false
},
mounted: function () {
},
methods: {
submitForm: function (formName) {
this.$refs[formName].validate(function (valid) {
if (valid) {
this.isLogin = true;
ajax.authLogin(this.form).then(function (response) {
this.isLogin = false;
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
nav.i("登录成功!", function () {
location.href = "/index.htm"
});
}
})
} else {
return false;
}
}.bind(this));
},
resetForm: function (formName) {
this.$refs[formName].resetFields();
}
},
})
</script>

@ -0,0 +1,343 @@
<div id="app" v-cloak>
<el-card class="box-card">
<el-form :inline="true" :model="vm" ref="vm" label-width="90px">
<el-form-item label="字典名称" prop="dictName">
<el-input v-model="vm.dictName" clearable size="small" placeholder=""></el-input>
</el-form-item>
<el-form-item label="字典代码" prop="dictCode">
<el-input v-model="vm.dictCode" clearable size="small" placeholder=""></el-input>
</el-form-item>
<el-form-item label="是否有效" prop="valid">
<el-select v-model="vm.valid" size="small" placeholder="">
<el-option label="所有" value=""></el-option>
<el-option label="有效" value="true"></el-option>
<el-option label="无效" value="false"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" size="small" icon="el-icon-search" @click="onSearch">搜索</el-button>
<el-button type="warning" size="small" icon="el-icon-refresh-left" @click="onReset('vm')">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="box-card">
<el-row>
<el-col :span="12">
<el-button type="success" size="small" icon="el-icon-plus" @click="onAction(['create',''])">新增
</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button>
<el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px">
<el-form-item label="字典名称" prop="dictName">
<el-input size="small" v-model="form.dictName"></el-input>
</el-form-item>
<el-form-item label="字典代码" prop="dictCode">
<el-input size="small" v-model="form.dictCode"></el-input>
</el-form-item>
<el-form-item label="字典版本" required>
<el-date-picker size="small"
v-model="form.version"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
placeholder="选择日期时间"
align="right">
</el-date-picker>
</el-form-item>
<el-form-item label="是否有效" prop="valid">
<el-switch size="small" v-model="form.valid"></el-switch>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="form.dialog = false">取 消</el-button>
<el-button size="small" type="primary" @click="onAction(['save',''])">保存</el-button>
</span>
</el-dialog>
</el-col>
<el-col :span="12">
<el-button-group style="float: right;">
<el-button size="small" icon="el-icon-delete" @click="onBitchDelete"></el-button>
<el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
</el-button-group>
</el-col>
</el-row>
<el-table
style="margin-top: 10px"
@selection-change="onSelectionChange"
empty-text="无数据"
:data="result"
size="small"
style="width: 100%">
<el-table-column
align="center"
type="selection"
width="50">
</el-table-column>
<el-table-column
align="center"
prop="id"
label="主键"
width="140">
</el-table-column>
<el-table-column
align="center"
width="80"
label="是否有效">
<template slot-scope="scope">
<el-tag size="mini" v-if="scope.row.valid">有效</el-tag>
<el-tag size="mini" type="danger" v-if="!scope.row.valid">无效</el-tag>
</template>
</el-table-column>
<el-table-column
align="center"
prop="dictName"
label="字典名称">
</el-table-column>
<el-table-column
align="center"
prop="dictCode"
label="字典代码">
</el-table-column>
<el-table-column
align="center"
prop="version"
label="字典版本">
</el-table-column>
<el-table-column
align="center"
prop="createTime"
label="创建时间">
</el-table-column>
<el-table-column
align="center"
fixed="right"
width="120"
label="操作">
<template slot-scope="scope">
<el-dropdown size="mini" split-button type="primary" @click="onAction(['view',scope.row])"
@command="onAction">
<i class="el-icon-tickets"></i>查看
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="['edit',scope.row]" icon="el-icon-edit">编辑</el-dropdown-item>
<el-dropdown-item :command="['delete',scope.row]" icon="el-icon-delete">删除
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<el-pagination
style="margin-top: 10px"
v-if="vm.totalCount > vm.pageSize"
@current-change="onPage"
:current-page="vm.pageNumber"
:page-size="vm.pageSize"
layout="total, prev, pager, next, jumper"
:total="vm.totalCount">
</el-pagination>
</el-card>
</div>
<style>
#app {
padding: 10px;
}
.box-card {
margin: 10px;
}
.form .el-dialog {
width: 700px;
}
.form .el-dialog .el-form-item__content {
width: 220px;
}
</style>
<script>
var app = new Vue({
el: "#app",
data: {
vm: {
id: '',
dictName: '',
dictCode: '',
valid: "",
pageNumber: 1,
pageSize: 10,
totalCount: 0
},
select: [],
result: [],
form: {
title: "",
dialog: false,
id: '',
dictName: '',
dictCode: '',
version: '',
valid: false,
rowVersion: '',
},
formRules: {
dictName: [
{required: true, message: '请输入字典名称', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur'}
],
dictCode: [
{required: true, message: '请输入字典代码', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
],
version: [
{type: 'date', required: true, message: '字典版本不能为空', trigger: 'change'}
],
},
},
methods: {
onSearch: function () {
this.vm.pageNumber = 1;
this.onFind();
},
onReset: function (form) {
this.$refs[form].resetFields();
nav.w('重置成功');
},
onFind: function () {
ajax.dictFind(this.vm).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.result = response.result;
this.vm.totalCount = Number(response.totalCount);
}
}.bind(this))
},
onPage: function (pageNumber) {
this.vm.pageNumber = pageNumber;
this.onFind();
},
onSelectionChange: function (select) {
this.select = select;
},
onBitchDelete: function () {
if (this.select.length == 0) {
nav.w("至少选中一项");
} else {
this.$confirm('将删除已选择的项, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
for (var i = 0; i < this.select.length; i++) {
var obj = this.select[i];
ajax.dictDelete({id: obj.id}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
for (var j = 0; j < this.select.length; j++) {
if (this.select[j].id == obj.id) {
this.select.splice(j, 1);
}
}
if (this.select.length == 0) {
nav.s("删除成功")
this.onFind();
}
}
}.bind(this))
}
}.bind(this)).catch(function (action) {
});
}
},
onAction: function (arg) {
const action = arg[0];
const item = arg[1];
switch (action) {
case "create":
this.form.title = '新增字典';
this.form.id = '';
this.form.dictName = '';
this.form.dictCode = '';
this.form.version = '';
this.form.valid = true;
this.form.dialog = true;
break;
case "save":
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
ajax.dictUpdate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
} else {
ajax.dictCreate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
}
} else {
return false;
}
}.bind(this));
break;
case "view":
parent.index.addTab({
title: "字典项管理",
name: "dictItem" + item.id,
url: "${context}/system/dictItem.htm?dictId=" + item.id
});
break;
case "edit":
this.form.title = '编辑字典';
this.form.id = item.id;
this.form.dictName = item.dictName;
this.form.dictCode = item.dictCode;
this.form.version = item.version;
this.form.valid = item.valid;
this.form.rowVersion = item.rowVersion;
this.form.dialog = true;
break;
case "delete":
this.$confirm('将删除该项, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
ajax.dictDelete({id: item.id}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
nav.s("删除成功");
this.onFind();
}
}.bind(this));
}.bind(this));
break;
}
}
},
filters: {},
created: function () {
},
mounted: function () {
this.onFind();
},
watch: {}
})
</script>

@ -0,0 +1,339 @@
<div id="app" v-cloak>
<el-card class="box-card">
<el-form :inline="true" :model="vm" ref="vm" label-width="90px">
<el-form-item label="字典名称">
<el-input disabled v-model="vm.dictName" clearable size="small"></el-input>
</el-form-item>
<el-form-item label="字典键" prop="key">
<el-input v-model="vm.key" clearable size="small" placeholder=""></el-input>
</el-form-item>
<el-form-item label="字典值" prop="value">
<el-input v-model="vm.value" clearable size="small" placeholder=""></el-input>
</el-form-item>
<el-form-item label="是否有效" prop="valid">
<el-select v-model="vm.valid" size="small" placeholder="">
<el-option label="所有" value=""></el-option>
<el-option label="有效" value="true"></el-option>
<el-option label="无效" value="false"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" size="small" icon="el-icon-search" @click="onSearch">搜索</el-button>
<el-button type="warning" size="small" icon="el-icon-refresh-left" @click="onReset('vm')">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="box-card">
<el-row>
<el-col :span="12">
<el-button type="success" size="small" icon="el-icon-plus" @click="onAction(['create',''])">新增</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button>
<el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
<el-form :model="form":inline="true" :rules="formRules" ref="form" label-width="90px">
<el-form-item label="字典键" prop="dictName">
<el-input size="small" v-model="form.key"></el-input>
</el-form-item>
<el-form-item label="字典值" prop="dictCode">
<el-input size="small" v-model="form.value"></el-input>
</el-form-item>
<el-form-item label="排序值" prop="dictCode">
<el-input-number size="small" v-model="form.sort" :min="0" :max="10000"
label="描述文字"></el-input-number>
</el-form-item>
<el-form-item label="是否有效" prop="valid">
<el-switch size="small" v-model="form.valid"></el-switch>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="form.dialog = false">取消</el-button>
<el-button size="small" type="primary" @click="onAction(['save',''])">保存</el-button>
</span>
</el-dialog>
</el-col>
<el-col :span="12">
<el-button-group style="float: right;">
<el-button size="small" icon="el-icon-delete" @click="onBitchDelete"></el-button>
<el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
</el-button-group>
</el-col>
</el-row>
<el-table
@selection-change="onSelectionChange"
empty-text="无数据"
:data="result"
size="small"
style="width: 100%">
<el-table-column
align="center"
type="selection"
width="50">
</el-table-column>
<el-table-column
align="center"
prop="id"
label="主键"
width="140">
</el-table-column>
<el-table-column
align="center"
width="80"
label="是否有效">
<template slot-scope="scope">
<el-tag size="mini" v-if="scope.row.valid">有效</el-tag>
<el-tag size="mini" type="danger" v-if="!scope.row.valid">无效</el-tag>
</template>
</el-table-column>
<el-table-column
align="center"
prop="key"
label="字典键">
</el-table-column>
<el-table-column
align="center"
prop="value"
label="字典值">
</el-table-column>
<el-table-column
align="center"
prop="sort"
label="排序">
</el-table-column>
<el-table-column
align="center"
prop="createTime"
label="创建时间">
</el-table-column>
<el-table-column
align="center"
fixed="right"
width="120"
label="操作">
<template slot-scope="scope">
<el-dropdown size="mini" split-button type="primary" @click="onAction(['edit',scope.row])"
@command="onAction">
<i class="el-icon-edit"></i>编辑
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="['delete',scope.row]" icon="el-icon-delete">删除
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<el-pagination
v-if="vm.totalCount > vm.pageSize"
@current-change="onPage"
:current-page="vm.pageNumber"
:page-size="vm.pageSize"
layout="total, prev, pager, next, jumper"
:total="vm.totalCount">
</el-pagination>
</el-card>
</div>
<style>
#app {
padding: 10px;
}
.box-card {
margin: 10px;
}
.form .el-dialog{
width: 700px;
}
.form .el-dialog .el-form-item__content {
width: 220px;
}
</style>
<script>
var app = new Vue({
el: "#app",
data: {
vm: {
id: '',
dictId: location.getParam("dictId"),
dictName: '',
key: '',
value: '',
valid: '',
pageNumber: 1,
pageSize: 10,
totalCount: 0
},
select: [],
result: [],
form: {
title: "",
dialog: false,
id: '',
dictId: location.getParam("dictId"),
key: '',
value: '',
sort: 0,
valid: true
},
formRules: {
key: [
{required: true, message: '请输入字典名称', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur'}
],
value: [
{required: true, message: '请输入字典代码', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
],
},
},
methods: {
onSearch: function () {
this.vm.pageNumber = 1;
this.onFind();
},
onReset: function (form) {
this.$refs[form].resetFields();
nav.w('重置成功');
},
onFind: function () {
ajax.dictItemFind(this.vm).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.result = response.result;
this.vm.totalCount = Number(response.totalCount);
}
}.bind(this))
},
onPage: function (pageNumber) {
this.vm.pageNumber = pageNumber;
this.onFind();
},
onSelectionChange: function (select) {
this.select = select;
},
onBitchDelete: function () {
if (this.select.length == 0) {
nav.w("至少选中一项");
} else {
this.$confirm('将删除已选择的项, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
for (var i = 0; i < this.select.length; i++) {
var obj = this.select[i];
ajax.dictItemDelete({id: obj.id}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
for (var j = 0; j < this.select.length; j++) {
if (this.select[j].id == obj.id) {
this.select.splice(j, 1);
}
}
if (this.select.length == 0) {
nav.s("删除成功")
this.onFind();
}
}
}.bind(this))
}
}.bind(this)).catch(function (action) {
});
}
},
getDict: function () {
ajax.dictGet({id: location.getParam("dictId")}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.vm.dictName = response.dict.dictName;
}
}.bind(this))
},
onAction: function (arg) {
const action = arg[0];
const item = arg[1];
switch (action) {
case "create":
this.form.title = '新增字典项';
this.form.id = '';
this.form.key = '';
this.form.value = '';
this.form.sort = this.vm.totalCount;
this.form.valid = true;
this.form.dialog = true;
break;
case "save":
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
ajax.dictItemUpdate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
} else {
ajax.dictItemCreate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
}
} else {
return false;
}
}.bind(this));
break;
case "edit":
this.form.title = '编辑字典项';
this.form.id = item.id;
this.form.key = item.key;
this.form.value = item.value;
this.form.valid = item.valid;
this.form.sort = item.sort;
this.form.rowVersion = item.rowVersion;
this.form.dialog = true;
break;
case "delete":
this.$confirm('将删除该项, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
ajax.dictItemDelete({id: item.id}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
nav.s("删除成功")
this.onFind();
}
}.bind(this));
}.bind(this));
break;
}
}
},
filters: {},
created: function () {
},
mounted: function () {
this.getDict();
this.onFind();
},
watch: {}
})
</script>

@ -0,0 +1,381 @@
<div id="app" v-cloak>
<el-card class="box-card">
<el-form :inline="true" :model="vm" ref="vm" label-width="90px">
<el-form-item label="用户名" prop="name">
<el-input v-model="vm.name" clearable size="small" placeholder="请输入用户名"></el-input>
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input v-model="vm.age" clearable size="small" placeholder="请输入年龄"></el-input>
</el-form-item>
<el-form-item label="性别" prop="sex">
<el-input v-model="vm.sex" clearable size="small" placeholder="请输入性别"></el-input>
</el-form-item>
<el-form-item label="头像" prop="tx">
<el-input v-model="vm.tx" clearable size="small" placeholder="请输入头像"></el-input>
</el-form-item>
<el-form-item label="QQ" prop="qq">
<el-input v-model="vm.qq" clearable size="small" placeholder="请输入QQ"></el-input>
</el-form-item>
<el-form-item label="微信、" prop="wx">
<el-input v-model="vm.wx" clearable size="small" placeholder="请输入微信、"></el-input>
</el-form-item>
<el-form-item label="微博" prop="wb">
<el-input v-model="vm.wb" clearable size="small" placeholder="请输入微博"></el-input>
</el-form-item>
<el-form-item label="个人主页" prop="personPage">
<el-input v-model="vm.personPage" clearable size="small" placeholder="请输入个人主页"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" size="small" icon="el-icon-search" @click="onSearch">搜索</el-button>
<el-button type="warning" size="small" icon="el-icon-refresh-left" @click="onReset('vm')">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="box-card">
<el-row>
<el-col :span="12">
<el-button type="success" size="small" icon="el-icon-plus" @click="onAction(['create',''])">新增
</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button>
<el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px">
<el-form-item label="用户名" prop="name">
<el-input v-model="form.name" clearable size="small" placeholder="请输入用户名"></el-input>
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input v-model="form.age" clearable size="small" placeholder="请输入年龄"></el-input>
</el-form-item>
<el-form-item label="性别" prop="sex">
<el-input v-model="form.sex" clearable size="small" placeholder="请输入性别"></el-input>
</el-form-item>
<el-form-item label="头像" prop="tx">
<el-input v-model="form.tx" clearable size="small" placeholder="请输入头像"></el-input>
</el-form-item>
<el-form-item label="QQ" prop="qq">
<el-input v-model="form.qq" clearable size="small" placeholder="请输入QQ"></el-input>
</el-form-item>
<el-form-item label="微信、" prop="wx">
<el-input v-model="form.wx" clearable size="small" placeholder="请输入微信、"></el-input>
</el-form-item>
<el-form-item label="微博" prop="wb">
<el-input v-model="form.wb" clearable size="small" placeholder="请输入微博"></el-input>
</el-form-item>
<el-form-item label="个人主页" prop="personPage">
<el-input v-model="form.personPage" clearable size="small" placeholder="请输入个人主页"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="form.dialog = false">取 消</el-button>
<el-button size="small" type="primary" @click="onAction(['save',''])">保存</el-button>
</span>
</el-dialog>
</el-col>
<el-col :span="12">
<el-button-group style="float: right;">
<el-button size="small" icon="el-icon-delete" @click="onBitchDelete"></el-button>
<el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
</el-button-group>
</el-col>
</el-row>
<el-table
style="margin-top: 10px"
@selection-change="onSelectionChange"
empty-text="无数据"
:data="result"
size="mini"
style="width: 100%">
<el-table-column
align="center"
type="selection"
width="40">
</el-table-column>
<el-table-column
align="center"
prop="name"
label="用户名">
</el-table-column>
<el-table-column
align="center"
prop="age"
label="年龄">
</el-table-column>
<el-table-column
align="center"
prop="sex"
label="性别">
</el-table-column>
<el-table-column
align="center"
prop="tx"
label="头像">
</el-table-column>
<el-table-column
align="center"
prop="qq"
label="QQ">
</el-table-column>
<el-table-column
align="center"
prop="wx"
label="微信、">
</el-table-column>
<el-table-column
align="center"
prop="wb"
label="微博">
</el-table-column>
<el-table-column
align="center"
prop="personPage"
label="个人主页">
</el-table-column>
<el-table-column
align="center"
prop="createTime"
width="140"
label="创建时间">
</el-table-column>
<el-table-column
align="center"
fixed="right"
width="120"
label="操作">
<template slot-scope="scope">
<el-dropdown size="mini" split-button type="primary" @click="onAction(['edit',scope.row])"
@command="onAction">
<i class="el-icon-edit"></i>编辑
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="['delete',scope.row]" icon="el-icon-delete">删除
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<el-pagination
style="margin-top: 10px"
v-if="vm.totalCount > vm.pageSize"
@current-change="onPage"
:current-page="vm.pageNumber"
:page-size="vm.pageSize"
layout="total, prev, pager, next, jumper"
:total="vm.totalCount">
</el-pagination>
</el-card>
</div>
<style>
#app {
padding: 10px;
}
.box-card {
margin: 10px;
}
.form .el-dialog{
width: 700px;
}
.form .el-dialog .el-form-item__content {
width: 220px;
}
</style>
<script>
var app = new Vue({
el: "#app",
data: {
vm: {//条件及分页参数
name: "",
age: "",
sex: "",
tx: "",
qq: "",
wx: "",
wb: "",
personPage: "",
pageNumber: 1,
pageSize: 10,
totalCount: 0
},
form: {//待提交表单
title: "",
dialog: false,
id: '',
name: "",
age: "",
sex: "",
tx: "",
qq: "",
wx: "",
wb: "",
personPage: "",
rowVersion: ""
},
formRules: {
name: [
{min: 1, max: 10, message: '用户名长度在 1 到 10 个字符', trigger: 'blur'}
],
age: [
{min: 1, max: 50, message: '年龄长度在 1 到 50 个字符', trigger: 'blur'}
],
sex: [
{min: 1, max: 50, message: '性别长度在 1 到 50 个字符', trigger: 'blur'}
],
tx: [
{min: 1, max: 50, message: '头像长度在 1 到 50 个字符', trigger: 'blur'}
],
qq: [
{min: 1, max: 50, message: 'QQ长度在 1 到 50 个字符', trigger: 'blur'}
],
wx: [
{min: 1, max: 50, message: '微信、长度在 1 到 50 个字符', trigger: 'blur'}
],
wb: [
{min: 1, max: 50, message: '微博长度在 1 到 50 个字符', trigger: 'blur'}
],
personPage: [
{min: 1, max: 50, message: '个人主页长度在 1 到 50 个字符', trigger: 'blur'}
],
},
select: [],
result: [],
},
methods: {
onSearch: function () {
this.vm.pageNumber = 1;
this.onFind();
},
onReset: function (form) {
this.$refs[form].resetFields();
nav.w('重置成功');
},
onFind: function () {
ajax.user1Find(this.vm).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.result = response.result;
this.vm.totalCount = Number(response.totalCount);
}
}.bind(this))
},
onPage: function (pageNumber) {
this.vm.pageNumber = pageNumber;
this.onFind();
},
onBitchDelete: function () {
if (this.select.length === 0) {
nav.e("尚未选择数据列");
return;
}
this.$confirm('将删除所有选中项, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
this.select.forEach(function (item) {
ajax.user1Delete({id: item.id}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.select.remove(item);
if (this.select.length===0){
nav.s("删除成功");
this.onFind();
}
}
}.bind(this))
}.bind(this))
}.bind(this)).catch(function (action) {
});
},
onSelectionChange: function (select) {
this.select = select;
},
onAction: function (arg) {
const action = arg[0];
const item = arg[1];
switch (action) {
case "create":
this.form.title = "用户1新增";
this.form.dialog = true;
this.form.id = "";
this.form.name = "";
this.form.age = "";
this.form.sex = "";
this.form.tx = "";
this.form.qq = "";
this.form.wx = "";
this.form.wb = "";
this.form.personPage = "";
break;
case "save":
if (this.form.id) {
ajax.user1Update(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
} else {
ajax.user1Create(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
}
break;
case "edit":
this.form.title = "用户1编辑";
this.form.dialog = true;
this.form.id = item.id;
this.form.name = item.name;
this.form.age = item.age;
this.form.sex = item.sex;
this.form.tx = item.tx;
this.form.qq = item.qq;
this.form.wx = item.wx;
this.form.wb = item.wb;
this.form.personPage = item.personPage;
this.form.rowVersion = item.rowVersion;
break;
case "delete":
this.$confirm('将删除该项, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
ajax.user1Delete({id: item.id}).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
nav.s("删除成功")
this.onFind();
}
}.bind(this))
}.bind(this)).catch(function (action) {
});
break;
}
},
},
created: function () {
},
mounted: function () {
this.onFind();
},
watch: {}
})
</script>
Loading…
Cancel
Save

Powered by TurnKey Linux.