wangbing 6 years ago
parent be805155e1
commit 447b3a2450

@ -0,0 +1,187 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/>
</parent>
<groupId>xyz.wbsite</groupId>
<artifactId>FILEMGR-WEB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<!--<packaging>war</packaging>--><!--需要打包成war时放开-->
<name>FILEMGR-WEB</name>
<description>project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
<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>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</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>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</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>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>${artifactId}-${version}</finalName>
<!-- 默认的主代码目录 -->
<sourceDirectory>src/main/java</sourceDirectory>
<!-- 默认的测试代码目录 -->
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- 包含java下的xml文件 -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/mpr/*.xml</include>
</includes>
</resource>
<!-- 包含lib中所有jar包 -->
<resource>
<directory>${basedir}/src/main/resources/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
<!-- 启动bat -->
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>*.bat</include>
</includes>
<targetPath>${basedir}/target</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/src/main/resources/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/src/main/resources/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>

@ -0,0 +1,22 @@
package xyz.wbsite;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

@ -0,0 +1,169 @@
package xyz.wbsite.action;
import xyz.wbsite.framework.utils.LogUtil;
import xyz.wbsite.framework.base.FileUploadResponse;
import xyz.wbsite.framework.base.BaseResponse;
import xyz.wbsite.framework.base.ErrorType;
import xyz.wbsite.framework.base.Screen;
import xyz.wbsite.framework.utils.LocalData;
import xyz.wbsite.framework.config.BeanDefinitionRegistryConfig;
import org.springframework.beans.BeansException;
import org.apache.commons.io.FileUtils;
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.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
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 java.util.ArrayList;
import org.springframework.beans.factory.annotation.Value;
@Controller
@ControllerAdvice
public class GlobalController implements ErrorController {
@Value("${web.welcome.page}")
private String homePage;
/**
*
*
* @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);
}
}
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) {
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
switch (statusCode) {
case 404:
return "404";
case 403:
return "403";
case 500:
return "500";
default:
return "403";
}
}
/**
* layoutscreen
* 使layoutViewNameTranslator
* @param model
* @param request
*/
@RequestMapping("/**")
public void hold(HttpServletRequest request, Model model) {
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
// 处理根Url
String servletPath = request.getServletPath();
if ("/".equals(servletPath)) {
servletPath = "/" + homePage;
}
LocalData.setTarget(servletPath);
// 尝试执行Target Screen执行器(服务器渲染),不存在则直接返回视图模板(Ajax渲染)
Screen screenExec = null;
try {
servletPath = servletPath.replaceAll("/", ".").toLowerCase();
screenExec = LocalData.getApplicationContext().getBean(BeanDefinitionRegistryConfig.SCREEN_PREFIX + servletPath, Screen.class);
screenExec.exec(model, request, response);
} catch (BeansException e) {
}
//todo 可在此获取共性数据(也可以在全局拦截器GlobalHandlerInterceptor、拦截器作用域比此更高)
//todo 例如用户信息等。其他业务数据在页面渲染后通过Ajax请求
}
@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("/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);
headers.setContentDispositionFormData("attachment", file);
//========
//下载DEMO
//========
if (file == null) {
file = "test.txt";
headers.setContentDispositionFormData("attachment", file);
return new ResponseEntity<byte[]>("test".getBytes(),
headers, HttpStatus.CREATED);
}
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(file)),
headers, HttpStatus.CREATED);
}
}

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

@ -0,0 +1,15 @@
package xyz.wbsite.action.control;
import xyz.wbsite.framework.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.action.screen;
import xyz.wbsite.framework.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,98 @@
package xyz.wbsite.framework.base;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Date;
/**
* Base -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseEntity {
/**
*
*/
private long rowVersion;
/**
*
*/
@JsonIgnore
private long createBy;
/**
*
*/
@JsonIgnore
private Date createTime;
/**
*
*/
@JsonIgnore
private long lastUpdateBy;
/**
*
*/
@JsonIgnore
private Date lastUpdateTime;
/**
*
*/
@JsonIgnore
private boolean isDeleted;
public boolean getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}
public long getRowVersion() {
return rowVersion;
}
public void setRowVersion(long rowVersion) {
this.rowVersion = rowVersion;
}
public long getCreateBy() {
return createBy;
}
public void setCreateBy(long createBy) {
this.createBy = createBy;
}
public long getLastUpdateBy() {
return lastUpdateBy;
}
public void setLastUpdateBy(long lastUpdateBy) {
this.lastUpdateBy = lastUpdateBy;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
}

@ -0,0 +1,57 @@
package xyz.wbsite.framework.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;
private int beginIndex = 0;
private int endIndex = 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;
}
public int getBeginIndex() {
beginIndex = pageSize * (pageNumber - 1);
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public int getEndIndex() {
endIndex = pageSize * (pageNumber - 1) + pageSize;
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public void updatePageNumber(int totalCount){
int maxPage = totalCount / pageSize + (totalCount % pageSize > 0 ? 1 : 0);
if (pageNumber > maxPage){
pageNumber = maxPage;
}
}
}

@ -0,0 +1,33 @@
package xyz.wbsite.framework.base;
import java.util.List;
/**
* BaseFindResponse -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseFindResponse<T> extends BaseResponse{
private List<T> result;
private Long totalCount;
public List<T> getResult() {
return result;
}
public void setResult(List<T> result) {
this.result = result;
}
public Long getTotalCount() {
return totalCount;
}
public void setTotalCount(Long totalCount) {
this.totalCount = totalCount;
}
}

@ -0,0 +1,32 @@
package xyz.wbsite.framework.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;
}
}

@ -0,0 +1,12 @@
package xyz.wbsite.framework.base;
/**
* BaseRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseRequest {
}

@ -0,0 +1,38 @@
package xyz.wbsite.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);
}
}

@ -0,0 +1,24 @@
package xyz.wbsite.framework.base;
/**
* BaseSearchRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseSearchRequest extends BaseFindRequest {
/**
*
*/
private String keyword;
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}

@ -0,0 +1,24 @@
package xyz.wbsite.framework.base;
/**
* BaseUpdateRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class BaseUpdateRequest extends BaseRequest{
/**
*
*/
private long rowVersion;
public long getRowVersion() {
return rowVersion;
}
public void setRowVersion(long rowVersion) {
this.rowVersion = rowVersion;
}
}

@ -0,0 +1,10 @@
package xyz.wbsite.framework.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);
}

@ -0,0 +1,41 @@
package xyz.wbsite.framework.base;
/**
* Error -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class Error {
/*错误类型*/
private ErrorType type;
/*错误内容*/
private String message;
public Error() {
}
public Error(ErrorType type, String message) {
this.type = type;
this.message = message;
}
public ErrorType getType() {
return type;
}
public void setType(ErrorType type) {
this.type = type;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,17 @@
package xyz.wbsite.framework.base;
/**
* ErrorType -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public enum ErrorType {
BUSINESS_ERROR,
SYSTEM_ERROR,
UNKNOWN_ERROR,
UNIQUENESS_ERROR,
EXPECTATION_NULL,
INVALID_PARAMETER
}

@ -0,0 +1,34 @@
package xyz.wbsite.framework.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.framework.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);
}

@ -0,0 +1,17 @@
package xyz.wbsite.framework.base;
/**
* SortTypeEnum -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public enum SortType {
//升序
ASC,
//降序
DESC
}

@ -0,0 +1,74 @@
package xyz.wbsite.framework.base;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/**
* Token -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class Token implements Serializable {
private static final Long serialVersionUID = 1L;
/** ID */
private long id;
/** 用户ID */
private long userId;
/** 用户名称 */
private String userName;
private Set<String> resourceSet = new HashSet<>();
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean hasResource(String 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,80 @@
package xyz.wbsite.framework.config;
import xyz.wbsite.framework.base.Control;
import xyz.wbsite.framework.base.Screen;
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 java.io.IOException;
@Configuration
public class BeanDefinitionRegistryConfig implements BeanDefinitionRegistryPostProcessor {
public static final String SCREEN_PREFIX = "screen";
public static final String CONTROL_PREFIX = "control";
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
String aPackage = this.getClass().getPackage().getName();
int i = registryScreen(aPackage.replaceAll("framework.config", "action.screen"), beanDefinitionRegistry);
int i1 = registryControl(aPackage.replaceAll("framework.config", "action.control"), beanDefinitionRegistry);
System.out.println();
}
@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 s = beanClassName.replaceAll(basePackage, SCREEN_PREFIX);
return s.toLowerCase();
}
});
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 s = beanClassName.replaceAll(basePackage, CONTROL_PREFIX);
return s.toLowerCase();
}
});
return classPathBeanDefinitionScanner.scan(basePackage);
}
}

@ -0,0 +1,90 @@
package xyz.wbsite.framework.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.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.Authentication;
import xyz.wbsite.framework.base.Token;
import xyz.wbsite.framework.utils.CookieUtil;
import xyz.wbsite.framework.utils.LocalData;
import javax.servlet.http.HttpServletRequest;
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${web.url.auth.excluded}")
private String[] excluded;
@Value("${web.url.auth.included}")
private String[] included;
@Value("${web.url.login}")
private String login;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers(excluded).permitAll()
.antMatchers(included).access("@Authorization.hasPermission(request,authentication)")
.and().cors()
.and().headers().frameOptions().disable()
.and().csrf().disable();
}
/**
*
*
* Using generated security password: f6b42a66-71b1-4c31-b6a8-942838c81408
*
* @return
* @throws Exception
*/
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean("Authorization")
public Object getAuthorization() {
return new Object() {
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
// 获取Token
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("/admin/.*");
LocalData.setToken(token1);
}
// 授权
Token token_ = LocalData.getToken();
if (token_.hasResource(request.getServletPath())) {
return true;
}
return false;
}
};
}
}

@ -0,0 +1,38 @@
package xyz.wbsite.framework.config;
import xyz.wbsite.framework.utils.LogUtil;
import xyz.wbsite.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 java.util.concurrent.Executors;
/**
* Task,Task
* :@Profile("dev") () @Profile("prod")()
*/
@Configuration
@EnableScheduling
@Profile("prod")
public class TaskConfig implements SchedulingConfigurer {
@Scheduled(cron="0/30 * * * * ? ")
public void task(){
LogUtil.i("--------------------Task--------------------");
}
/**
* Spring Schedule 线
* 线 SchedulingConfigurerconfigureTasks
*
* @param scheduledTaskRegistrar
*/
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.setScheduler(Executors.newScheduledThreadPool(3));
}
}

@ -0,0 +1,56 @@
package xyz.wbsite.framework.config;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.lang.reflect.Method;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@EnableAsync
public class ThreadPoolConfig implements AsyncConfigurer {
private ThreadPoolTaskExecutor executor;
private int corePoolSize = 10;//线程池维护线程的最少数量
private int maxPoolSize = 30;//线程池维护线程的最大数量
private int queueCapacity = 8; //缓存队列
private int keepAlive = 60;//允许的空闲时间
@Nullable
@Override
public Executor getAsyncExecutor() {
executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("mqExecutor-");
// rejection-policy当pool已经达到max size的时候如何处理新任务
// CALLER_RUNS不在新线程中执行任务而是由调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //对拒绝task的处理策略
executor.setKeepAliveSeconds(keepAlive);
executor.initialize();
return executor;
}
@Nullable
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new AsyncUncaughtExceptionHandler() {
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
System.out.println("-------------》》》捕获线程异常信息");
}
};
}
}

@ -0,0 +1,132 @@
package xyz.wbsite.framework.config;
import xyz.wbsite.framework.springmvc.GlobalHandlerInterceptor;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource;
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.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import xyz.wbsite.framework.springmvc.GlobalHandlerInterceptor;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//将资源Order设为 -1 权重大于 Mapping保证资源优先级高于Mapping("**")
registry.setOrder(-1);
}
@Autowired
private GlobalHandlerInterceptor globalHandlerInterceptor;
/**
*
*
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(globalHandlerInterceptor).addPathPatterns("/**").excludePathPatterns("/static/**");
}
/**
* Jackson
*
* 1LonglongStringjavascriptNumber
*
* @param converters
*/
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = jackson2HttpMessageConverter.getObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
// 将转化器注册到首个
converters.add(0, jackson2HttpMessageConverter);
}
// @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;
// }
}

@ -0,0 +1,105 @@
package xyz.wbsite.framework.freemarker;
import java.io.File;
import xyz.wbsite.framework.config.BeanDefinitionRegistryConfig;
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.stereotype.Component;
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.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
import xyz.wbsite.framework.base.Control;
import xyz.wbsite.framework.utils.LocalData;
/**
*
*
* @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;
}
if (servletPath.startsWith("/")) {
servletPath = servletPath.substring(1);
}
// 去除头部/
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 screenPrefix + servletPath + suffix;
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public String setControl(String control) {
// 查找是否存在对应控制面板执行器
Control controlExec = null;
try {
controlExec = LocalData.getApplicationContext().getBean(BeanDefinitionRegistryConfig.CONTROL_PREFIX + "." + control, 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 controlPrefix + control + suffix;
}
}

@ -0,0 +1,41 @@
package xyz.wbsite.framework.freemarker;
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
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Component
public class Uri {
public String getUrl(String path) throws TemplateModelException {
if (path == null) {
return "";
}
if (!path.startsWith("/")) {
return "/" + path;
}
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// 协议
String scheme = request.getScheme();
// 域名
String serverName = request.getServerName();
// 端口
int serverPort = request.getServerPort();
// 上下文路径
String contextPath = request.getContextPath();
return String.format(Locale.CHINA, "%s://%s:%d%s%s", scheme, serverName, serverPort, contextPath, path);
}
}

@ -0,0 +1,120 @@
package xyz.wbsite.framework.freemarker;
import xyz.wbsite.framework.utils.LogUtil;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
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.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Locale;
import java.util.Map;
/**
* FreemarkerViewName
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Component("viewNameTranslator")
public class ViewNameTranslator extends DefaultRequestToViewNameTranslator {
@Value("${web.welcome.page}")
private String homePage;
@Autowired
private FreeMarkerViewResolver viewResolver;
@Autowired
private Layout layout;
@Autowired
private Uri uri;
@PostConstruct
public void setSharedVariable() {
//设置基本工具类
Map<String, Object> attributesMap = viewResolver.getAttributesMap();
attributesMap.put("Layout", layout);
attributesMap.put("Uri", uri);
}
@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 = homePage;
} else {
servletPath = servletPath.replaceAll("^/", "");
}
Locale locale = localeResolver.resolveLocale(request);
{//查询View
String[] split = servletPath.split("/");
StringBuilder sb = new StringBuilder("");
sb.append("screen");
for (int i = 0; i < split.length; i++) {
sb.append(File.separator);
sb.append(split[i]);
}
viewName = sb.toString();
View view = viewResolver.resolveViewName(viewName, locale);
if (view == null) {
LogUtil.e("can not find screen.");
return "404";
}
}
{//查找layout
String[] split = servletPath.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]);
}
viewName = sb.toString() + File.separator + split[split.length - 1];
View view = viewResolver.resolveViewName(viewName, locale);
//无法找到对应layout使用默认layout
if (view == null) {
viewName = sb.toString() + File.separator + "default";
View defaultView = viewResolver.resolveViewName(viewName, 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) {
e.printStackTrace();
}
return viewName;
}
}

@ -0,0 +1,65 @@
package xyz.wbsite.framework.springmvc;
import xyz.wbsite.framework.utils.LocalData;
import xyz.wbsite.framework.base.Token;
import xyz.wbsite.framework.utils.LogUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* SpringMVC
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
@Component
public class GlobalHandlerInterceptor extends HandlerInterceptorAdapter {
@Value("${web.welcome.page}")
private String homePage;
@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);
//主页
modelAndView.addObject("homePath", homePage);
//获取项目路径,在项目非根路径下用于拼接URL
String contextPath = request.getContextPath();
modelAndView.addObject("contextPath", contextPath);
}
@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);
}
}
@Override
public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
super.afterConcurrentHandlingStarted(request, response, handler);
}
}

@ -0,0 +1,122 @@
package xyz.wbsite.framework.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;
}
public static void main(String[] args) {
// 加密
String data = "我有一个苹果";
String secret = "1234567890123456";
System.out.println("加密后的Base64密文是:" + AESUtil.encrypt2Base64(data.getBytes(), secret));
// 解密
String encrypt2Base64 = AESUtil.encrypt2Base64(data.getBytes(), secret);
byte[] decrypt = AESUtil.decrypt(Base64Util.decode(encrypt2Base64), secret);
System.out.println("解密后的明文是:" + new String(decrypt));
}
}

@ -0,0 +1,506 @@
package xyz.wbsite.framework.utils;
import java.util.Arrays;
/**
* Base64Util
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class Base64Util {
private static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static final int[] IA = new int[256];
static {
Arrays.fill(IA, -1);
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)
return new char[0];
int eLen = (sLen / 3) * 3; // Length of even 24-bits.
int cCnt = ((sLen - 1) / 3 + 1) << 2; // Returned character count
int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
char[] dArr = new char[dLen];
// Encode even 24-bits
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);
// Encode the int into four chars
dArr[d++] = CA[(i >>> 18) & 0x3f];
dArr[d++] = CA[(i >>> 12) & 0x3f];
dArr[d++] = CA[(i >>> 6) & 0x3f];
dArr[d++] = CA[i & 0x3f];
// Add optional line separator
if (lineSep && ++cc == 19 && d < dLen - 2) {
dArr[d++] = '\r';
dArr[d++] = '\n';
cc = 0;
}
}
// Pad and encode last bits if source isn't even 24 bits.
int left = sLen - eLen; // 0 - 2.
if (left > 0) {
// Prepare the int
int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
// Set last four chars
dArr[dLen - 4] = CA[i >> 12];
dArr[dLen - 3] = CA[(i >>> 6) & 0x3f];
dArr[dLen - 2] = left == 2 ? CA[i & 0x3f] : '=';
dArr[dLen - 1] = '=';
}
return dArr;
}
/**
* Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045.
*
* @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 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));
}
/**
* Encodes a raw byte array into a BASE64 <code>byte[]</code> representation i accordance with RFC 2045.
*
* @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[] encodeToByte(byte[] sArr, boolean lineSep) {
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if (sLen == 0)
return new byte[0];
int eLen = (sLen / 3) * 3; // Length of even 24-bits.
int cCnt = ((sLen - 1) / 3 + 1) << 2; // Returned character count
int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
byte[] dArr = new byte[dLen];
// Encode even 24-bits
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);
// Encode the int into four chars
dArr[d++] = (byte) CA[(i >>> 18) & 0x3f];
dArr[d++] = (byte) CA[(i >>> 12) & 0x3f];
dArr[d++] = (byte) CA[(i >>> 6) & 0x3f];
dArr[d++] = (byte) CA[i & 0x3f];
// Add optional line separator
if (lineSep && ++cc == 19 && d < dLen - 2) {
dArr[d++] = '\r';
dArr[d++] = '\n';
cc = 0;
}
}
// Pad and encode last bits if source isn't an even 24 bits.
int left = sLen - eLen; // 0 - 2.
if (left > 0) {
// Prepare the int
int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
// Set last four chars
dArr[dLen - 4] = (byte) CA[i >> 12];
dArr[dLen - 3] = (byte) CA[(i >>> 6) & 0x3f];
dArr[dLen - 2] = left == 2 ? (byte) CA[i & 0x3f] : (byte) '=';
dArr[dLen - 1] = '=';
}
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.
*
* @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. Will be <code>null</code> if the legal characters
* (including '=') isn't divideable by 4. (I.e. definitely corrupted).
*/
public final static byte[] decode(byte[] sArr) {
// Check special case
int sLen = sArr.length;
// 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)
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] & 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; ) {
// 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++] & 0xff];
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 that is known to be resonably well formatted. The method is about twice as
* 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>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
*
* @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 byte[] decodeFast(byte[] 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] & 0xff] < 0)
sIx++;
// Trim illegal chars from end
while (eIx > 0 && IA[sArr[eIx] & 0xff] < 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;
}
/**
* 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 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 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;
}
/**
* Decodes a BASE64 encoded <code>String</code>. All illegal characters will be ignored and can handle both strings with
* and without line separators.<br>
* <b>Note!</b> It can be up to about 2x the speed to call <code>decode(str.toCharArray())</code> instead. That
* will create a temporary array though. This version will use <code>str.charAt(i)</code> to iterate the string.
*
* @param str The source string. <code>null</code> or length 0 will return an empty array.
* @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters
* (including '=') isn't divideable by 4. (I.e. definitely corrupted).
*/
public final static byte[] decode(String str) {
// Check special case
int sLen = str != null ? str.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[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)
return null;
// Count '=' at end
int pad = 0;
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; ) {
// 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[str.charAt(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 string that is known to be resonably well formatted. The method is about twice as
* 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 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 str) {
// Check special case
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[str.charAt(sIx) & 0xff] < 0)
sIx++;
// Trim illegal chars from end
while (eIx > 0 && IA[str.charAt(eIx) & 0xff] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
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 ? (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; ) {
// Assemble three bytes into an int from four "valid" characters.
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);
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[str.charAt(sIx++)] << (18 - j * 6);
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(("我搜搜").getBytes());
System.out.println(s);
byte[] decode = Base64Util.decode(s);
System.out.println(new String(decode));
}
}

@ -0,0 +1,34 @@
package xyz.wbsite.framework.utils;
import javax.servlet.http.Cookie;
/**
* 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;
}
}

@ -0,0 +1,80 @@
package xyz.wbsite.framework.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* IDgenerator - ID
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class IDgenerator {
private static long workerId = 1L;
private static long datacenterId = 1L;
private static long sequence = 0L;
// 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
private static long twepoch = 1531130104852L;
// 机器标识位数
private static long workerIdBits = 2L;//分布应用可设置为5这里减少占位增加可支持时间
// 数据中心标识位数
private static long datacenterIdBits = 2L;//分布应用可设置为5这里减少占位增加可支持时间
// 机器ID最大值
private static long maxWorkerId = -1L ^ (-1L << workerIdBits);
// 数据中心ID最大值
private static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
// 毫秒内自增位
private static long sequenceBits = 12L;
// 机器ID偏左移12位
private static long workerIdShift = sequenceBits;
// 数据中心ID左移17位
private static long datacenterIdShift = sequenceBits + workerIdBits;
// 时间毫秒左移22位
private static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
private static long sequenceMask = -1L ^ (-1L << sequenceBits);
// 上次生产id时间戳
private static long lastTimestamp = -1L;
public static synchronized long nextId() {
long timestamp = timeGen();
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0L;
}
lastTimestamp = timestamp;
return ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift) | (workerId << workerIdShift) | sequence;
}
protected static long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
protected static long timeGen() {
return System.currentTimeMillis();
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
long l = IDgenerator.nextId();
System.out.println(l);
}
}
}

@ -0,0 +1,86 @@
package xyz.wbsite.framework.utils;
import xyz.wbsite.framework.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 final long serialVersionUID = 1L;
private static Token temp = null;
private static Token system = null;
static {
temp = new Token();
temp.setId(-1);
temp.setUserId(-1);
temp.setUserName("游客");
temp.putResource("/ajax");
temp.putResource("/upload");
temp.putResource("ajax.example.example");
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> targetHolder = new ThreadLocal();
public static String getTarget() {
return targetHolder.get();
}
public static void setTarget(String target) {
targetHolder.set(target);
}
/**
*
*/
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,70 @@
package xyz.wbsite.framework.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* LogUtil -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class LogUtil {
//定义一个全局的记录器通过LoggerFactory获取
private final static Logger logger = LoggerFactory.getLogger(LogUtil.class);
/**
* info
* @param context
*/
public static void i(String context){
logger.info(context);
}
/**
* debug
* @param context
*/
public static void d(String context){
logger.debug(context);
}
/**
* warn
* @param context
*/
public static void w(String context){
logger.warn(context);
}
/**
* error
* @param context
*/
public static void e(String context){
logger.error(context);
}
/**
*
*/
public static void dumpException(Throwable e){
StringBuffer msg = new StringBuffer("null");
if (e != null) {
msg = new StringBuffer("");
String message = e.toString();
int length = e.getStackTrace().length;
if (length > 0) {
msg.append(message).append("\n");
for (int i = 0; i < length; i++) {
msg.append("\t").append(e.getStackTrace()[i]).append("\n");
}
} else {
msg.append(message);
}
}
logger.error(msg.toString());
}
}

@ -0,0 +1,87 @@
package xyz.wbsite.framework.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();
}
/**
*
*
* @param args
*/
public static void main(String[] args) {
// String encode = MD5Util.encode("123456");
// System.out.println(encode);
//
// UserCreateRequest user = new UserCreateRequest();
// user.setUser("wangbing");
//
//
// ArrayList<User> users = new ArrayList<>();
// User user1 = new User();
// user1.setUser("ddd");
// users.add(user1);
// user.setList(users);
//
// TreeNode treeNode = MapperUtil.toTree(user);
// String s = MapperUtil.toJson(user,true);
// System.out.println(s);
//
// String s1 = MD5Util.toSign(treeNode, "asasasdadasda", "wwwwwwwwwwwwwwww");
//
// System.out.println(s1);
}
}

@ -0,0 +1,133 @@
package xyz.wbsite.framework.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.*;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* MapUtil -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class MapperUtil {
private static ObjectMapper om;
private static Mapper mapper;
static {
//初始化
om = new ObjectMapper();
//序列化时忽略null属性
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) {
try {
return om.readTree(json);
} catch (IOException e) {
e.printStackTrace();
return om.createObjectNode();
}
}
public static TreeNode toTree(Object json) {
return om.valueToTree(json);
}
public static String toJson(Object object) {
return toJson(object, false);
}
public static String toJson(Object object, boolean pretty) {
try {
if (pretty) {
return om.writerWithDefaultPrettyPrinter().writeValueAsString(object);
} else {
return om.writeValueAsString(object);
}
} catch (JsonProcessingException e) {
e.printStackTrace();
return "{}";
}
}
public static String toJson(JsonNode jsonNode) {
return jsonNode.asText();
}
public static <T> T toJava(String json, Class<T> cls) {
try {
if (json == null || "".equals(json)) {
return cls.newInstance();
}
return om.readValue(json, cls);
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return null;
}
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 valueTypeRef) {
try {
return om.readValue(json, valueTypeRef);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static <T> List<T> toJavaList(String json, TypeReference<List<T>> reference) {
try {
return om.readValue(json, reference);
} catch (IOException e) {
e.printStackTrace();
}
return 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 <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);
}
}

@ -0,0 +1,21 @@
package xyz.wbsite.framework.utils;
/**
* Message -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class Message {
public static final String ERROR_500 = "服务器走了下神,稍后再试一次";
public static final String NOT_EXIST_METHOD = "调用的方法不存在";
public static String CREATE_FAILURE = "创建失败,请刷新后重新尝试";
public static String DELETE_FAILURE = "删除失败,请刷新后重新尝试";
public static String UPDATE_FAILURE = "更新失败,请刷新后重新尝试";
public static String FIND_FAILURE = "查询失败,请刷新后重新尝试";
public static String GET_FAILURE = "未获取相应内容";
public static String INSERT_DUPLICATE = "已经存在相同数据,返回列表页面确认";
}

@ -0,0 +1,135 @@
package xyz.wbsite.framework.utils;
import java.awt.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class ProcessUtil {
/**
* windowsexe
* @param path exe
*/
public static void execExe(String path) {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec(path);
} catch (Exception e) {
System.out.println("Error exec!");
}
}
/**
* windows
* @param path
*/
public static void execBat(String path) {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec(path);
} catch (Exception e) {
System.out.println("Error exec!");
}
}
/**
* windows cmd
* @param command cmd
*/
public static String execCmd(String command) {
return exec("cmd /c " + command);
}
/**
*
* @param command cmd
*/
public static String exec(String command) {
StringBuilder build = new StringBuilder();
Runtime runtime = Runtime.getRuntime();
Process process = null;
try {
process = runtime.exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
String line = null;
while ((line = br.readLine()) != null) {
build.append(line);
}
process.destroy();
} catch (IOException e) {
e.printStackTrace();
}
return build.toString();
}
/**
* @throws IOException
* @desc
* @author zp
* @date 2018-3-29
*/
public static void killProc(String processName) throws IOException {
if (processName != null && !"".equals(processName)) {
execCmd("taskkill /F /IM " + processName);
}
}
/**
* @desc
* @author zp
* @date 2018-3-29
*/
public static boolean findProcess(String processName) {
BufferedReader bufferedReader = null;
try {
Process proc = Runtime.getRuntime().exec("tasklist -fi " + '"' + "imagename eq " + processName + '"');
bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains(processName)) {
return true;
}
}
return false;
} catch (Exception ex) {
ex.printStackTrace();
return false;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception ex) {
}
}
}
}
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,330 @@
package xyz.wbsite.framework.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, 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 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;
}
/**
*
*
* @param args
*/
public static void main(String[] args) {
{//创建秘钥对
RSAUtil.createKey();
}
{//加解密
//加密
String encrypt = RSAUtil.encrypt2Base64("我有一个苹果".getBytes());
System.out.println(encrypt);
//解密
String decrypt = RSAUtil.decrypt2String(encrypt);
System.out.println(decrypt);
}
String sign = sign2Base64("我有一个苹果".getBytes(), signPrivateKeyBase64);
System.out.println(sign);
boolean b = doCheck("我有一个苹果".getBytes(), sign, signPublicKeyBase64);
System.out.println(b);
}
}

@ -0,0 +1,54 @@
package xyz.wbsite.framework.utils;
import xyz.wbsite.framework.base.BaseRequest;
import xyz.wbsite.framework.base.BaseResponse;
import xyz.wbsite.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;
/**
*
*
* @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;
}
}

@ -0,0 +1,459 @@
package xyz.wbsite.framework.utils;
import javax.net.ssl.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* WebUtils - http访
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class WebUtils {
private static final String DEFAULT_CHARSET = "UTF-8";
private static final String METHOD_POST = "POST";
private static final String METHOD_GET = "GET";
//private static final Certificate verisign; //
private static boolean ignoreSSLCheck; // 忽略SSL检查
private static class TrustAllTrustManager implements X509TrustManager {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
}
private WebUtils() {
}
public static void setIgnoreSSLCheck(boolean ignoreSSLCheck) {
WebUtils.ignoreSSLCheck = ignoreSSLCheck;
}
/**
* HTTP POST
*
* @param url
* @param params
* @return
*/
public static String doPost(String url, Map<String, String> params, int connectTimeout, int readTimeout) throws IOException {
return doPost(url, params, DEFAULT_CHARSET, connectTimeout, readTimeout);
}
/**
* HTTP POST
*
* @param url
* @param params
* @param charset UTF-8, GBK, GB2312
* @return
*/
public static String doPost(String url, Map<String, String> params, String charset, int connectTimeout, int readTimeout) throws IOException {
return doPost(url, params, charset, connectTimeout, readTimeout, null);
}
public static String doPost(String url, Map<String, String> params, String charset, int connectTimeout, int readTimeout, Map<String, String> headerMap) throws IOException {
String ctype = "application/x-www-form-urlencoded;charset=" + charset;
String query = buildQuery(params, charset);
byte[] content = {};
if (query != null) {
content = query.getBytes(charset);
}
return _doPost(url, ctype, content, connectTimeout, readTimeout, headerMap);
}
/**
* HTTP POST
*
* @param url
* @param ctype
* @param content
* @return
*/
public static String doPost(String url, String ctype, byte[] content, int connectTimeout, int readTimeout) throws IOException {
return _doPost(url, ctype, content, connectTimeout, readTimeout, null);
}
private static String _doPost(String url, String ctype, byte[] content, int connectTimeout, int readTimeout, Map<String, String> headerMap) throws IOException {
HttpURLConnection conn = null;
OutputStream out = null;
String rsp = null;
try {
try {
conn = getConnection(new URL(url), METHOD_POST, ctype, headerMap);
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);
} catch (IOException e) {
throw e;
}
try {
out = conn.getOutputStream();
out.write(content);
rsp = getResponseAsString(conn);
} catch (IOException e) {
throw e;
}
} finally {
if (out != null) {
out.close();
}
if (conn != null) {
conn.disconnect();
}
}
return rsp;
}
private static byte[] getTextEntry(String fieldName, String fieldValue, String charset) throws IOException {
StringBuilder entry = new StringBuilder();
entry.append("Content-Disposition:form-data;name=\"");
entry.append(fieldName);
entry.append("\"\r\nContent-Type:text/plain\r\n\r\n");
entry.append(fieldValue);
return entry.toString().getBytes(charset);
}
private static byte[] getFileEntry(String fieldName, String fileName, String mimeType, String charset) throws IOException {
StringBuilder entry = new StringBuilder();
entry.append("Content-Disposition:form-data;name=\"");
entry.append(fieldName);
entry.append("\";filename=\"");
entry.append(fileName);
entry.append("\"\r\nContent-Type:");
entry.append(mimeType);
entry.append("\r\n\r\n");
return entry.toString().getBytes(charset);
}
/**
* HTTP GET
*
* @param url
* @param params
* @return
*/
public static String doGet(String url, Map<String, String> params) throws IOException {
return doGet(url, params, DEFAULT_CHARSET);
}
/**
* HTTP GET
*
* @param url
* @param params
* @param charset UTF-8, GBK, GB2312
* @return
*/
public static String doGet(String url, Map<String, String> params, String charset) throws IOException {
HttpURLConnection conn = null;
String rsp = null;
try {
String ctype = "application/x-www-form-urlencoded;charset=" + charset;
String query = buildQuery(params, charset);
try {
conn = getConnection(buildGetUrl(url, query), METHOD_GET, ctype, null);
} catch (IOException e) {
throw e;
}
try {
rsp = getResponseAsString(conn);
} catch (IOException e) {
throw e;
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
return rsp;
}
private static HttpURLConnection getConnection(URL url, String method, String ctype, Map<String, String> headerMap) throws IOException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection connHttps = (HttpsURLConnection) conn;
if (ignoreSSLCheck) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[]{new TrustAllTrustManager()}, new SecureRandom());
connHttps.setSSLSocketFactory(ctx.getSocketFactory());
connHttps.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (Exception e) {
throw new IOException(e);
}
} else {
try {
//SSLContext ctx = SSLContext.getInstance("TLS");
//ctx.init(null, new TrustManager[] { new VerisignTrustManager() }, new SecureRandom());
//connHttps.setSSLSocketFactory(ctx.getSocketFactory());
} catch (Exception e) {
throw new IOException(e);
}
}
conn = connHttps;
}
conn.setRequestMethod(method);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Accept", "text/xml,text/javascript");
conn.setRequestProperty("User-Agent", "top-sdk-java");
conn.setRequestProperty("Content-Type", ctype);
if (headerMap != null) {
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
}
return conn;
}
private static URL buildGetUrl(String strUrl, String query) throws IOException {
URL url = new URL(strUrl);
if (isEmpty(query)) {
return url;
}
if (isEmpty(url.getQuery())) {
if (strUrl.endsWith("?")) {
strUrl = strUrl + query;
} else {
strUrl = strUrl + "?" + query;
}
} else {
if (strUrl.endsWith("&")) {
strUrl = strUrl + query;
} else {
strUrl = strUrl + "&" + query;
}
}
return new URL(strUrl);
}
public static String buildQuery(Map<String, String> params, String charset) throws IOException {
if (params == null || params.isEmpty()) {
return null;
}
StringBuilder query = new StringBuilder();
Set<Map.Entry<String, String>> entries = params.entrySet();
boolean hasParam = false;
for (Map.Entry<String, String> entry : entries) {
String name = entry.getKey();
String value = entry.getValue();
// 忽略参数名或参数值为空的参数
if (areNotEmpty(name, value)) {
if (hasParam) {
query.append("&");
} else {
hasParam = true;
}
query.append(name).append("=").append(URLEncoder.encode(value, charset));
}
}
return query.toString();
}
public static boolean isEmpty(String value) {
int strLen;
if (value == null || (strLen = value.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(value.charAt(i)) == false)) {
return false;
}
}
return true;
}
/**
*
*/
public static boolean areNotEmpty(String... values) {
boolean result = true;
if (values == null || values.length == 0) {
result = false;
} else {
for (String value : values) {
result &= !isEmpty(value);
}
}
return result;
}
protected static String getResponseAsString(HttpURLConnection conn) throws IOException {
String charset = getResponseCharset(conn.getContentType());
InputStream es = conn.getErrorStream();
if (es == null) {
return getStreamAsString(conn.getInputStream(), charset);
} else {
String msg = getStreamAsString(es, charset);
if (isEmpty(msg)) {
throw new IOException(conn.getResponseCode() + ":" + conn.getResponseMessage());
} else {
throw new IOException(msg);
}
}
}
private static String getStreamAsString(InputStream stream, String charset) throws IOException {
try {
Reader reader = new InputStreamReader(stream, charset);
StringBuilder response = new StringBuilder();
final char[] buff = new char[1024];
int read = 0;
while ((read = reader.read(buff)) > 0) {
response.append(buff, 0, read);
}
return response.toString();
} finally {
if (stream != null) {
stream.close();
}
}
}
private static String getResponseCharset(String ctype) {
String charset = DEFAULT_CHARSET;
if (!isEmpty(ctype)) {
String[] params = ctype.split(";");
for (String param : params) {
param = param.trim();
if (param.startsWith("charset")) {
String[] pair = param.split("=", 2);
if (pair.length == 2) {
if (!isEmpty(pair[1])) {
charset = pair[1].trim();
}
}
break;
}
}
}
return charset;
}
/**
* 使UTF-8
*
* @param value
* @return
*/
public static String decode(String value) {
return decode(value, DEFAULT_CHARSET);
}
/**
* 使UTF-8
*
* @param value
* @return
*/
public static String encode(String value) {
return encode(value, DEFAULT_CHARSET);
}
/**
* 使
*
* @param value
* @param charset
* @return
*/
public static String decode(String value, String charset) {
String result = null;
if (!isEmpty(value)) {
try {
result = URLDecoder.decode(value, charset);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return result;
}
/**
* 使
*
* @param value
* @param charset
* @return
*/
public static String encode(String value, String charset) {
String result = null;
if (!isEmpty(value)) {
try {
result = URLEncoder.encode(value, charset);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return result;
}
private static Map<String, String> getParamsFromUrl(String url) {
Map<String, String> map = null;
if (url != null && url.indexOf('?') != -1) {
map = splitUrlQuery(url.substring(url.indexOf('?') + 1));
}
if (map == null) {
map = new HashMap<String, String>();
}
return map;
}
/**
* URL
*
* @param query URL
* @return
*/
public static Map<String, String> splitUrlQuery(String query) {
Map<String, String> result = new HashMap<String, String>();
String[] pairs = query.split("&");
if (pairs != null && pairs.length > 0) {
for (String pair : pairs) {
String[] param = pair.split("=", 2);
if (param != null && param.length == 2) {
result.put(param[0], param[1]);
}
}
}
return result;
}
}

@ -0,0 +1,47 @@
# 开发环境
server.port=8080
server.servlet.context-path=/
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:static/
spring.application.name=FILEMGR-WEB
# 编码配置
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
# 根路径、欢迎页
web.welcome.page = index
# 需要验证授权
web.url.auth.included = /**
# 不需要验证授权
web.url.auth.excluded = /static/**,/open/**,/api,/index,/,/login,/up
# 默认的登录URL
web.url.login = /login
# 日志配置
logging.path=D://
logging.levels=DEBUG
logging.config=classpath:logback-config.xml
# 热部署生效
spring.devtools.restart.enabled = true
# freemarker
spring.freemarker.enabled=true
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
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.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 = true
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB

@ -0,0 +1,46 @@
# 生产环境
server.port=80
server.servlet.context-path=/
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:static/
spring.application.name=FILEMGR-WEB
spring.main.banner-mode=off
# 编码配置
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
# 根路径、欢迎页
web.welcome.page = index
# 需要验证授权
web.url.auth.included = /**
# 不需要验证授权
web.url.auth.excluded = /static/**,/open/**,/api,/index,/,/login
# 默认的登录URL
web.url.login = /login
# 日志配置
logging.path = /root/
logging.levels=INFO
logging.config = classpath:logback-config.xml
# freemarker
spring.freemarker.enabled=true
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
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.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 = true
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB

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

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<projectName>FILEMGR-WEB</projectName>
<projectBasePackage>xyz.wbsite</projectBasePackage>
<projectAuthor>wangbing</projectAuthor>
<modules>
<module>
<moduleComment>文件管理</moduleComment>
<modulePrefix>FM_</modulePrefix>
<moduleName>filemgr</moduleName>
<hasSysFields>true</hasSysFields>
<tables>
<table create="true" delete="true" find="true" get="true" getAll="false" search="false" tableComment="注释" tableName="NEW_TABLE" update="true">
<fields>
<field IsSystem="true" defaultValue="" fieldComment="主键" fieldLength="0" fieldName="ID" fieldType="Long" isMust="true" isPrimaryKey="true" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="行版本" fieldLength="0" fieldName="ROW_VERSION" fieldType="Long" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="0" fieldComment="是否已删除" fieldLength="0" fieldName="IS_DELETED" fieldType="Boolean" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="创建用户" fieldLength="0" fieldName="CREATE_BY" fieldType="Long" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="NULL" fieldComment="创建时间" fieldLength="0" fieldName="CREATE_TIME" fieldType="Date" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="最后更新用户" fieldLength="0" fieldName="LAST_UPDATE_BY" fieldType="Long" isMust="false" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="最后更新时间" fieldLength="0" fieldName="LAST_UPDATE_TIME" fieldType="Date" isMust="false" isPrimaryKey="false" isQuery="false" isSearch="false"/>
</fields>
</table>
</tables>
</module>
</modules>
</project>

@ -0,0 +1,15 @@
-- ----------------------------
-- Table structure for NEW_TABLE - 注释
-- ----------------------------
CREATE TABLE `FM_NEW_TABLE` (
`ID` BIGINT(20) NOT NULL COMMENT '主键',
`ROW_VERSION` BIGINT(20) NOT NULL DEFAULT 0 COMMENT '行版本',
`IS_DELETED` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已删除',
`CREATE_BY` BIGINT(20) NOT NULL COMMENT '创建用户',
`CREATE_TIME` DATETIME NOT NULL COMMENT '创建时间',
`LAST_UPDATE_BY` BIGINT(20) DEFAULT NULL COMMENT '最后更新用户',
`LAST_UPDATE_TIME` DATETIME DEFAULT NULL COMMENT '最后更新时间',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='注释';

@ -0,0 +1,20 @@
/*
Target : MYSQL
Author
Date: 2019-02-15
*/
-- ----------------------------
-- Table structure for NEW_TABLE - 注释
-- ----------------------------
CREATE TABLE `FM_NEW_TABLE` (
`ID` BIGINT(20) NOT NULL COMMENT '主键',
`ROW_VERSION` BIGINT(20) NOT NULL DEFAULT 0 COMMENT '行版本',
`IS_DELETED` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已删除',
`CREATE_BY` BIGINT(20) NOT NULL COMMENT '创建用户',
`CREATE_TIME` DATETIME NOT NULL COMMENT '创建时间',
`LAST_UPDATE_BY` BIGINT(20) DEFAULT NULL COMMENT '最后更新用户',
`LAST_UPDATE_TIME` DATETIME DEFAULT NULL COMMENT '最后更新时间',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='注释';

@ -0,0 +1,109 @@
<?xml version="1.0"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志根目录 -->
<springProperty scope="context" name="root" source="logging.path"/>
<!-- 日志等级 -->
<springProperty scope="context" name="level" source="logging.level"/>
<!-- 迭代日志All级别文件 -->
<appender name="RollingFile_ALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${root}log/all/all.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${root}log/all/all-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>10MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%-4level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%logger{36}-%method] %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
<!-- 迭代日志error级别文件 -->
<appender name="RollingFile_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${root}log/error/error.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${root}log/error/error-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>10MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%-4level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%logger{36}-%method] %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 迭代日志warn级别文件 -->
<appender name="RollingFile_WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${root}log/warn/warn.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${root}log/warn/warn-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>10MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%-4level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%logger{36}-%method] %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 迭代日志info级别文件 -->
<appender name="RollingFile_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${root}log/info/info.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${root}log/info/info-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>10MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%-4level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%logger{36}-%method] %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 控制台输出 -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
debug级别及以上
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<encoder>
<pattern>%highlight(%d{yyyy-MM-dd HH:mm:ss.SSS} [%-4level] [%thread] [%logger{36}-%method] %ex %msg%n)</pattern>
</encoder>
</appender>
<logger name="java.sql" level="INFO"></logger>
<!-- 日志总入口 -->
<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"/>
</root>
</configuration>

@ -0,0 +1,3 @@
@echo off
cd %cd%
start java -Dfile.encoding=UTF-8 -jar FILEMGR-WEB-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev

@ -0,0 +1,3 @@
@echo off
cd %cd%
start java -Dfile.encoding=UTF-8 -jar FILEMGR-WEB-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod

@ -0,0 +1,786 @@
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
margin: 0px;
padding: 0px;
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
}
html {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%
}
body {
margin: 0;
font-size: 12px;
line-height: 1.5;
color: #515a6e;
background-color: #fff;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale
}
html, body {
width: 100%;
height: 100%;
}
article, aside, footer, header, nav, section {
display: block
}
h1 {
font-size: 2em;
margin: .67em 0
}
figcaption, figure, main {
display: block
}
figure {
margin: 1em 40px
}
hr {
-webkit-box-sizing: content-box;
box-sizing: content-box;
height: 0;
overflow: visible
}
pre {
font-family: monospace, monospace;
font-size: 1em
}
abbr[title] {
border-bottom: none;
text-decoration: underline;
-webkit-text-decoration: underline dotted;
text-decoration: underline dotted
}
b, strong {
font-weight: inherit
}
b, strong {
font-weight: bolder
}
code, kbd, samp {
font-family: monospace, monospace;
font-size: 1em
}
dfn {
font-style: italic
}
mark {
background-color: #ff0;
color: #000
}
small {
font-size: 80%
}
sub, sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline
}
sub {
bottom: -.25em
}
sup {
top: -.5em
}
audio, video {
display: inline-block
}
audio:not([controls]) {
display: none;
height: 0
}
img {
border-style: none
}
svg:not(:root) {
overflow: hidden
}
button, input, optgroup, select, textarea {
font-family: sans-serif;
font-size: 100%;
line-height: 1.15;
margin: 0
}
button, input {
overflow: visible
}
button, select {
text-transform: none
}
[type=reset], [type=submit], button, html [type=button] {
-webkit-appearance: button
}
[type=button]::-moz-focus-inner, [type=reset]::-moz-focus-inner, [type=submit]::-moz-focus-inner, button::-moz-focus-inner {
border-style: none;
padding: 0
}
[type=button]:-moz-focusring, [type=reset]:-moz-focusring, [type=submit]:-moz-focusring, button:-moz-focusring {
outline: 1px dotted ButtonText
}
fieldset {
border: 1px solid silver;
margin: 0 2px;
padding: .35em .625em .75em
}
legend {
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: inherit;
display: table;
max-width: 100%;
padding: 0;
white-space: normal
}
progress {
display: inline-block;
vertical-align: baseline
}
textarea {
overflow: auto;
resize: vertical
}
[type=checkbox], [type=radio] {
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 0
}
[type=number]::-webkit-inner-spin-button, [type=number]::-webkit-outer-spin-button {
height: auto
}
[type=search] {
-webkit-appearance: textfield;
outline-offset: -2px
}
[type=search]::-webkit-search-cancel-button, [type=search]::-webkit-search-decoration {
-webkit-appearance: none
}
::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit
}
details, menu {
display: block
}
summary {
display: list-item
}
canvas {
display: inline-block
}
template {
display: none
}
[hidden] {
display: none
}
:after, :before {
-webkit-box-sizing: border-box;
box-sizing: border-box
}
article, aside, blockquote, body, button, dd, details, div, dl, dt, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, input, legend, li, menu, nav, ol, p, section, td, textarea, th, ul {
margin: 0;
padding: 0
}
button, input, select, textarea {
font-family: inherit;
font-size: inherit;
line-height: inherit
}
input::-ms-clear, input::-ms-reveal {
display: none
}
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
}
code, kbd, pre, samp {
font-family: Consolas, Menlo, Courier, monospace
}
a {
text-decoration: none;
}
/*主标题*/
h1 {
font-size: 20px;
padding: 10px 0px;
margin: 20px 0px 10px 0px;
}
/*标题*/
h2 {
font-size: 18px;
padding: 9px 0px;
margin: 18px 0px 8px 0px;
}
/*小标题*/
h3 {
font-size: 16px;
padding: 8px 0px;
margin: 16px 0px 6px 0px;
}
/*次要标题*/
h4 {
font-size: 14px;
padding: 4px 0px;
margin: 4px 0px 4px 0px;
}
p {
font-size: 14px;
padding: 7px 0px;
color: #545C64;;
}
p.text-indent {
text-indent: 2em
}
/*正文*/
.text-regular {
font-size: 14px;
}
/*正文(小)*/
.text-small {
font-size: 13px
}
/*辅助文字*/
.text-smaller {
font-size: 12px
}
/*中文字体*/
.typo-PingFang {
font-family: PingFang SC
}
.typo-Hiragino {
font-family: Hiragino Sans GB
}
.typo-Microsoft {
font-family: Microsoft YaHei
}
/*英文/数字字体*/
.typo-Helvetica-Neue {
font-family: Helvetica Neue
}
.typo-Helvetica {
font-family: Helvetica
}
.typo-Arial {
font-family: Arial
}
.bg-blue {
background-color: #409eff
}
.bg-success {
background-color: #67c23a
}
.bg-warning {
background-color: #e6a23c
}
.bg-danger {
background-color: #f56c6c
}
.bg-info {
background-color: #909399
}
.text-color-primary {
color: #303133
}
.text-color-regular {
color: #606266
}
.text-color-secondary {
color: #909399
}
.text-color-placeholder {
color: #c0c4cc
}
.bg-border-base {
background-color: #dcdfe6
}
.bg-border-light {
background-color: #e4e7ed
}
.bg-border-lighter {
background-color: #ebeef5
}
.bg-border-extra-light {
background-color: #f2f6fc
}
[class*="bg-border-"] {
color: #303133
}
code {
background-color: #f9fafc;
padding: 0 4px;
border: 1px solid #eaeefb;
border-radius: 4px;
display: inline-block;
}
.remarks {
font-size: 12px;
color: #909399
}
.table {
display: table;
}
.table-cell {
display: table-cell;
}
.table-cell.center {
text-align: center;
vertical-align: middle;
}
.table-cell.v-center {
vertical-align: middle;
}
.table-cell.h-center {
text-align: center;
}
.table-cell.right {
text-align: right;
}
.table-cell.left {
text-align: left;
}
.table-cell.top {
vertical-align: top;
}
.table-cell.bottom {
vertical-align: bottom;
}
.m-t-10 {
margin-top: 10px;
}
.m-t-20 {
margin-top: 20px;
}
.m-t-30 {
margin-top: 30px;
}
.m-t-40 {
margin-top: 40px;
}
.m-t-50 {
margin-top: 50px;
}
.center{
text-align: center;
}
.full {
width: 100%;
height: 100%;
}
.nowrap {
white-space: nowrap;
overflow: hidden;
word-break: keep-all;
}
[v-cloak] {
display: none;
}
/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.left-in-right-out-enter-active, .left-in-right-out-leave-active {
transition: all 0.3s linear;
position: absolute;
}
.left-in-right-out-enter
/* .slide-fade-leave-active for below version 2.1.8 */
{
transform: translateX(-100%);
opacity: 0;
}
.left-in-right-out-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */
{
transform: translateX(100%);
opacity: 0;
}
.right-in-left-out-enter-active, .right-in-left-out-leave-active {
transition: all .3s linear;
position: absolute;
}
.right-in-left-out-enter {
transform: translateX(100%);
}
.right-in-left-out-leave-to {
transform: translateX(-100%);
}
.el-switch__input:focus ~ .el-switch__core {
position: relative;
box-sizing: border-box;
outline: none !important;
}
.row {
position: relative;
box-sizing: border-box;
}
[class*=col-] {
float: left;
box-sizing: border-box;
}
.col-1 {
width: 4.16667%;
}
.col-2 {
width: 8.33333%;
}
.col-3 {
width: 12.5%;
}
.col-4 {
width: 16.66667%;
}
.col-5 {
width: 20.83333%;
}
.col-6 {
width: 25%;
}
.col-7 {
width: 29.16667%;
}
.col-8 {
width: 33.33333%;
}
.col-9 {
width: 37.5%;
}
.col-10 {
width: 41.66667%;
}
.col-11 {
width: 45.83333%;
}
.col-12 {
width: 50%;
}
.col-13 {
width: 54.16667%;
}
.col-14 {
width: 58.33333%;
}
.col-15 {
width: 62.5%;
}
.col-16 {
width: 66.66667%;
}
.col-17 {
width: 70.83333%;
}
.col-18 {
width: 75%;
}
.col-19 {
width: 79.16667%;
}
.col-20 {
width: 83.33333%;
}
.col-21 {
width: 87.5%;
}
.col-22 {
width: 91.66667%;
}
.col-23 {
width: 95.83333%;
}
.col-24 {
width: 100%;
}
.page_list {
display: flex;
}
.page_list a {
display: inline-block;
height: 35px;
width: 35px;
line-height: 35px;
text-align: center;
cursor: pointer;
background-color: #2a2a2a;
color: #ffffff;
}
.page_list a.disabled {
opacity: 0.7;
}
.page_list a.current {
background-color: #16C0F8;
color: #ffffff;
}
.page_list a:hover {
background-color: #16C0F8;
color: #ffffff;
}
.page_list a.disabled:hover {
background-color: #373737;
color: #ffffff;
}
.page_list a.top_page,
.page_list a.page_prev,
.page_list a.page_next,
.page_list a.end_page {
width: 55px;
padding: 0px 5px;
}
.page_list p{
padding: 0px 20px;
line-height: 35px;
}
::-webkit-scrollbar {
width: 7px;
height: 7px;
background-color: #ffffff;
}
::-webkit-scrollbar-thumb {
background-color: #16C0F8;
}
::-webkit-scrollbar-track {
background-color: #ffffff;
}
.el-scrollbar.hidden_x > .el-scrollbar__wrap {
overflow-x: hidden !important;
}
.el-scrollbar.hidden_x > .el-scrollbar__wrap > .el-scrollbar__view {
height: 100%;
}
.el-menu--horizontal {
border-bottom: solid 0px #e6e6e6 !important;
}
.el-message {
min-width: 100px;
padding: 10px 60px 10px 20px;
background-color: #ffffff;
box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
}
.loading-bar {
width: 100%;
padding: 0px;
top: 0px;
box-shadow: 0px 0px 0px 0px;
border: 0px;
}
.loading-bar .el-message__content {
display: block;
width: 100%;
height: 2px;
}
.loading-bar .el-message__content .bar {
display: block;
height: 2px;
background-color: #2d8cf0;
}
.loading-bar .el-message__content .bar.error {
background-color: #ff1a0e;
}
/* 带有固定title布局,title保持固定*/
.wb-layout-title-fix {
width: 100%;
height: 100%;
overflow: hidden;
}
.wb-layout-title-fix > .wb-head {
height: 60px;
overflow: hidden;
}
.wb-layout-title-fix > .wb-body {
height: calc(100% - 60px);
}
/* 保持页脚绝对底部,当内容足够或高于屏幕,会自动将页面撑开,底部依旧保持在底部*/
.wb-layout-foot-absolute {
position: relative;
width: 100%;
height: auto;
min-height: 100%;
}
.wb-layout-foot-absolute > .wb-body {
padding-bottom: 50px;
}
.wb-layout-foot-absolute > .wb-foot {
position: absolute;
bottom: 0px;
left: 0px;
height: 50px;
width: 100%;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -0,0 +1,135 @@
//创建axios实例
instance = axios.create({
method: 'post',
timeout: 30000,
});
// 添加请求拦截器
instance.interceptors.request.use(function (config) {
// 在发送请求之前做些什么
nav.bar.show();
if (config.url == '/upload') {
nav.tip.show("上传中 ...");
} else {
nav.tip.show();
}
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
instance.interceptors.response.use(function (response) {
// 对响应数据做点什么
nav.tip.close();
nav.bar.finish();
return response;
}, function (error) {
// 对响应错误做点什么
nav.tip.close();
nav.bar.error();
const rsp = {errors: []};
if (!error.response) {
rsp.errors.push({message: error.message});
} else {
switch (error.response.status) {
case 401:
rsp.errors.push({message: "未授权,请登录(401)"});
break
case 403:
rsp.errors.push({message: "拒绝访问(403)"});
break
case 404:
rsp.errors.push({message: "请求地址错误(404)"});
break
case 408:
rsp.errors.push({message: "请求超时(408)"});
break
case 500:
rsp.errors.push({message: "服务器内部错误(500)"});
break
case 501:
rsp.errors.push({message: "服务未实现(501)"});
break
default:
rsp.errors.push({message: "请求错误(" + error.response.status + ")"});
break
}
}
return Promise.reject(rsp);
});
jsonRequest = function (config) {
return instance.request({
params: {
method: config.method
},
url: "/ajax",
headers: {'Content-Type': 'text/plain'},
data: config.data
}).then(function (response) {
return Promise.resolve(response.data);
}, function (response) {
return Promise.resolve(response);
})
};
fileRequest = function (config) {
return instance.request({
url: "/upload",
data: config.data,
headers: {'Content-Type': 'multipart/form-data'},
onUploadProgress: function (progressEvent) {
var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
nav.tip.show("上传中(" + complete + ")")
}
}).then(function (response) {
return Promise.resolve(response.data);
}, function (response) {
return Promise.resolve(response);
})
};
window.ajax = {
example: function (data) {
return jsonRequest({
method: "ajax.example.example",
data: data
})
},
fileUpload: function (file) {
var fd = new FormData();
fd.append("file", file);
return fileRequest({
data: fd
})
},
newTableCreate: function (data) {
return jsonRequest({
method:"ajax.filemgr.new.table.create",
data: JSON.stringify(data),
})
},
newTableDelete: function (data) {
return jsonRequest({
method:"ajax.filemgr.new.table.delete",
data: JSON.stringify(data),
})
},
newTableUpdate: function (data) {
return jsonRequest({
method:"ajax.filemgr.new.table.update",
data: JSON.stringify(data),
})
},
newTableFind: function (data) {
return jsonRequest({
method:"ajax.filemgr.new.table.find",
data: JSON.stringify(data),
})
},
newTableGet: function(data) {
return jsonRequest({
method:"ajax.filemgr.new.table.get",
data: JSON.stringify(data),
})
},
}

@ -0,0 +1,249 @@
<head>
<style>
body {
margin: 0px;
padding: 0px;
background-color: #f2f2f2;
}
.box {
width: 700px;
margin: 50px auto;
display: table;
}
.container {
display: table-cell;
vertical-align: middle;
}
.code {
font-weight: 500;
top: 100px;
left: 400px;
text-align: center;
width: 300px;
margin-top: 30px;
margin-bottom: 10px;
font-family: 'Varela Round', sans-serif;
font-size: 60px;
color: #6bbee0;
letter-spacing: 3px;
text-shadow: 0 0 5px #78d0ec;
animation: flux 2s linear infinite;
}
.message {
font-family: 'Poppins', sans-serif;
font-size: 20px;
color: #505050;
font-weight: 500;
}
.message2 {
font-family: 'Poppins', sans-serif;
font-size: 15px;
color: #505050;
font-weight: 300;
width: 360px;
white-space: nowrap;
}
.door-frame {
height: 340px;
width: 220px;
border-radius: 90px 90px 0 0;
background-color: #8594A5;
display: flex;
justify-content: center;
align-items: center;
}
.door {
height: 280px;
width: 170px;
border-radius: 70px 70px 0 0;
background-color: #A0AEC0;
}
.eye {
top: 15px;
left: 25px;
height: 5px;
width: 15px;
border-radius: 50%;
background-color: white;
animation: eye 7s ease-in-out infinite;
position: absolute;
}
.eye2 {
left: 65px;
}
.window {
height: 40px;
width: 130px;
background-color: #1C2127;
border-radius: 3px;
margin: 80px auto;
position: relative;
}
.leaf {
height: 40px;
width: 130px;
background-color: #8594A5;
border-radius: 3px;
margin: 80px auto;
animation: leaf 7s infinite;
transform-origin: right;
}
.handle {
height: 8px;
width: 30px;
border-radius: 4px;
background-color: #EBF3FC;
position: absolute;
margin-top: 195px;
margin-left: 30px;
}
.rectangle {
height: 60px;
width: 20px;
background-color: #CBD8E6;
border-radius: 4px;
position: absolute;
margin-top: 160px;
margin-left: 20px;
}
.message3 {
margin-top: 20px;
font-size: 12px;
}
a.login {
font-size: 15px;
text-decoration: none;
color: rgba(0, 130, 192, 0.69);
}
a.login:hover {
color: #0074c0;
}
@keyframes leaf {
0% {
transform: scaleX(1);
}
5% {
transform: scaleX(0.2);
}
70% {
transform: scaleX(0.2);
}
75% {
transform: scaleX(1);
}
100% {
transform: scaleX(1);
}
}
@keyframes eye {
0% {
opacity: 0;
transform: translateX(0)
}
5% {
opacity: 0;
}
15% {
opacity: 1;
transform: translateX(0)
}
20% {
transform: translateX(15px)
}
35% {
transform: translateX(15px)
}
40% {
transform: translateX(-15px)
}
60% {
transform: translateX(-15px)
}
65% {
transform: translateX(0)
}
}
@keyframes flux {
0%,
100% {
text-shadow: 0 0 5px #00FFC6, 0 0 15px #00FFC6, 0 0 50px #00FFC6, 0 0 50px #00FFC6, 0 0 2px #B9FFE8, 2px 2px 3px #12E29C;
color: #4BFFEF;
}
50% {
text-shadow: 0 0 3px #00B58D, 0 0 7px #00B58D, 0 0 25px #00B58D, 0 0 25px #00B58D, 0 0 2px #00B58D, 2px 2px 3px #006A60;
color: #63D3AE;
}
}
</style>
<script>
window.onload = function () {
var count = 4;
function go() {
if (count > 0) {
var e = document.getElementById("timer");
e.innerHTML = count + " 秒后自动跳转登录页"
count--;
} else {
location.href = '${Uri.getUrl("/login")}';
}
}
setInterval(go, 1000);
};
</script>
</head>
<body>
<div class="box">
<div class="container">
<div class="door-frame">
<div class="door">
<div class="rectangle">
</div>
<div class="handle">
</div>
<div class="window">
<div class="eye">
</div>
<div class="eye eye2">
</div>
<div class="leaf">
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="code">403</div>
<div class="message">您没有足够的权限哦!</div>
<div class="message2">您正在试图访问一个没有事先授权的页面.或登录已失效。</div>
<div class="message3" id="timer">5 秒后自动跳转登录页</div>
<a class="login" href="${Uri.getUrl("/login")}">立即跳转</a>
</div>
</div>
</body>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,40 @@
<head>
<style>
html,body{
overflow: hidden;
}
.box{
width: 100%;
height: 100%;
overflow: scroll;
}
.box a{
color: #c38168;
line-height: 18px;
text-decoration: underline;
}
.box::-webkit-scrollbar {/*滚动条整体样式*/
width: 10px; /*高宽分别对应横竖滚动条的尺寸*/
height: 1px;
}
.box::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
border-radius: 10px;
-webkit-box-shadow: inset 0 0 5px rgba(73, 73, 73, 0.2);
background: #828282;
}
.box::-webkit-scrollbar-track {/*滚动条里面轨道*/
-webkit-box-shadow: inset 0 0 5px rgba(125, 125, 125, 0.2);
border-radius: 10px;
background: #EDEDED;
}
</style>
</head>
<body>
<div class="box">
<p>
${msg}
</p>
</div>
</body>

@ -0,0 +1,5 @@
<div style="height: 50px;background-color: #303133">
<center>
<h3 style="color: #ffffff">------------------------------this is footer html------------------------------</h3>
</center>
</div>

@ -0,0 +1,119 @@
<div id="header">
<div class="logo">
<img @click="this.nav.toHome()" src="${Uri.getUrl('/static/img/logo.png')}">
</div>
<a class="home" href="${Uri.getUrl('/')}">Home</a>
<div class="menu">
<ul>
<li>
<a href="${Uri.getUrl('/1')}">首页</a>
</li>
<li>
<a href="${Uri.getUrl('/2')}">工作台</a>
</li>
<li>
<a href="${Uri.getUrl('/3')}">消息中心</a>
</li>
<li>
<a href="${Uri.getUrl('/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,233 @@
<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);
}
})();
}
}
});
/**
* 获取url参数
* @param key
*/
window.location.getParam = function (key) {
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
return null;
}
/**
* 打开新标签
* @param url
*/
window.location.open = function (url) {
$("body").append($("<a id='wb-open' href='" + url + "' target='_blank' style='dispaly:none;'></a>"))
document.getElementById("wb-open").click();
$("#wb-open").remove();
}
/**
* 日期格式化
*/
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
};
/**
* 数组移除
*/
Array.prototype.remove = function (val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
/**
* 数组替换
*/
Array.prototype.replace = function (val, obj) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1, obj);
}
};
/**
* 数组位置调整
*/
Array.prototype.exchange = function (val1, val2) {
if (val1 < 0 || val2 < 0 || val2 >= this.length || val1 >= this.length) {
return;
}
var o1 = this[val1];
var o2 = this[val2];
this.splice(val1, 1, o2);
this.splice(val2, 1, o1);
};
</script>

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="${Uri.getUrl('/static/img/favicon.ico')}" rel="Shortcut Icon" type="image/x-icon"/>
<script src="${Uri.getUrl('/static/dist/lib.min.js')}" type="text/javascript"></script>
<link href="${Uri.getUrl('/static/dist/lib.min.css')}" rel="stylesheet"/>
<script src="${Uri.getUrl('/static/js/ajax.js')}" type="text/javascript"></script>
<link href="${Uri.getUrl('/static/css/base.css')}" rel="stylesheet"/>
</head>
<body>
<#include Layout.setControl("macro")/>
<#include Layout.setControl("nav")/>
<div class="wb-layout-title-fix">
<div class="wb-head">
<#include Layout.setControl("header")/>
</div>
<div class="wb-body">
<#include Layout.setScreen()/>
</div>
</div>
</body>
</html>

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>文件管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<link href="${Uri.getUrl('/static/img/favicon.ico')}" rel="Shortcut Icon" type="image/x-icon"/>
<script src="${Uri.getUrl('/static/dist/lib.min.js')}" type="text/javascript"></script>
</head>
<body>
<#include Layout.setScreen()/>
</html>

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Mint UI</title>
</head>
<body>
<div id="app">
<router-link to="/">首页</router-link>
<router-link to="/next">next</router-link>
<transition name="wb-zoom-in-top">
<router-view></router-view>
</transition>
</div>
<template id="home"><div>home</div></template>
<template id="next"><div>next</div></template>
<script src="${Uri.getUrl('/static/lib/vue/vue.min.js')}" type="text/javascript"></script>
<script src="${Uri.getUrl('/static/lib/vue/vue-router.min.js')}" type="text/javascript"></script>
<script src="${Uri.getUrl('/static/lib/fastclick.js')}" type="text/javascript"></script>
<script>
var router = new VueRouter({
routes:[
{
path: '/',
name: 'home',
component:Vue.extend({template: '#home'})
},
{
path: '/next',
name: 'next',
component:Vue.extend({template: '#next'})
}
]
});
var app = new Vue({
el: '#app',
router:router
})
</script>
</html>

@ -0,0 +1,18 @@
<div id="app" v-cloak>
</div>
<style>
</style>
<script>
var app = new Vue({
el: "#app",
data: {},
methods: {},
created: function () {
},
mounted: function () {
},
watch: {}
})
</script>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,141 @@
<div id="app" v-cloak>
<div class="main">
<div class="content">
<div class="head">
<a>文件上传服务</a>
</div>
<el-upload
style="width: 300px;"
name="file"
class="upload-demo"
action="upload"
:http-request="handleUpload"
:on-preview="handlePreview"
:on-remove="handleRemove"
:before-remove="beforeRemove"
multiple
:limit="3"
:on-exceed="handleExceed"
:file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件且不超过500kb</div>
</el-upload>
<div class="body">
<form action="upload" method="post" enctype="multipart/form-data">
<a class="icon" onclick="file.click()">
<img src="${Uri.getUrl('/static/img/add.png')}">
</a>
<input id="file" name="file" type="file">
<input class="submit" type="submit" value="提交">
</form>
</div>
</div>
</div>
</div>
<style>
#app {
margin: 0px auto;
display: flex;
justify-content: center;
height: 100%;
}
* {
margin: 0px;
padding: 0px;
}
.main {
padding: 5px;
}
.content {
background-color: #ececd2;
box-shadow: 0px 0px 5px 0px;
}
.content .head {
height: 27px;
line-height: 27px;
padding-left: 10px;
background-color: #67B2FF;
color: white;
font-weight: bolder;
}
.content .body {
padding: 10px;
text-align: center;
}
.content .body .icon {
display: block;
text-align: center;
}
.content .body .icon img {
width: 50px;
height: 50px;
}
.content .body .submit {
display: inline-block;
width: 100%;
height: 30px;
margin-top: 10px;
background-color: #ffffff;
border: 1px solid #D6D6D6;
color: #6F7173;
font-weight: bolder;
}
</style>
<script type="text/javascript">
$(function () {
var app = new Vue({
el: '#app',
data: {
transitionName: ''
},
methods: {
fileList: [{
name: 'food.jpeg',
url: 'static/img/logo.png'
}],
handleUpload: function (req) {
ajax.fileUpload(req.file).then(function (response) {
if (response.errors.length > 0) {
req.onError();
nav.e(response.errors[0].message);
} else {
req.onSuccess();
nav.i("文件上传成功!");
}
})
},
handlePreview: function (file) {
console.log(file);
},
handleRemove: function (file, fileList) {
console.log(file, fileList);
},
beforeRemove: function (file, fileList) {
console.log(fileList);
return this.$confirm('确定移除 ${ file.name }');
},
handleExceed: function (files, fileList) {
this.$message.warning('当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件用户头像上传');
},
},
created: function () {
},
mounted: function () {
},
});
});
</script>

@ -0,0 +1,25 @@
package xyz.wbsite.config;
import xyz.wbsite.framework.base.Token;
import xyz.wbsite.framework.springmvc.GlobalHandlerInterceptor;
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.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class TestConfig {
@Bean
public Token getTestToken() {
Token token = new Token();
token.setId(-1);
token.setUserId(-1);
token.setUserName("system");
return token;
}
}

@ -0,0 +1,56 @@
# 开发环境
server.port=8080
server.servlet.context-path=/
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:static/
spring.application.name=SpringBoot
# 编码配置
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
# 根路径、欢迎页
web.welcome.page = index
# 排除的不需要验证的URL
web.url.excluded = /static/**,/open/**,/api,/index,/,/login
web.url.authorization = /**
# 默认的登录URL
web.url.login = /login
# 日志配置
logging.config=classpath:logback-config.xml
# 热部署生效
spring.devtools.restart.enabled=true
# 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
spring.datasource.username=test
spring.datasource.password=123456
# mybatis
mybatis.mapper-locations=classpath:**/mpr/*.xml
# pagehelper
pagehelper.autoRuntimeDialect=true
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
# freemarker
spring.freemarker.enabled=true
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
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.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 = true
spring.servlet.multipart.max-file-size=100Mb
spring.servlet.multipart.max-request-size=100Mb

@ -0,0 +1,22 @@
<?xml version="1.0"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 控制台输出 -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
debug级别及以上
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<encoder>
<pattern>%highlight(%d{yyyy-MM-dd HH:mm:ss.SSS} [%-4level] [%thread] [%logger{36}-%method] %ex %msg%n)</pattern>
</encoder>
</appender>
<logger name="java.sql" level="INFO"></logger>
<!-- 日志总入口 -->
<root level="DEBUG">
<appender-ref ref="Console"/>
</root>
</configuration>
Loading…
Cancel
Save

Powered by TurnKey Linux.