@@ -60,6 +60,7 @@ | |||
<module>spring-boot-demo-multi-datasource-mybatis</module> | |||
<module>spring-boot-demo-sharding-jdbc</module> | |||
<module>spring-boot-demo-tio</module> | |||
<module>spring-boot-demo-codegen</module> | |||
</modules> | |||
<packaging>pom</packaging> | |||
@@ -0,0 +1,28 @@ | |||
/target/ | |||
!.mvn/wrapper/maven-wrapper.jar | |||
### STS ### | |||
.apt_generated | |||
.classpath | |||
.factorypath | |||
.project | |||
.settings | |||
.springBeans | |||
.sts4-cache | |||
### IntelliJ IDEA ### | |||
.idea | |||
*.iws | |||
*.iml | |||
*.ipr | |||
### NetBeans ### | |||
/nbproject/private/ | |||
/nbbuild/ | |||
/dist/ | |||
/nbdist/ | |||
/.nb-gradle/ | |||
/build/ | |||
### VS Code ### | |||
.vscode/ |
@@ -0,0 +1,98 @@ | |||
<?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> | |||
<artifactId>spring-boot-demo-codegen</artifactId> | |||
<version>1.0.0-SNAPSHOT</version> | |||
<packaging>jar</packaging> | |||
<name>spring-boot-demo-codegen</name> | |||
<description>Demo project for Spring Boot</description> | |||
<parent> | |||
<groupId>com.xkcoding</groupId> | |||
<artifactId>spring-boot-demo</artifactId> | |||
<version>1.0.0-SNAPSHOT</version> | |||
</parent> | |||
<properties> | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |||
<java.version>1.8</java.version> | |||
</properties> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-web</artifactId> | |||
<exclusions> | |||
<exclusion> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-tomcat</artifactId> | |||
</exclusion> | |||
</exclusions> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-undertow</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-test</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.zaxxer</groupId> | |||
<artifactId>HikariCP</artifactId> | |||
</dependency> | |||
<!--velocity代码生成使用模板 --> | |||
<dependency> | |||
<groupId>org.apache.velocity</groupId> | |||
<artifactId>velocity</artifactId> | |||
<version>1.7</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.commons</groupId> | |||
<artifactId>commons-text</artifactId> | |||
<version>1.6</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>mysql</groupId> | |||
<artifactId>mysql-connector-java</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>cn.hutool</groupId> | |||
<artifactId>hutool-all</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.guava</groupId> | |||
<artifactId>guava</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.projectlombok</groupId> | |||
<artifactId>lombok</artifactId> | |||
<optional>true</optional> | |||
</dependency> | |||
</dependencies> | |||
<build> | |||
<finalName>spring-boot-demo-codegen</finalName> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-maven-plugin</artifactId> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</project> |
@@ -0,0 +1,26 @@ | |||
package com.xkcoding.codegen; | |||
import org.springframework.boot.SpringApplication; | |||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
/** | |||
* <p> | |||
* 启动器 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen | |||
* @description: 启动器 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 09:10 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@SpringBootApplication | |||
public class SpringBootDemoCodegenApplication { | |||
public static void main(String[] args) { | |||
SpringApplication.run(SpringBootDemoCodegenApplication.class, args); | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.xkcoding.codegen.common; | |||
/** | |||
* <p> | |||
* 统一状态码接口 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.rbac.shiro.common | |||
* @description: 统一状态码接口 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-21 16:28 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
public interface IResultCode { | |||
/** | |||
* 获取状态码 | |||
* | |||
* @return 状态码 | |||
*/ | |||
Integer getCode(); | |||
/** | |||
* 获取返回消息 | |||
* | |||
* @return 返回消息 | |||
*/ | |||
String getMessage(); | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.xkcoding.codegen.common; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 分页结果集 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.common | |||
* @description: 分页结果集 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 11:24 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Data | |||
@AllArgsConstructor | |||
public class PageResult<T> { | |||
/** | |||
* 总条数 | |||
*/ | |||
private Long total; | |||
/** | |||
* 页码 | |||
*/ | |||
private int pageNumber; | |||
/** | |||
* 每页结果数 | |||
*/ | |||
private int pageSize; | |||
/** | |||
* 结果集 | |||
*/ | |||
private List<T> list; | |||
} |
@@ -0,0 +1,95 @@ | |||
package com.xkcoding.codegen.common; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
/** | |||
* <p> | |||
* 统一API对象返回 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.common | |||
* @description: 统一API对象返回 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:13 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Data | |||
@NoArgsConstructor | |||
public class R<T> { | |||
/** | |||
* 状态码 | |||
*/ | |||
private Integer code; | |||
/** | |||
* 返回消息 | |||
*/ | |||
private String message; | |||
/** | |||
* 状态 | |||
*/ | |||
private boolean status; | |||
/** | |||
* 返回数据 | |||
*/ | |||
private T data; | |||
public R(Integer code, String message, boolean status, T data) { | |||
this.code = code; | |||
this.message = message; | |||
this.status = status; | |||
this.data = data; | |||
} | |||
public R(IResultCode resultCode, boolean status, T data) { | |||
this.code = resultCode.getCode(); | |||
this.message = resultCode.getMessage(); | |||
this.status = status; | |||
this.data = data; | |||
} | |||
public R(IResultCode resultCode, boolean status) { | |||
this.code = resultCode.getCode(); | |||
this.message = resultCode.getMessage(); | |||
this.status = status; | |||
this.data = null; | |||
} | |||
public static <T> R success() { | |||
return new R<>(ResultCode.OK, true); | |||
} | |||
public static <T> R message(String message) { | |||
return new R<>(ResultCode.OK.getCode(), message, true, null); | |||
} | |||
public static <T> R success(T data) { | |||
return new R<>(ResultCode.OK, true, data); | |||
} | |||
public static <T> R fail() { | |||
return new R<>(ResultCode.ERROR, false); | |||
} | |||
public static <T> R fail(IResultCode resultCode) { | |||
return new R<>(resultCode, false); | |||
} | |||
public static <T> R fail(Integer code, String message) { | |||
return new R<>(code, message, false, null); | |||
} | |||
public static <T> R fail(IResultCode resultCode, T data) { | |||
return new R<>(resultCode, false, data); | |||
} | |||
public static <T> R fail(Integer code, String message, T data) { | |||
return new R<>(code, message, false, data); | |||
} | |||
} |
@@ -0,0 +1,44 @@ | |||
package com.xkcoding.codegen.common; | |||
import lombok.Getter; | |||
/** | |||
* <p> | |||
* 通用状态枚举 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.common | |||
* @description: 通用状态枚举 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:13 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Getter | |||
public enum ResultCode implements IResultCode { | |||
/** | |||
* 成功 | |||
*/ | |||
OK(200, "成功"), | |||
/** | |||
* 失败 | |||
*/ | |||
ERROR(500, "失败"); | |||
/** | |||
* 返回码 | |||
*/ | |||
private Integer code; | |||
/** | |||
* 返回消息 | |||
*/ | |||
private String message; | |||
ResultCode(Integer code, String message) { | |||
this.code = code; | |||
this.message = message; | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
package com.xkcoding.codegen.constants; | |||
/** | |||
* <p> | |||
* 常量池 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.constants | |||
* @description: 常量池 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:04 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
public interface GenConstants { | |||
/** | |||
* 签名 | |||
*/ | |||
String SIGNATURE = "xkcoding"; | |||
/** | |||
* JDBC连接串前缀 | |||
*/ | |||
String JDBC_URL_PREFIX = "jdbc:mysql://"; | |||
} |
@@ -0,0 +1,60 @@ | |||
package com.xkcoding.codegen.controller; | |||
import cn.hutool.core.io.IoUtil; | |||
import com.xkcoding.codegen.common.R; | |||
import com.xkcoding.codegen.entity.GenConfig; | |||
import com.xkcoding.codegen.entity.TableRequest; | |||
import com.xkcoding.codegen.service.CodeGenService; | |||
import lombok.AllArgsConstructor; | |||
import lombok.SneakyThrows; | |||
import org.springframework.http.HttpHeaders; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.servlet.http.HttpServletResponse; | |||
/** | |||
* <p> | |||
* 代码生成器 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.controller | |||
* @description: 代码生成器 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:11 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@RestController | |||
@AllArgsConstructor | |||
@RequestMapping("/generator") | |||
public class CodeGenController { | |||
private final CodeGenService codeGenService; | |||
/** | |||
* 列表 | |||
* | |||
* @param request 参数集 | |||
* @return 数据库表 | |||
*/ | |||
@GetMapping("/table") | |||
public R listTables(TableRequest request) { | |||
return R.success(codeGenService.listTables(request)); | |||
} | |||
/** | |||
* 生成代码 | |||
*/ | |||
@SneakyThrows | |||
@PostMapping("") | |||
public void generatorCode(@RequestBody GenConfig genConfig, HttpServletResponse response) { | |||
byte[] data = codeGenService.generatorCode(genConfig); | |||
response.reset(); | |||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s.zip", genConfig.getTableName())); | |||
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length)); | |||
response.setContentType("application/octet-stream; charset=UTF-8"); | |||
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data); | |||
} | |||
} |
@@ -0,0 +1,48 @@ | |||
package com.xkcoding.codegen.entity; | |||
import lombok.Data; | |||
/** | |||
* <p> | |||
* 列属性: https://blog.csdn.net/lkforce/article/details/79557482 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.entity | |||
* @description: 列属性: https://blog.csdn.net/lkforce/article/details/79557482 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 09:46 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Data | |||
public class ColumnEntity { | |||
/** | |||
* 列表 | |||
*/ | |||
private String columnName; | |||
/** | |||
* 数据类型 | |||
*/ | |||
private String dataType; | |||
/** | |||
* 备注 | |||
*/ | |||
private String comments; | |||
/** | |||
* 驼峰属性 | |||
*/ | |||
private String caseAttrName; | |||
/** | |||
* 普通属性 | |||
*/ | |||
private String lowerAttrName; | |||
/** | |||
* 属性类型 | |||
*/ | |||
private String attrType; | |||
/** | |||
* 其他信息 | |||
*/ | |||
private String extra; | |||
} |
@@ -0,0 +1,48 @@ | |||
package com.xkcoding.codegen.entity; | |||
import lombok.Data; | |||
/** | |||
* <p> | |||
* 生成配置 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.entity | |||
* @description: 生成配置 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 09:47 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Data | |||
public class GenConfig { | |||
/** | |||
* 请求参数 | |||
*/ | |||
private TableRequest request; | |||
/** | |||
* 包名 | |||
*/ | |||
private String packageName; | |||
/** | |||
* 作者 | |||
*/ | |||
private String author; | |||
/** | |||
* 模块名称 | |||
*/ | |||
private String moduleName; | |||
/** | |||
* 表前缀 | |||
*/ | |||
private String tablePrefix; | |||
/** | |||
* 表名称 | |||
*/ | |||
private String tableName; | |||
/** | |||
* 表备注 | |||
*/ | |||
private String comments; | |||
} |
@@ -0,0 +1,46 @@ | |||
package com.xkcoding.codegen.entity; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 表属性: https://blog.csdn.net/lkforce/article/details/79557482 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.entity | |||
* @description: 表属性: https://blog.csdn.net/lkforce/article/details/79557482 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 09:47 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Data | |||
public class TableEntity { | |||
/** | |||
* 名称 | |||
*/ | |||
private String tableName; | |||
/** | |||
* 备注 | |||
*/ | |||
private String comments; | |||
/** | |||
* 主键 | |||
*/ | |||
private ColumnEntity pk; | |||
/** | |||
* 列名 | |||
*/ | |||
private List<ColumnEntity> columns; | |||
/** | |||
* 驼峰类型 | |||
*/ | |||
private String caseClassName; | |||
/** | |||
* 普通类型 | |||
*/ | |||
private String lowerClassName; | |||
} |
@@ -0,0 +1,44 @@ | |||
package com.xkcoding.codegen.entity; | |||
import lombok.Data; | |||
/** | |||
* <p> | |||
* 表格请求参数 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.entity | |||
* @description: 表格请求参数 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:24 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Data | |||
public class TableRequest { | |||
/** | |||
* 当前页 | |||
*/ | |||
private Integer currentPage; | |||
/** | |||
* 每页条数 | |||
*/ | |||
private Integer pageSize; | |||
/** | |||
* jdbc-url | |||
*/ | |||
private String url; | |||
/** | |||
* 用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 密码 | |||
*/ | |||
private String password; | |||
/** | |||
* 表名 | |||
*/ | |||
private String tableName; | |||
} |
@@ -0,0 +1,37 @@ | |||
package com.xkcoding.codegen.service; | |||
import cn.hutool.db.Entity; | |||
import com.xkcoding.codegen.common.PageResult; | |||
import com.xkcoding.codegen.entity.GenConfig; | |||
import com.xkcoding.codegen.entity.TableRequest; | |||
/** | |||
* <p> | |||
* 代码生成器 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.service | |||
* @description: 代码生成器 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:15 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
public interface CodeGenService { | |||
/** | |||
* 生成代码 | |||
* | |||
* @param genConfig 生成配置 | |||
* @return 代码压缩文件 | |||
*/ | |||
byte[] generatorCode(GenConfig genConfig); | |||
/** | |||
* 分页查询表信息 | |||
* | |||
* @param request 请求参数 | |||
* @return 表名分页信息 | |||
*/ | |||
PageResult<Entity> listTables(TableRequest request); | |||
} |
@@ -0,0 +1,128 @@ | |||
package com.xkcoding.codegen.service.impl; | |||
import cn.hutool.core.io.IoUtil; | |||
import cn.hutool.core.util.StrUtil; | |||
import cn.hutool.db.Db; | |||
import cn.hutool.db.Entity; | |||
import cn.hutool.db.Page; | |||
import com.xkcoding.codegen.common.PageResult; | |||
import com.xkcoding.codegen.entity.GenConfig; | |||
import com.xkcoding.codegen.entity.TableRequest; | |||
import com.xkcoding.codegen.service.CodeGenService; | |||
import com.xkcoding.codegen.utils.CodeGenUtil; | |||
import com.xkcoding.codegen.utils.DbUtil; | |||
import com.zaxxer.hikari.HikariDataSource; | |||
import lombok.AllArgsConstructor; | |||
import lombok.SneakyThrows; | |||
import org.springframework.stereotype.Service; | |||
import java.io.ByteArrayOutputStream; | |||
import java.math.BigDecimal; | |||
import java.util.List; | |||
import java.util.zip.ZipOutputStream; | |||
/** | |||
* 代码生成器 | |||
* | |||
* @author lengleng | |||
* @date 2018-07-30 | |||
*/ | |||
@Service | |||
@AllArgsConstructor | |||
public class CodeGenServiceImpl implements CodeGenService { | |||
private final String TABLE_SQL_TEMPLATE = "select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables where table_schema = (select database()) %s order by create_time desc"; | |||
private final String COLUMN_SQL_TEMPLATE = "select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns where table_name = ? and table_schema = (select database()) order by ordinal_position"; | |||
private final String COUNT_SQL_TEMPLATE = "select count(1) from (%s)tmp"; | |||
private final String PAGE_SQL_TEMPLATE = " limit ?,?"; | |||
/** | |||
* 分页查询表信息 | |||
* | |||
* @param request 请求参数 | |||
* @return 表名分页信息 | |||
*/ | |||
@Override | |||
@SneakyThrows | |||
public PageResult<Entity> listTables(TableRequest request) { | |||
HikariDataSource dataSource = DbUtil.buildFromTableRequest(request); | |||
Db db = new Db(dataSource); | |||
Page page = new Page(request.getCurrentPage(), request.getPageSize()); | |||
int start = page.getStartPosition(); | |||
int pageSize = page.getPageSize(); | |||
String paramSql = StrUtil.EMPTY; | |||
if (StrUtil.isNotBlank(request.getTableName())) { | |||
paramSql = "and table_name like concat('%', ?, '%')"; | |||
} | |||
String sql = String.format(TABLE_SQL_TEMPLATE, paramSql); | |||
String countSql = String.format(COUNT_SQL_TEMPLATE, sql); | |||
List<Entity> query; | |||
BigDecimal count; | |||
if (StrUtil.isNotBlank(request.getTableName())) { | |||
query = db.query(sql + PAGE_SQL_TEMPLATE, request.getTableName(), start, pageSize); | |||
count = (BigDecimal) db.queryNumber(countSql, request.getTableName()); | |||
} else { | |||
query = db.query(sql + PAGE_SQL_TEMPLATE, start, pageSize); | |||
count = (BigDecimal) db.queryNumber(countSql); | |||
} | |||
PageResult<Entity> pageResult = new PageResult<>(count.longValue(), page.getPageNumber(), page.getPageSize(), query); | |||
dataSource.close(); | |||
return pageResult; | |||
} | |||
/** | |||
* 生成代码 | |||
* | |||
* @param genConfig 生成配置 | |||
* @return 代码压缩文件 | |||
*/ | |||
@Override | |||
public byte[] generatorCode(GenConfig genConfig) { | |||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |||
ZipOutputStream zip = new ZipOutputStream(outputStream); | |||
//查询表信息 | |||
Entity table = queryTable(genConfig.getRequest()); | |||
//查询列信息 | |||
List<Entity> columns = queryColumns(genConfig.getRequest()); | |||
//生成代码 | |||
CodeGenUtil.generatorCode(genConfig, table, columns, zip); | |||
IoUtil.close(zip); | |||
return outputStream.toByteArray(); | |||
} | |||
@SneakyThrows | |||
private Entity queryTable(TableRequest request) { | |||
HikariDataSource dataSource = DbUtil.buildFromTableRequest(request); | |||
Db db = new Db(dataSource); | |||
String paramSql = StrUtil.EMPTY; | |||
if (StrUtil.isNotBlank(request.getTableName())) { | |||
paramSql = "and table_name = ?"; | |||
} | |||
String sql = String.format(TABLE_SQL_TEMPLATE, paramSql); | |||
Entity entity = db.queryOne(sql, request.getTableName()); | |||
dataSource.close(); | |||
return entity; | |||
} | |||
@SneakyThrows | |||
private List<Entity> queryColumns(TableRequest request) { | |||
HikariDataSource dataSource = DbUtil.buildFromTableRequest(request); | |||
Db db = new Db(dataSource); | |||
List<Entity> query = db.query(COLUMN_SQL_TEMPLATE, request.getTableName()); | |||
dataSource.close(); | |||
return query; | |||
} | |||
} |
@@ -0,0 +1,267 @@ | |||
package com.xkcoding.codegen.utils; | |||
import cn.hutool.core.date.DateUtil; | |||
import cn.hutool.core.io.IoUtil; | |||
import cn.hutool.core.util.CharsetUtil; | |||
import cn.hutool.core.util.StrUtil; | |||
import cn.hutool.db.Entity; | |||
import cn.hutool.setting.dialect.Props; | |||
import com.google.common.collect.Lists; | |||
import com.xkcoding.codegen.constants.GenConstants; | |||
import com.xkcoding.codegen.entity.ColumnEntity; | |||
import com.xkcoding.codegen.entity.GenConfig; | |||
import com.xkcoding.codegen.entity.TableEntity; | |||
import lombok.experimental.UtilityClass; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.text.WordUtils; | |||
import org.apache.velocity.Template; | |||
import org.apache.velocity.VelocityContext; | |||
import org.apache.velocity.app.Velocity; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.StringWriter; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.*; | |||
import java.util.zip.ZipEntry; | |||
import java.util.zip.ZipOutputStream; | |||
/** | |||
* <p> | |||
* 代码生成器 工具类 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.utils | |||
* @description: 代码生成器 工具类 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 09:27 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Slf4j | |||
@UtilityClass | |||
public class CodeGenUtil { | |||
private final String ENTITY_JAVA_VM = "Entity.java.vm"; | |||
private final String MAPPER_JAVA_VM = "Mapper.java.vm"; | |||
private final String SERVICE_JAVA_VM = "Service.java.vm"; | |||
private final String SERVICE_IMPL_JAVA_VM = "ServiceImpl.java.vm"; | |||
private final String CONTROLLER_JAVA_VM = "Controller.java.vm"; | |||
private final String MAPPER_XML_VM = "Mapper.xml.vm"; | |||
private final String API_JS_VM = "api.js.vm"; | |||
private List<String> getTemplates() { | |||
List<String> templates = new ArrayList<>(); | |||
templates.add("template/Entity.java.vm"); | |||
templates.add("template/Mapper.java.vm"); | |||
templates.add("template/Mapper.xml.vm"); | |||
templates.add("template/Service.java.vm"); | |||
templates.add("template/ServiceImpl.java.vm"); | |||
templates.add("template/Controller.java.vm"); | |||
templates.add("template/api.js.vm"); | |||
return templates; | |||
} | |||
/** | |||
* 生成代码 | |||
*/ | |||
public void generatorCode(GenConfig genConfig, Entity table, List<Entity> columns, ZipOutputStream zip) { | |||
//配置信息 | |||
Props props = getConfig(); | |||
boolean hasBigDecimal = false; | |||
//表信息 | |||
TableEntity tableEntity = new TableEntity(); | |||
tableEntity.setTableName(table.getStr("tableName")); | |||
if (StrUtil.isNotBlank(genConfig.getComments())) { | |||
tableEntity.setComments(genConfig.getComments()); | |||
} else { | |||
tableEntity.setComments(table.getStr("tableComment")); | |||
} | |||
String tablePrefix; | |||
if (StrUtil.isNotBlank(genConfig.getTablePrefix())) { | |||
tablePrefix = genConfig.getTablePrefix(); | |||
} else { | |||
tablePrefix = props.getStr("tablePrefix"); | |||
} | |||
//表名转换成Java类名 | |||
String className = tableToJava(tableEntity.getTableName(), tablePrefix); | |||
tableEntity.setCaseClassName(className); | |||
tableEntity.setLowerClassName(StrUtil.lowerFirst(className)); | |||
//列信息 | |||
List<ColumnEntity> columnList = Lists.newArrayList(); | |||
for (Entity column : columns) { | |||
ColumnEntity columnEntity = new ColumnEntity(); | |||
columnEntity.setColumnName(column.getStr("columnName")); | |||
columnEntity.setDataType(column.getStr("dataType")); | |||
columnEntity.setComments(column.getStr("columnComment")); | |||
columnEntity.setExtra(column.getStr("extra")); | |||
//列名转换成Java属性名 | |||
String attrName = columnToJava(columnEntity.getColumnName()); | |||
columnEntity.setCaseAttrName(attrName); | |||
columnEntity.setLowerAttrName(StrUtil.lowerFirst(attrName)); | |||
//列的数据类型,转换成Java类型 | |||
String attrType = props.getStr(columnEntity.getDataType(), "unknownType"); | |||
columnEntity.setAttrType(attrType); | |||
if (!hasBigDecimal && "BigDecimal".equals(attrType)) { | |||
hasBigDecimal = true; | |||
} | |||
//是否主键 | |||
if ("PRI".equalsIgnoreCase(column.getStr("columnKey")) && tableEntity.getPk() == null) { | |||
tableEntity.setPk(columnEntity); | |||
} | |||
columnList.add(columnEntity); | |||
} | |||
tableEntity.setColumns(columnList); | |||
//没主键,则第一个字段为主键 | |||
if (tableEntity.getPk() == null) { | |||
tableEntity.setPk(tableEntity.getColumns().get(0)); | |||
} | |||
//设置velocity资源加载器 | |||
Properties prop = new Properties(); | |||
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | |||
Velocity.init(prop); | |||
//封装模板数据 | |||
Map<String, Object> map = new HashMap<>(16); | |||
map.put("tableName", tableEntity.getTableName()); | |||
map.put("pk", tableEntity.getPk()); | |||
map.put("className", tableEntity.getCaseClassName()); | |||
map.put("classname", tableEntity.getLowerClassName()); | |||
map.put("pathName", tableEntity.getLowerClassName().toLowerCase()); | |||
map.put("columns", tableEntity.getColumns()); | |||
map.put("hasBigDecimal", hasBigDecimal); | |||
map.put("datetime", DateUtil.now()); | |||
map.put("year", DateUtil.year(new Date())); | |||
if (StrUtil.isNotBlank(genConfig.getComments())) { | |||
map.put("comments", genConfig.getComments()); | |||
} else { | |||
map.put("comments", tableEntity.getComments()); | |||
} | |||
if (StrUtil.isNotBlank(genConfig.getAuthor())) { | |||
map.put("author", genConfig.getAuthor()); | |||
} else { | |||
map.put("author", props.getStr("author")); | |||
} | |||
if (StrUtil.isNotBlank(genConfig.getModuleName())) { | |||
map.put("moduleName", genConfig.getModuleName()); | |||
} else { | |||
map.put("moduleName", props.getStr("moduleName")); | |||
} | |||
if (StrUtil.isNotBlank(genConfig.getPackageName())) { | |||
map.put("package", genConfig.getPackageName()); | |||
map.put("mainPath", genConfig.getPackageName()); | |||
} else { | |||
map.put("package", props.getStr("package")); | |||
map.put("mainPath", props.getStr("mainPath")); | |||
} | |||
VelocityContext context = new VelocityContext(map); | |||
//获取模板列表 | |||
List<String> templates = getTemplates(); | |||
for (String template : templates) { | |||
//渲染模板 | |||
StringWriter sw = new StringWriter(); | |||
Template tpl = Velocity.getTemplate(template, CharsetUtil.UTF_8); | |||
tpl.merge(context, sw); | |||
try { | |||
//添加到zip | |||
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(getFileName(template, tableEntity.getCaseClassName(), map | |||
.get("package") | |||
.toString(), map.get("moduleName").toString())))); | |||
IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString()); | |||
IoUtil.close(sw); | |||
zip.closeEntry(); | |||
} catch (IOException e) { | |||
throw new RuntimeException("渲染模板失败,表名:" + tableEntity.getTableName(), e); | |||
} | |||
} | |||
} | |||
/** | |||
* 列名转换成Java属性名 | |||
*/ | |||
private String columnToJava(String columnName) { | |||
return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", ""); | |||
} | |||
/** | |||
* 表名转换成Java类名 | |||
*/ | |||
private String tableToJava(String tableName, String tablePrefix) { | |||
if (StrUtil.isNotBlank(tablePrefix)) { | |||
tableName = tableName.replaceFirst(tablePrefix, ""); | |||
} | |||
return columnToJava(tableName); | |||
} | |||
/** | |||
* 获取配置信息 | |||
*/ | |||
private Props getConfig() { | |||
Props props = new Props("generator.properties"); | |||
props.autoLoad(true); | |||
return props; | |||
} | |||
/** | |||
* 获取文件名 | |||
*/ | |||
private String getFileName(String template, String className, String packageName, String moduleName) { | |||
// 包路径 | |||
String packagePath = GenConstants.SIGNATURE + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator; | |||
// 资源路径 | |||
String resourcePath = GenConstants.SIGNATURE + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator; | |||
// api路径 | |||
String apiPath = GenConstants.SIGNATURE + File.separator + "api" + File.separator; | |||
if (StrUtil.isNotBlank(packageName)) { | |||
packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator; | |||
} | |||
if (template.contains(ENTITY_JAVA_VM)) { | |||
return packagePath + "entity" + File.separator + className + ".java"; | |||
} | |||
if (template.contains(MAPPER_JAVA_VM)) { | |||
return packagePath + "mapper" + File.separator + className + "Mapper.java"; | |||
} | |||
if (template.contains(SERVICE_JAVA_VM)) { | |||
return packagePath + "service" + File.separator + className + "Service.java"; | |||
} | |||
if (template.contains(SERVICE_IMPL_JAVA_VM)) { | |||
return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java"; | |||
} | |||
if (template.contains(CONTROLLER_JAVA_VM)) { | |||
return packagePath + "controller" + File.separator + className + "Controller.java"; | |||
} | |||
if (template.contains(MAPPER_XML_VM)) { | |||
return resourcePath + "mapper" + File.separator + className + "Mapper.xml"; | |||
} | |||
if (template.contains(API_JS_VM)) { | |||
return apiPath + className.toLowerCase() + ".js"; | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
package com.xkcoding.codegen.utils; | |||
import com.xkcoding.codegen.constants.GenConstants; | |||
import com.xkcoding.codegen.entity.TableRequest; | |||
import com.zaxxer.hikari.HikariDataSource; | |||
import lombok.experimental.UtilityClass; | |||
import lombok.extern.slf4j.Slf4j; | |||
/** | |||
* <p> | |||
* 数据库工具类 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen.utils | |||
* @description: 数据库工具类 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:26 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@Slf4j | |||
@UtilityClass | |||
public class DbUtil { | |||
public HikariDataSource buildFromTableRequest(TableRequest request) { | |||
HikariDataSource dataSource = new HikariDataSource(); | |||
dataSource.setJdbcUrl(GenConstants.JDBC_URL_PREFIX + request.getUrl()); | |||
dataSource.setUsername(request.getUsername()); | |||
dataSource.setPassword(request.getPassword()); | |||
return dataSource; | |||
} | |||
} |
@@ -0,0 +1,4 @@ | |||
server: | |||
port: 8080 | |||
servlet: | |||
context-path: /demo |
@@ -0,0 +1,29 @@ | |||
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F | |||
mainPath=com.xkcoding | |||
#\u5305\u540D | |||
package=com.xkcoding | |||
moduleName=generator | |||
#\u4F5C\u8005 | |||
author=Yangkai.Shen | |||
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00) | |||
tablePrefix=tb_ | |||
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F | |||
tinyint=Integer | |||
smallint=Integer | |||
mediumint=Integer | |||
int=Integer | |||
integer=Integer | |||
bigint=Long | |||
float=Float | |||
double=Double | |||
decimal=BigDecimal | |||
bit=Boolean | |||
char=String | |||
varchar=String | |||
tinytext=String | |||
text=String | |||
mediumtext=String | |||
longtext=String | |||
date=LocalDateTime | |||
datetime=LocalDateTime | |||
timestamp=LocalDateTime |
@@ -0,0 +1,313 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="utf-8"> | |||
<title>代码生成器</title> | |||
<!-- import Vue.js --> | |||
<script src="libs/vue/vue.min.js"></script> | |||
<!-- import stylesheet --> | |||
<link rel="stylesheet" href="libs/iview/iview.css"> | |||
<!-- import iView --> | |||
<script src="libs/iview/iview.min.js"></script> | |||
<!-- import axios --> | |||
<script src="libs/axios/axios.min.js"></script> | |||
<!-- import date --> | |||
<script src="libs/datejs/date-zh-CN.js"></script> | |||
<style> | |||
html, body { | |||
height: 100%; | |||
} | |||
#app { | |||
height: inherit; | |||
} | |||
.xkcoding-layout { | |||
height: inherit; | |||
} | |||
.layout-header-center { | |||
text-align: center; | |||
} | |||
.layout-footer-center { | |||
color: #999999; | |||
text-align: center; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<div id="app"> | |||
<Layout class="xkcoding-layout"> | |||
<Header class="layout-header-center"> | |||
<h1>代码生成</h1> | |||
</Header> | |||
<Content :style="{padding: '0 50px'}"> | |||
<Card> | |||
<Row :gutter="16"> | |||
<i-form ref="formTableRequest" :model="tableRequest" label-position="right" label-width="50" | |||
:rules="tableRequestValidate"> | |||
<i-col span="7"> | |||
<form-item label="URL" prop="url" required> | |||
<i-input v-model="tableRequest.url" placeholder="格式为 <host>:<port>/<dbName>"> | |||
<span slot="prepend">jdbc:mysql://</span> | |||
</i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="4"> | |||
<form-item label="用户名" prop="username" label-width="60" required> | |||
<i-input v-model="tableRequest.username" placeholder="请输入数据库用户名"></i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="4"> | |||
<form-item label="密码" prop="password" required> | |||
<i-input v-model="tableRequest.password" type="password" | |||
placeholder="请输入数据库密码"></i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="5"> | |||
<form-item label="表名" prop="tableName" label-width="40"> | |||
<i-input v-model="tableRequest.tableName" placeholder="请输入数据库表名"></i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="4" style="text-align: center"> | |||
<i-button type="primary" long icon="ios-search" @click="search('formTableRequest')">查询 | |||
</i-button> | |||
</i-col> | |||
</i-form> | |||
</Row> | |||
<br> | |||
<Row> | |||
<i-col> | |||
<i-table border :columns="columns" :data="data"> | |||
<template slot-scope="{ row }" slot="tableName"> | |||
<strong>{{ row.tableName }}</strong> | |||
</template> | |||
<template slot-scope="{ row }" slot="action"> | |||
<i-button type="primary" icon="md-code-download" @click="showConfig(row.tableName)">生成代码 | |||
</i-button> | |||
</template> | |||
</i-table> | |||
</i-col> | |||
</Row> | |||
<br> | |||
<Row> | |||
<i-col> | |||
<Page :total="total" | |||
:current.sync="tableRequest.currentPage" | |||
@on-change="changePage" | |||
@on-page-size-change="changePageSize" | |||
show-sizer | |||
show-elevator | |||
show-total | |||
:page-size-opts="[10, 20, 30]"></Page> | |||
</i-col> | |||
</Row> | |||
</Card> | |||
</Content> | |||
<Footer class="layout-footer-center">2019 © xkcoding</Footer> | |||
</Layout> | |||
<Modal v-model="showConfigDialog" | |||
:closable="false"> | |||
<div slot="header" style="text-align:center"> | |||
<h2>生成配置</h2> | |||
</div> | |||
<i-form ref="form" :model="genConfig"> | |||
<Row :gutter="16"> | |||
<i-col span="12"> | |||
<form-item label="表名" prop="tableName" label-width="40"> | |||
<i-input v-model="genConfig.tableName" disabled></i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="12"> | |||
<form-item label="包名" prop="packageName" label-width="40"> | |||
<i-input v-model="genConfig.packageName" placeholder="可为空,加载系统默认配置"></i-input> | |||
</form-item> | |||
</i-col> | |||
</Row> | |||
<Row :gutter="16"> | |||
<i-col span="12"> | |||
<form-item label="作者" prop="author" label-width="40"> | |||
<i-input v-model="genConfig.author" placeholder="可为空,加载系统默认配置"></i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="12"> | |||
<form-item label="模块" prop="moduleName" label-width="40"> | |||
<i-input v-model="genConfig.moduleName" placeholder="可为空,加载系统默认配置"></i-input> | |||
</form-item> | |||
</i-col> | |||
</Row> | |||
<Row :gutter="16"> | |||
<i-col span="12"> | |||
<form-item label="前缀" prop="tablePrefix" label-width="40"> | |||
<i-input v-model="genConfig.tablePrefix" placeholder="可为空,加载系统默认配置"></i-input> | |||
</form-item> | |||
</i-col> | |||
<i-col span="12"> | |||
<form-item label="注释" prop="comments" label-width="40"> | |||
<i-input v-model="genConfig.comments" placeholder="可为空,加载数据库表注释"></i-input> | |||
</form-item> | |||
</i-col> | |||
</Row> | |||
</i-form> | |||
<div slot="footer" style="text-align:center"> | |||
<i-button icon="md-trash" size="large" @click="cancel">取消</i-button> | |||
<i-button type="success" icon="md-cloud-download" size="large" @click="download">生成代码</i-button> | |||
</div> | |||
</Modal> | |||
</div> | |||
<script> | |||
const http = axios.create({ | |||
baseURL: '/demo' | |||
}); | |||
new Vue({ | |||
el: "#app", | |||
data: { | |||
showConfigDialog: false, | |||
genConfig: { | |||
request: { | |||
url: "", | |||
username: "", | |||
password: "", | |||
tableName: "" | |||
}, | |||
packageName: "", | |||
author: "", | |||
moduleName: "", | |||
tablePrefix: "", | |||
comments: "", | |||
tableName: "" | |||
}, | |||
tableRequest: { | |||
currentPage: 1, | |||
pageSize: 10, | |||
url: "", | |||
username: "", | |||
password: "", | |||
tableName: "" | |||
}, | |||
total: 0, | |||
tableRequestValidate: { | |||
url: [ | |||
{required: true, message: 'JDBC连接串不能为空', trigger: 'blur'} | |||
], | |||
username: [ | |||
{required: true, message: '用户名不能为空', trigger: 'blur'} | |||
], | |||
password: [ | |||
{required: true, message: '密码不能为空', trigger: 'blur'} | |||
] | |||
}, | |||
columns: [ | |||
{ | |||
title: '序号', | |||
type: 'index', | |||
align: 'center', | |||
width: 80 | |||
}, | |||
{ | |||
title: '表名', | |||
slot: 'tableName', | |||
align: 'center' | |||
}, | |||
{ | |||
title: '注释', | |||
key: 'tableComment', | |||
align: 'center' | |||
}, | |||
{ | |||
title: '索引', | |||
key: 'engine', | |||
align: 'center' | |||
}, | |||
{ | |||
title: '创建时间', | |||
key: 'createTime', | |||
align: 'center', | |||
render: (h, params) => { | |||
return h('div', Date.parse(params.row.createTime.substring(0, params.row.createTime.indexOf("."))).toString('yyyy-MM-dd HH:mm:ss')); | |||
} | |||
}, | |||
{ | |||
title: '操作', | |||
slot: 'action', | |||
width: 150, | |||
align: 'center' | |||
} | |||
], | |||
data: [] | |||
}, | |||
methods: { | |||
showConfig(tableName) { | |||
this.genConfig.tableName = tableName; | |||
this.genConfig.request.tableName = tableName; | |||
this.genConfig.request.url = this.tableRequest.url; | |||
this.genConfig.request.username = this.tableRequest.username; | |||
this.genConfig.request.password = this.tableRequest.password; | |||
this.showConfigDialog = true; | |||
}, | |||
changePage(currentPage) { | |||
this.tableRequest.currentPage = currentPage; | |||
this.search("formTableRequest"); | |||
}, | |||
changePageSize(pageSize) { | |||
this.tableRequest.pageSize = pageSize; | |||
this.search("formTableRequest"); | |||
}, | |||
search(name) { | |||
this.$refs[name].validate((valid) => { | |||
if (valid) { | |||
let param = { | |||
currentPage: 1, | |||
pageSize: 10 | |||
}; | |||
Object.assign(param, this.tableRequest); | |||
http.get('/generator/table', { | |||
params: param | |||
}) | |||
.then(response => { | |||
const data = response.data; | |||
if (data.code === 200 && data.status) { | |||
this.data = data.data.list; | |||
this.total = data.data.total; | |||
} | |||
}) | |||
.catch(() => this.$Message.error("查询失败")); | |||
} else { | |||
this.$Message.error("请填写查询参数"); | |||
} | |||
}); | |||
}, | |||
download() { | |||
http({ | |||
url: '/generator', | |||
method: 'post', | |||
data: this.genConfig, | |||
responseType: 'arraybuffer' | |||
}).then((response) => { // 处理返回的文件流 | |||
let blob = new Blob([response.data], {type: 'application/zip'}); | |||
let filename = this.genConfig.tableName + '.zip'; | |||
let link = document.createElement('a'); | |||
link.href = URL.createObjectURL(blob); | |||
link.download = filename; | |||
document.body.appendChild(link); | |||
link.click(); | |||
window.setTimeout(function () { | |||
URL.revokeObjectURL(blob); | |||
document.body.removeChild(link); | |||
}, 0) | |||
}).catch(() => this.$Message.error("代码生成失败")); | |||
}, | |||
cancel() { | |||
this.showConfigDialog = false; | |||
} | |||
} | |||
}) | |||
</script> | |||
</body> | |||
</html> |
@@ -0,0 +1,145 @@ | |||
/** | |||
* @version: 1.0 Alpha-1 | |||
* @author: Coolite Inc. http://www.coolite.com/ | |||
* @date: 2008-05-13 | |||
* @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved. | |||
* @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. | |||
* @website: http://www.datejs.com/ | |||
*/ | |||
Date.CultureInfo={name:"zh-CN",englishName:"Chinese (People's Republic of China)",nativeName:"中文(中华人民共和国)",dayNames:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],abbreviatedDayNames:["日","一","二","三","四","五","六"],shortestDayNames:["日","一","二","三","四","五","六"],firstLetterDayNames:["日","一","二","三","四","五","六"],monthNames:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],abbreviatedMonthNames:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],amDesignator:"上午",pmDesignator:"下午",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"ymd",formatPatterns:{shortDate:"yyyy/M/d",longDate:"yyyy'年'M'月'd'日'",shortTime:"H:mm",longTime:"H:mm:ss",fullDateTime:"yyyy'年'M'月'd'日' H:mm:ss",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"M'月'd'日'",yearMonth:"yyyy'年'M'月'"},regexPatterns:{jan:/^一月/i,feb:/^二月/i,mar:/^三月/i,apr:/^四月/i,may:/^五月/i,jun:/^六月/i,jul:/^七月/i,aug:/^八月/i,sep:/^九月/i,oct:/^十月/i,nov:/^十一月/i,dec:/^十二月/i,sun:/^星期日/i,mon:/^星期一/i,tue:/^星期二/i,wed:/^星期三/i,thu:/^星期四/i,fri:/^星期五/i,sat:/^星期六/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|aft(er)?|from|hence)/i,subtract:/^(\-|bef(ore)?|ago)/i,yesterday:/^yes(terday)?/i,today:/^t(od(ay)?)?/i,tomorrow:/^tom(orrow)?/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^mn|min(ute)?s?/i,hour:/^h(our)?s?/i,week:/^w(eek)?s?/i,month:/^m(onth)?s?/i,day:/^d(ay)?s?/i,year:/^y(ear)?s?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt|utc)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a(?!u|p)|p)/i},timezones:[{name:"UTC",offset:"-000"},{name:"GMT",offset:"-000"},{name:"EST",offset:"-0500"},{name:"EDT",offset:"-0400"},{name:"CST",offset:"-0600"},{name:"CDT",offset:"-0500"},{name:"MST",offset:"-0700"},{name:"MDT",offset:"-0600"},{name:"PST",offset:"-0800"},{name:"PDT",offset:"-0700"}]}; | |||
(function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,p=function(s,l){if(!l){l=2;} | |||
return("000"+s).slice(l*-1);};$P.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};$P.setTimeToNow=function(){var n=new Date();this.setHours(n.getHours());this.setMinutes(n.getMinutes());this.setSeconds(n.getSeconds());this.setMilliseconds(n.getMilliseconds());return this;};$D.today=function(){return new Date().clearTime();};$D.compare=function(date1,date2){if(isNaN(date1)||isNaN(date2)){throw new Error(date1+" - "+date2);}else if(date1 instanceof Date&&date2 instanceof Date){return(date1<date2)?-1:(date1>date2)?1:0;}else{throw new TypeError(date1+" - "+date2);}};$D.equals=function(date1,date2){return(date1.compareTo(date2)===0);};$D.getDayNumberFromName=function(name){var n=$C.dayNames,m=$C.abbreviatedDayNames,o=$C.shortestDayNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s||o[i].toLowerCase()==s){return i;}} | |||
return-1;};$D.getMonthNumberFromName=function(name){var n=$C.monthNames,m=$C.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;i<n.length;i++){if(n[i].toLowerCase()==s||m[i].toLowerCase()==s){return i;}} | |||
return-1;};$D.isLeapYear=function(year){return((year%4===0&&year%100!==0)||year%400===0);};$D.getDaysInMonth=function(year,month){return[31,($D.isLeapYear(year)?29:28),31,30,31,30,31,31,30,31,30,31][month];};$D.getTimezoneAbbreviation=function(offset){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].offset===offset){return z[i].name;}} | |||
return null;};$D.getTimezoneOffset=function(name){var z=$C.timezones,p;for(var i=0;i<z.length;i++){if(z[i].name===name.toUpperCase()){return z[i].offset;}} | |||
return null;};$P.clone=function(){return new Date(this.getTime());};$P.compareTo=function(date){return Date.compare(this,date);};$P.equals=function(date){return Date.equals(this,date||new Date());};$P.between=function(start,end){return this.getTime()>=start.getTime()&&this.getTime()<=end.getTime();};$P.isAfter=function(date){return this.compareTo(date||new Date())===1;};$P.isBefore=function(date){return(this.compareTo(date||new Date())===-1);};$P.isToday=function(){return this.isSameDay(new Date());};$P.isSameDay=function(date){return this.clone().clearTime().equals(date.clone().clearTime());};$P.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};$P.addSeconds=function(value){return this.addMilliseconds(value*1000);};$P.addMinutes=function(value){return this.addMilliseconds(value*60000);};$P.addHours=function(value){return this.addMilliseconds(value*3600000);};$P.addDays=function(value){this.setDate(this.getDate()+value);return this;};$P.addWeeks=function(value){return this.addDays(value*7);};$P.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,$D.getDaysInMonth(this.getFullYear(),this.getMonth())));return this;};$P.addYears=function(value){return this.addMonths(value*12);};$P.add=function(config){if(typeof config=="number"){this._orient=config;return this;} | |||
var x=config;if(x.milliseconds){this.addMilliseconds(x.milliseconds);} | |||
if(x.seconds){this.addSeconds(x.seconds);} | |||
if(x.minutes){this.addMinutes(x.minutes);} | |||
if(x.hours){this.addHours(x.hours);} | |||
if(x.weeks){this.addWeeks(x.weeks);} | |||
if(x.months){this.addMonths(x.months);} | |||
if(x.years){this.addYears(x.years);} | |||
if(x.days){this.addDays(x.days);} | |||
return this;};var $y,$m,$d;$P.getWeek=function(){var a,b,c,d,e,f,g,n,s,w;$y=(!$y)?this.getFullYear():$y;$m=(!$m)?this.getMonth()+1:$m;$d=(!$d)?this.getDate():$d;if($m<=2){a=$y-1;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=0;f=$d-1+(31*($m-1));}else{a=$y;b=(a/4|0)-(a/100|0)+(a/400|0);c=((a-1)/4|0)-((a-1)/100|0)+((a-1)/400|0);s=b-c;e=s+1;f=$d+((153*($m-3)+2)/5)+58+s;} | |||
g=(a+b)%7;d=(f+g-e)%7;n=(f+3-d)|0;if(n<0){w=53-((g-s)/5|0);}else if(n>364+s){w=1;}else{w=(n/7|0)+1;} | |||
$y=$m=$d=null;return w;};$P.getISOWeek=function(){$y=this.getUTCFullYear();$m=this.getUTCMonth()+1;$d=this.getUTCDate();return p(this.getWeek());};$P.setWeek=function(n){return this.moveToDayOfWeek(1).addWeeks(n-this.getWeek());};$D._validate=function(n,min,max,name){if(typeof n=="undefined"){return false;}else if(typeof n!="number"){throw new TypeError(n+" is not a Number.");}else if(n<min||n>max){throw new RangeError(n+" is not a valid value for "+name+".");} | |||
return true;};$D.validateMillisecond=function(value){return $D._validate(value,0,999,"millisecond");};$D.validateSecond=function(value){return $D._validate(value,0,59,"second");};$D.validateMinute=function(value){return $D._validate(value,0,59,"minute");};$D.validateHour=function(value){return $D._validate(value,0,23,"hour");};$D.validateDay=function(value,year,month){return $D._validate(value,1,$D.getDaysInMonth(year,month),"day");};$D.validateMonth=function(value){return $D._validate(value,0,11,"month");};$D.validateYear=function(value){return $D._validate(value,0,9999,"year");};$P.set=function(config){if($D.validateMillisecond(config.millisecond)){this.addMilliseconds(config.millisecond-this.getMilliseconds());} | |||
if($D.validateSecond(config.second)){this.addSeconds(config.second-this.getSeconds());} | |||
if($D.validateMinute(config.minute)){this.addMinutes(config.minute-this.getMinutes());} | |||
if($D.validateHour(config.hour)){this.addHours(config.hour-this.getHours());} | |||
if($D.validateMonth(config.month)){this.addMonths(config.month-this.getMonth());} | |||
if($D.validateYear(config.year)){this.addYears(config.year-this.getFullYear());} | |||
if($D.validateDay(config.day,this.getFullYear(),this.getMonth())){this.addDays(config.day-this.getDate());} | |||
if(config.timezone){this.setTimezone(config.timezone);} | |||
if(config.timezoneOffset){this.setTimezoneOffset(config.timezoneOffset);} | |||
if(config.week&&$D._validate(config.week,0,53,"week")){this.setWeek(config.week);} | |||
return this;};$P.moveToFirstDayOfMonth=function(){return this.set({day:1});};$P.moveToLastDayOfMonth=function(){return this.set({day:$D.getDaysInMonth(this.getFullYear(),this.getMonth())});};$P.moveToNthOccurrence=function(dayOfWeek,occurrence){var shift=0;if(occurrence>0){shift=occurrence-1;} | |||
else if(occurrence===-1){this.moveToLastDayOfMonth();if(this.getDay()!==dayOfWeek){this.moveToDayOfWeek(dayOfWeek,-1);} | |||
return this;} | |||
return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek,+1).addWeeks(shift);};$P.moveToDayOfWeek=function(dayOfWeek,orient){var diff=(dayOfWeek-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};$P.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};$P.getOrdinalNumber=function(){return Math.ceil((this.clone().clearTime()-new Date(this.getFullYear(),0,1))/86400000)+1;};$P.getTimezone=function(){return $D.getTimezoneAbbreviation(this.getUTCOffset());};$P.setTimezoneOffset=function(offset){var here=this.getTimezoneOffset(),there=Number(offset)*-6/10;return this.addMinutes(there-here);};$P.setTimezone=function(offset){return this.setTimezoneOffset($D.getTimezoneOffset(offset));};$P.hasDaylightSavingTime=function(){return(Date.today().set({month:0,day:1}).getTimezoneOffset()!==Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.isDaylightSavingTime=function(){return(this.hasDaylightSavingTime()&&new Date().getTimezoneOffset()===Date.today().set({month:6,day:1}).getTimezoneOffset());};$P.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r.charAt(0)+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};$P.getElapsed=function(date){return(date||new Date())-this;};if(!$P.toISOString){$P.toISOString=function(){function f(n){return n<10?'0'+n:n;} | |||
return'"'+this.getUTCFullYear()+'-'+ | |||
f(this.getUTCMonth()+1)+'-'+ | |||
f(this.getUTCDate())+'T'+ | |||
f(this.getUTCHours())+':'+ | |||
f(this.getUTCMinutes())+':'+ | |||
f(this.getUTCSeconds())+'Z"';};} | |||
$P._toString=$P.toString;$P.toString=function(format){var x=this;if(format&&format.length==1){var c=$C.formatPatterns;x.t=x.toString;switch(format){case"d":return x.t(c.shortDate);case"D":return x.t(c.longDate);case"F":return x.t(c.fullDateTime);case"m":return x.t(c.monthDay);case"r":return x.t(c.rfc1123);case"s":return x.t(c.sortableDateTime);case"t":return x.t(c.shortTime);case"T":return x.t(c.longTime);case"u":return x.t(c.universalSortableDateTime);case"y":return x.t(c.yearMonth);}} | |||
var ord=function(n){switch(n*1){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}};return format?format.replace(/(\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S)/g,function(m){if(m.charAt(0)==="\\"){return m.replace("\\","");} | |||
x.h=x.getHours;switch(m){case"hh":return p(x.h()<13?(x.h()===0?12:x.h()):(x.h()-12));case"h":return x.h()<13?(x.h()===0?12:x.h()):(x.h()-12);case"HH":return p(x.h());case"H":return x.h();case"mm":return p(x.getMinutes());case"m":return x.getMinutes();case"ss":return p(x.getSeconds());case"s":return x.getSeconds();case"yyyy":return p(x.getFullYear(),4);case"yy":return p(x.getFullYear());case"dddd":return $C.dayNames[x.getDay()];case"ddd":return $C.abbreviatedDayNames[x.getDay()];case"dd":return p(x.getDate());case"d":return x.getDate();case"MMMM":return $C.monthNames[x.getMonth()];case"MMM":return $C.abbreviatedMonthNames[x.getMonth()];case"MM":return p((x.getMonth()+1));case"M":return x.getMonth()+1;case"t":return x.h()<12?$C.amDesignator.substring(0,1):$C.pmDesignator.substring(0,1);case"tt":return x.h()<12?$C.amDesignator:$C.pmDesignator;case"S":return ord(x.getDate());default:return m;}}):this._toString();};}()); | |||
(function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo,$N=Number.prototype;$P._orient=+1;$P._nth=null;$P._is=false;$P._same=false;$P._isSecond=false;$N._dateElement="day";$P.next=function(){this._orient=+1;return this;};$D.next=function(){return $D.today().next();};$P.last=$P.prev=$P.previous=function(){this._orient=-1;return this;};$D.last=$D.prev=$D.previous=function(){return $D.today().last();};$P.is=function(){this._is=true;return this;};$P.same=function(){this._same=true;this._isSecond=false;return this;};$P.today=function(){return this.same().day();};$P.weekday=function(){if(this._is){this._is=false;return(!this.is().sat()&&!this.is().sun());} | |||
return false;};$P.at=function(time){return(typeof time==="string")?$D.parse(this.toString("d")+" "+time):this.set(time);};$N.fromNow=$N.after=function(date){var c={};c[this._dateElement]=this;return((!date)?new Date():date.clone()).add(c);};$N.ago=$N.before=function(date){var c={};c[this._dateElement]=this*-1;return((!date)?new Date():date.clone()).add(c);};var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),pxf=("Milliseconds Seconds Minutes Hours Date Week Month FullYear").split(/\s/),nth=("final first second third fourth fifth").split(/\s/),de;$P.toObject=function(){var o={};for(var i=0;i<px.length;i++){o[px[i].toLowerCase()]=this["get"+pxf[i]]();} | |||
return o;};$D.fromObject=function(config){config.week=null;return Date.today().set(config);};var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} | |||
if(this._nth!==null){if(this._isSecond){this.addSeconds(this._orient*-1);} | |||
this._isSecond=false;var ntemp=this._nth;this._nth=null;var temp=this.clone().moveToLastDayOfMonth();this.moveToNthOccurrence(n,ntemp);if(this>temp){throw new RangeError($D.getDayName(n)+" does not occur "+ntemp+" times in the month of "+$D.getMonthName(temp.getMonth())+" "+temp.getFullYear()+".");} | |||
return this;} | |||
return this.moveToDayOfWeek(n,this._orient);};};var sdf=function(n){return function(){var t=$D.today(),shift=n-t.getDay();if(n===0&&$C.firstDayOfWeek===1&&t.getDay()!==0){shift=shift+7;} | |||
return t.addDays(shift);};};for(var i=0;i<dx.length;i++){$D[dx[i].toUpperCase()]=$D[dx[i].toUpperCase().substring(0,3)]=i;$D[dx[i]]=$D[dx[i].substring(0,3)]=sdf(i);$P[dx[i]]=$P[dx[i].substring(0,3)]=df(i);} | |||
var mf=function(n){return function(){if(this._is){this._is=false;return this.getMonth()===n;} | |||
return this.moveToMonth(n,this._orient);};};var smf=function(n){return function(){return $D.today().set({month:n,day:1});};};for(var j=0;j<mx.length;j++){$D[mx[j].toUpperCase()]=$D[mx[j].toUpperCase().substring(0,3)]=j;$D[mx[j]]=$D[mx[j].substring(0,3)]=smf(j);$P[mx[j]]=$P[mx[j].substring(0,3)]=mf(j);} | |||
var ef=function(j){return function(){if(this._isSecond){this._isSecond=false;return this;} | |||
if(this._same){this._same=this._is=false;var o1=this.toObject(),o2=(arguments[0]||new Date()).toObject(),v="",k=j.toLowerCase();for(var m=(px.length-1);m>-1;m--){v=px[m].toLowerCase();if(o1[v]!=o2[v]){return false;} | |||
if(k==v){break;}} | |||
return true;} | |||
if(j.substring(j.length-1)!="s"){j+="s";} | |||
return this["add"+j](this._orient);};};var nf=function(n){return function(){this._dateElement=n;return this;};};for(var k=0;k<px.length;k++){de=px[k].toLowerCase();$P[de]=$P[de+"s"]=ef(px[k]);$N[de]=$N[de+"s"]=nf(de);} | |||
$P._ss=ef("Second");var nthfn=function(n){return function(dayOfWeek){if(this._same){return this._ss(arguments[0]);} | |||
if(dayOfWeek||dayOfWeek===0){return this.moveToNthOccurrence(dayOfWeek,n);} | |||
this._nth=n;if(n===2&&(dayOfWeek===undefined||dayOfWeek===null)){this._isSecond=true;return this.addSeconds(this._orient);} | |||
return this;};};for(var l=0;l<nth.length;l++){$P[nth[l]]=(l===0)?nthfn(-1):nthfn(l);}}()); | |||
(function(){Date.Parsing={Exception:function(s){this.message="Parse error at '"+s.substring(0,10)+" ...'";}};var $P=Date.Parsing;var _=$P.Operators={rtoken:function(r){return function(s){var mx=s.match(r);if(mx){return([mx[0],s.substring(mx[0].length)]);}else{throw new $P.Exception(s);}};},token:function(s){return function(s){return _.rtoken(new RegExp("^\s*"+s+"\s*"))(s);};},stoken:function(s){return _.rtoken(new RegExp("^"+s));},until:function(p){return function(s){var qx=[],rx=null;while(s.length){try{rx=p.call(this,s);}catch(e){qx.push(rx[0]);s=rx[1];continue;} | |||
break;} | |||
return[qx,s];};},many:function(p){return function(s){var rx=[],r=null;while(s.length){try{r=p.call(this,s);}catch(e){return[rx,s];} | |||
rx.push(r[0]);s=r[1];} | |||
return[rx,s];};},optional:function(p){return function(s){var r=null;try{r=p.call(this,s);}catch(e){return[null,s];} | |||
return[r[0],r[1]];};},not:function(p){return function(s){try{p.call(this,s);}catch(e){return[null,s];} | |||
throw new $P.Exception(s);};},ignore:function(p){return p?function(s){var r=null;r=p.call(this,s);return[null,r[1]];}:null;},product:function(){var px=arguments[0],qx=Array.prototype.slice.call(arguments,1),rx=[];for(var i=0;i<px.length;i++){rx.push(_.each(px[i],qx));} | |||
return rx;},cache:function(rule){var cache={},r=null;return function(s){try{r=cache[s]=(cache[s]||rule.call(this,s));}catch(e){r=cache[s]=e;} | |||
if(r instanceof $P.Exception){throw r;}else{return r;}};},any:function(){var px=arguments;return function(s){var r=null;for(var i=0;i<px.length;i++){if(px[i]==null){continue;} | |||
try{r=(px[i].call(this,s));}catch(e){r=null;} | |||
if(r){return r;}} | |||
throw new $P.Exception(s);};},each:function(){var px=arguments;return function(s){var rx=[],r=null;for(var i=0;i<px.length;i++){if(px[i]==null){continue;} | |||
try{r=(px[i].call(this,s));}catch(e){throw new $P.Exception(s);} | |||
rx.push(r[0]);s=r[1];} | |||
return[rx,s];};},all:function(){var px=arguments,_=_;return _.each(_.optional(px));},sequence:function(px,d,c){d=d||_.rtoken(/^\s*/);c=c||null;if(px.length==1){return px[0];} | |||
return function(s){var r=null,q=null;var rx=[];for(var i=0;i<px.length;i++){try{r=px[i].call(this,s);}catch(e){break;} | |||
rx.push(r[0]);try{q=d.call(this,r[1]);}catch(ex){q=null;break;} | |||
s=q[1];} | |||
if(!r){throw new $P.Exception(s);} | |||
if(q){throw new $P.Exception(q[1]);} | |||
if(c){try{r=c.call(this,r[1]);}catch(ey){throw new $P.Exception(r[1]);}} | |||
return[rx,(r?r[1]:s)];};},between:function(d1,p,d2){d2=d2||d1;var _fn=_.each(_.ignore(d1),p,_.ignore(d2));return function(s){var rx=_fn.call(this,s);return[[rx[0][0],r[0][2]],rx[1]];};},list:function(p,d,c){d=d||_.rtoken(/^\s*/);c=c||null;return(p instanceof Array?_.each(_.product(p.slice(0,-1),_.ignore(d)),p.slice(-1),_.ignore(c)):_.each(_.many(_.each(p,_.ignore(d))),px,_.ignore(c)));},set:function(px,d,c){d=d||_.rtoken(/^\s*/);c=c||null;return function(s){var r=null,p=null,q=null,rx=null,best=[[],s],last=false;for(var i=0;i<px.length;i++){q=null;p=null;r=null;last=(px.length==1);try{r=px[i].call(this,s);}catch(e){continue;} | |||
rx=[[r[0]],r[1]];if(r[1].length>0&&!last){try{q=d.call(this,r[1]);}catch(ex){last=true;}}else{last=true;} | |||
if(!last&&q[1].length===0){last=true;} | |||
if(!last){var qx=[];for(var j=0;j<px.length;j++){if(i!=j){qx.push(px[j]);}} | |||
p=_.set(qx,d).call(this,q[1]);if(p[0].length>0){rx[0]=rx[0].concat(p[0]);rx[1]=p[1];}} | |||
if(rx[1].length<best[1].length){best=rx;} | |||
if(best[1].length===0){break;}} | |||
if(best[0].length===0){return best;} | |||
if(c){try{q=c.call(this,best[1]);}catch(ey){throw new $P.Exception(best[1]);} | |||
best[1]=q[1];} | |||
return best;};},forward:function(gr,fname){return function(s){return gr[fname].call(this,s);};},replace:function(rule,repl){return function(s){var r=rule.call(this,s);return[repl,r[1]];};},process:function(rule,fn){return function(s){var r=rule.call(this,s);return[fn.call(this,r[0]),r[1]];};},min:function(min,rule){return function(s){var rx=rule.call(this,s);if(rx[0].length<min){throw new $P.Exception(s);} | |||
return rx;};}};var _generator=function(op){return function(){var args=null,rx=[];if(arguments.length>1){args=Array.prototype.slice.call(arguments);}else if(arguments[0]instanceof Array){args=arguments[0];} | |||
if(args){for(var i=0,px=args.shift();i<px.length;i++){args.unshift(px[i]);rx.push(op.apply(null,args));args.shift();return rx;}}else{return op.apply(null,arguments);}};};var gx="optional not ignore cache".split(/\s/);for(var i=0;i<gx.length;i++){_[gx[i]]=_generator(_[gx[i]]);} | |||
var _vector=function(op){return function(){if(arguments[0]instanceof Array){return op.apply(null,arguments[0]);}else{return op.apply(null,arguments);}};};var vx="each any all".split(/\s/);for(var j=0;j<vx.length;j++){_[vx[j]]=_vector(_[vx[j]]);}}());(function(){var $D=Date,$P=$D.prototype,$C=$D.CultureInfo;var flattenAndCompact=function(ax){var rx=[];for(var i=0;i<ax.length;i++){if(ax[i]instanceof Array){rx=rx.concat(flattenAndCompact(ax[i]));}else{if(ax[i]){rx.push(ax[i]);}}} | |||
return rx;};$D.Grammar={};$D.Translator={hour:function(s){return function(){this.hour=Number(s);};},minute:function(s){return function(){this.minute=Number(s);};},second:function(s){return function(){this.second=Number(s);};},meridian:function(s){return function(){this.meridian=s.slice(0,1).toLowerCase();};},timezone:function(s){return function(){var n=s.replace(/[^\d\+\-]/g,"");if(n.length){this.timezoneOffset=Number(n);}else{this.timezone=s.toLowerCase();}};},day:function(x){var s=x[0];return function(){this.day=Number(s.match(/\d+/)[0]);};},month:function(s){return function(){this.month=(s.length==3)?"jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4:Number(s)-1;};},year:function(s){return function(){var n=Number(s);this.year=((s.length>2)?n:(n+(((n+2000)<$C.twoDigitYearMax)?2000:1900)));};},rday:function(s){return function(){switch(s){case"yesterday":this.days=-1;break;case"tomorrow":this.days=1;break;case"today":this.days=0;break;case"now":this.days=0;this.now=true;break;}};},finishExact:function(x){x=(x instanceof Array)?x:[x];for(var i=0;i<x.length;i++){if(x[i]){x[i].call(this);}} | |||
var now=new Date();if((this.hour||this.minute)&&(!this.month&&!this.year&&!this.day)){this.day=now.getDate();} | |||
if(!this.year){this.year=now.getFullYear();} | |||
if(!this.month&&this.month!==0){this.month=now.getMonth();} | |||
if(!this.day){this.day=1;} | |||
if(!this.hour){this.hour=0;} | |||
if(!this.minute){this.minute=0;} | |||
if(!this.second){this.second=0;} | |||
if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} | |||
if(this.day>$D.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} | |||
var r=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second);if(this.timezone){r.set({timezone:this.timezone});}else if(this.timezoneOffset){r.set({timezoneOffset:this.timezoneOffset});} | |||
return r;},finish:function(x){x=(x instanceof Array)?flattenAndCompact(x):[x];if(x.length===0){return null;} | |||
for(var i=0;i<x.length;i++){if(typeof x[i]=="function"){x[i].call(this);}} | |||
var today=$D.today();if(this.now&&!this.unit&&!this.operator){return new Date();}else if(this.now){today=new Date();} | |||
var expression=!!(this.days&&this.days!==null||this.orient||this.operator);var gap,mod,orient;orient=((this.orient=="past"||this.operator=="subtract")?-1:1);if(!this.now&&"hour minute second".indexOf(this.unit)!=-1){today.setTimeToNow();} | |||
if(this.month||this.month===0){if("year day hour minute second".indexOf(this.unit)!=-1){this.value=this.month+1;this.month=null;expression=true;}} | |||
if(!expression&&this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(!this.month){this.month=temp.getMonth();} | |||
this.year=temp.getFullYear();} | |||
if(expression&&this.weekday&&this.unit!="month"){this.unit="day";gap=($D.getDayNumberFromName(this.weekday)-today.getDay());mod=7;this.days=gap?((gap+(orient*mod))%mod):(orient*mod);} | |||
if(this.month&&this.unit=="day"&&this.operator){this.value=(this.month+1);this.month=null;} | |||
if(this.value!=null&&this.month!=null&&this.year!=null){this.day=this.value*1;} | |||
if(this.month&&!this.day&&this.value){today.set({day:this.value*1});if(!expression){this.day=this.value*1;}} | |||
if(!this.month&&this.value&&this.unit=="month"&&!this.now){this.month=this.value;expression=true;} | |||
if(expression&&(this.month||this.month===0)&&this.unit!="year"){this.unit="month";gap=(this.month-today.getMonth());mod=12;this.months=gap?((gap+(orient*mod))%mod):(orient*mod);this.month=null;} | |||
if(!this.unit){this.unit="day";} | |||
if(!this.value&&this.operator&&this.operator!==null&&this[this.unit+"s"]&&this[this.unit+"s"]!==null){this[this.unit+"s"]=this[this.unit+"s"]+((this.operator=="add")?1:-1)+(this.value||0)*orient;}else if(this[this.unit+"s"]==null||this.operator!=null){if(!this.value){this.value=1;} | |||
this[this.unit+"s"]=this.value*orient;} | |||
if(this.meridian&&this.hour){if(this.meridian=="p"&&this.hour<12){this.hour=this.hour+12;}else if(this.meridian=="a"&&this.hour==12){this.hour=0;}} | |||
if(this.weekday&&!this.day&&!this.days){var temp=Date[this.weekday]();this.day=temp.getDate();if(temp.getMonth()!==today.getMonth()){this.month=temp.getMonth();}} | |||
if((this.month||this.month===0)&&!this.day){this.day=1;} | |||
if(!this.orient&&!this.operator&&this.unit=="week"&&this.value&&!this.day&&!this.month){return Date.today().setWeek(this.value);} | |||
if(expression&&this.timezone&&this.day&&this.days){this.day=this.days;} | |||
return(expression)?today.add(this):today.set(this);}};var _=$D.Parsing.Operators,g=$D.Grammar,t=$D.Translator,_fn;g.datePartDelimiter=_.rtoken(/^([\s\-\.\,\/\x27]+)/);g.timePartDelimiter=_.stoken(":");g.whiteSpace=_.rtoken(/^\s*/);g.generalDelimiter=_.rtoken(/^(([\s\,]|at|@|on)+)/);var _C={};g.ctoken=function(keys){var fn=_C[keys];if(!fn){var c=$C.regexPatterns;var kx=keys.split(/\s+/),px=[];for(var i=0;i<kx.length;i++){px.push(_.replace(_.rtoken(c[kx[i]]),kx[i]));} | |||
fn=_C[keys]=_.any.apply(null,px);} | |||
return fn;};g.ctoken2=function(key){return _.rtoken($C.regexPatterns[key]);};g.h=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/),t.hour));g.hh=_.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/),t.hour));g.H=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/),t.hour));g.HH=_.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/),t.hour));g.m=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.minute));g.mm=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.minute));g.s=_.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/),t.second));g.ss=_.cache(_.process(_.rtoken(/^[0-5][0-9]/),t.second));g.hms=_.cache(_.sequence([g.H,g.m,g.s],g.timePartDelimiter));g.t=_.cache(_.process(g.ctoken2("shortMeridian"),t.meridian));g.tt=_.cache(_.process(g.ctoken2("longMeridian"),t.meridian));g.z=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zz=_.cache(_.process(_.rtoken(/^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/),t.timezone));g.zzz=_.cache(_.process(g.ctoken2("timezone"),t.timezone));g.timeSuffix=_.each(_.ignore(g.whiteSpace),_.set([g.tt,g.zzz]));g.time=_.each(_.optional(_.ignore(_.stoken("T"))),g.hms,g.timeSuffix);g.d=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.dd=_.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/),_.optional(g.ctoken2("ordinalSuffix"))),t.day));g.ddd=g.dddd=_.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),function(s){return function(){this.weekday=s;};}));g.M=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/),t.month));g.MM=_.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/),t.month));g.MMM=g.MMMM=_.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"),t.month));g.y=_.cache(_.process(_.rtoken(/^(\d\d?)/),t.year));g.yy=_.cache(_.process(_.rtoken(/^(\d\d)/),t.year));g.yyy=_.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/),t.year));g.yyyy=_.cache(_.process(_.rtoken(/^(\d\d\d\d)/),t.year));_fn=function(){return _.each(_.any.apply(null,arguments),_.not(g.ctoken2("timeContext")));};g.day=_fn(g.d,g.dd);g.month=_fn(g.M,g.MMM);g.year=_fn(g.yyyy,g.yy);g.orientation=_.process(g.ctoken("past future"),function(s){return function(){this.orient=s;};});g.operator=_.process(g.ctoken("add subtract"),function(s){return function(){this.operator=s;};});g.rday=_.process(g.ctoken("yesterday tomorrow today now"),t.rday);g.unit=_.process(g.ctoken("second minute hour day week month year"),function(s){return function(){this.unit=s;};});g.value=_.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/),function(s){return function(){this.value=s.replace(/\D/g,"");};});g.expression=_.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);_fn=function(){return _.set(arguments,g.datePartDelimiter);};g.mdy=_fn(g.ddd,g.month,g.day,g.year);g.ymd=_fn(g.ddd,g.year,g.month,g.day);g.dmy=_fn(g.ddd,g.day,g.month,g.year);g.date=function(s){return((g[$C.dateElementOrder]||g.mdy).call(this,s));};g.format=_.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),function(fmt){if(g[fmt]){return g[fmt];}else{throw $D.Parsing.Exception(fmt);}}),_.process(_.rtoken(/^[^dMyhHmstz]+/),function(s){return _.ignore(_.stoken(s));}))),function(rules){return _.process(_.each.apply(null,rules),t.finishExact);});var _F={};var _get=function(f){return _F[f]=(_F[f]||g.format(f)[0]);};g.formats=function(fx){if(fx instanceof Array){var rx=[];for(var i=0;i<fx.length;i++){rx.push(_get(fx[i]));} | |||
return _.any.apply(null,rx);}else{return _get(fx);}};g._formats=g.formats(["\"yyyy-MM-ddTHH:mm:ssZ\"","yyyy-MM-ddTHH:mm:ssZ","yyyy-MM-ddTHH:mm:ssz","yyyy-MM-ddTHH:mm:ss","yyyy-MM-ddTHH:mmZ","yyyy-MM-ddTHH:mmz","yyyy-MM-ddTHH:mm","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","MMddyyyy","ddMMyyyy","Mddyyyy","ddMyyyy","Mdyyyy","dMyyyy","yyyy","Mdyy","dMyy","d"]);g._start=_.process(_.set([g.date,g.time,g.expression],g.generalDelimiter,g.whiteSpace),t.finish);g.start=function(s){try{var r=g._formats.call({},s);if(r[1].length===0){return r;}}catch(e){} | |||
return g._start.call({},s);};$D._parse=$D.parse;$D.parse=function(s){var r=null;if(!s){return null;} | |||
if(s instanceof Date){return s;} | |||
try{r=$D.Grammar.start.call({},s.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));}catch(e){return null;} | |||
return((r[1].length===0)?r[0]:null);};$D.getParseFunction=function(fx){var fn=$D.Grammar.formats(fx);return function(s){var r=null;try{r=fn.call({},s);}catch(e){return null;} | |||
return((r[1].length===0)?r[0]:null);};};$D.parseExact=function(s,fx){return $D.getParseFunction(fx)(s);};}()); |
@@ -0,0 +1,88 @@ | |||
package ${package}.${moduleName}.controller; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.xkcoding.common.R; | |||
import com.xkcoding.scaffold.log.annotations.ApiLog; | |||
import ${package}.${moduleName}.entity.${className}; | |||
import ${package}.${moduleName}.service.${className}Service; | |||
import lombok.AllArgsConstructor; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* <p> | |||
* ${comments} | |||
* </p> | |||
* | |||
* @package: ${package}.${moduleName}.controller | |||
* @description: ${comments} | |||
* @author: ${author} | |||
* @date: Created in ${datetime} | |||
* @copyright: Copyright (c) ${year} | |||
* @version: V1.0 | |||
* @modified: ${author} | |||
*/ | |||
@RestController | |||
@AllArgsConstructor | |||
@RequestMapping("/${pathName}") | |||
public class ${className}Controller { | |||
private final ${className}Service ${classname}Service; | |||
/** | |||
* 分页查询${comments} | |||
* @param page 分页对象 | |||
* @param ${classname} ${comments} | |||
* @return R | |||
*/ | |||
@GetMapping("") | |||
public R list${className}(Page page, ${className} ${classname}) { | |||
return new R<>(${classname}Service.page(page,Wrappers.query(${classname}))); | |||
} | |||
/** | |||
* 通过id查询${comments} | |||
* @param ${pk.lowerAttrName} id | |||
* @return R | |||
*/ | |||
@GetMapping("/{${pk.lowerAttrName}}") | |||
public R get${className}(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){ | |||
return new R<>(${classname}Service.getById(${pk.lowerAttrName})); | |||
} | |||
/** | |||
* 新增${comments} | |||
* @param ${classname} ${comments} | |||
* @return R | |||
*/ | |||
@ApiLog("新增${comments}") | |||
@PostMapping | |||
public R save${className}(@RequestBody ${className} ${classname}){ | |||
return new R<>(${classname}Service.save(${classname})); | |||
} | |||
/** | |||
* 修改${comments} | |||
* @param ${pk.lowerAttrName} id | |||
* @param ${classname} ${comments} | |||
* @return R | |||
*/ | |||
@ApiLog("修改${comments}") | |||
@PutMapping("/{${pk.lowerAttrName}}") | |||
public R update${className}(@PathVariable ${pk.attrType} ${pk.lowerAttrName}, @RequestBody ${className} ${classname}){ | |||
return new R<>(${classname}Service.updateById(${classname})); | |||
} | |||
/** | |||
* 通过id删除${comments} | |||
* @param ${pk.lowerAttrName} id | |||
* @return R | |||
*/ | |||
@ApiLog("删除${comments}") | |||
@DeleteMapping("/{${pk.lowerAttrName}}") | |||
public R delete${className}(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){ | |||
return new R<>(${classname}Service.removeById(${pk.lowerAttrName})); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package ${package}.${moduleName}.entity; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.baomidou.mybatisplus.extension.activerecord.Model; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
#if(${hasBigDecimal}) | |||
import java.math.BigDecimal; | |||
#end | |||
import java.io.Serializable; | |||
import java.time.LocalDateTime; | |||
/** | |||
* <p> | |||
* ${comments} | |||
* </p> | |||
* | |||
* @package: ${package}.${moduleName}.entity | |||
* @description: ${comments} | |||
* @author: ${author} | |||
* @date: Created in ${datetime} | |||
* @copyright: Copyright (c) ${year} | |||
* @version: V1.0 | |||
* @modified: ${author} | |||
*/ | |||
@Data | |||
@TableName("${tableName}") | |||
@EqualsAndHashCode(callSuper = true) | |||
public class ${className} extends Model<${className}> { | |||
private static final long serialVersionUID = 1L; | |||
#foreach ($column in $columns) | |||
/** | |||
* $column.comments | |||
*/ | |||
#if($column.columnName == $pk.columnName) | |||
@TableId | |||
#end | |||
private $column.attrType $column.lowerAttrName; | |||
#end | |||
} |
@@ -0,0 +1,23 @@ | |||
package ${package}.${moduleName}.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.springframework.stereotype.Component; | |||
import ${package}.${moduleName}.entity.${className}; | |||
/** | |||
* <p> | |||
* ${comments} | |||
* </p> | |||
* | |||
* @package: ${package}.${moduleName}.mapper | |||
* @description: ${comments} | |||
* @author: ${author} | |||
* @date: Created in ${datetime} | |||
* @copyright: Copyright (c) ${year} | |||
* @version: V1.0 | |||
* @modified: ${author} | |||
*/ | |||
@Component | |||
public interface ${className}Mapper extends BaseMapper<${className}> { | |||
} |
@@ -0,0 +1,13 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="${package}.${moduleName}.mapper.${className}Mapper"> | |||
<resultMap id="${classname}Map" type="${package}.${moduleName}.entity.${className}"> | |||
#foreach($column in $columns) | |||
#if($column.lowerAttrName==$pk.lowerAttrName) | |||
<id property="${pk.lowerAttrName}" jdbcType="${pk.dataType}" column="${pk.columnName}"/> | |||
#else | |||
<result property="${column.lowerAttrName}" jdbcType="${column.dataType}" column="${column.columnName}"/> | |||
#end | |||
#end | |||
</resultMap> | |||
</mapper> |
@@ -0,0 +1,21 @@ | |||
package ${package}.${moduleName}.service; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import ${package}.${moduleName}.entity.${className}; | |||
/** | |||
* <p> | |||
* ${comments} | |||
* </p> | |||
* | |||
* @package: ${package}.${moduleName}.service | |||
* @description: ${comments} | |||
* @author: ${author} | |||
* @date: Created in ${datetime} | |||
* @copyright: Copyright (c) ${year} | |||
* @version: V1.0 | |||
* @modified: ${author} | |||
*/ | |||
public interface ${className}Service extends IService<${className}> { | |||
} |
@@ -0,0 +1,25 @@ | |||
package ${package}.${moduleName}.service.impl; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import ${package}.${moduleName}.entity.${className}; | |||
import ${package}.${moduleName}.mapper.${className}Mapper; | |||
import ${package}.${moduleName}.service.${className}Service; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* <p> | |||
* ${comments} | |||
* </p> | |||
* | |||
* @package: ${package}.${moduleName}.service.impl | |||
* @description: ${comments} | |||
* @author: ${author} | |||
* @date: Created in ${datetime} | |||
* @copyright: Copyright (c) ${year} | |||
* @version: V1.0 | |||
* @modified: ${author} | |||
*/ | |||
@Service | |||
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements ${className}Service { | |||
} |
@@ -0,0 +1,60 @@ | |||
import request from '@/router/axios' | |||
/** | |||
* 分页查询${comments} | |||
* @param query 分页查询条件 | |||
*/ | |||
export function fetchList(query) { | |||
return request({ | |||
url: '/${moduleName}/${pathName}', | |||
method: 'get', | |||
params: query | |||
}) | |||
} | |||
/** | |||
* 新增${comments} | |||
* @param obj ${comments} | |||
*/ | |||
export function addObj(obj) { | |||
return request({ | |||
url: '/${moduleName}/${pathName}', | |||
method: 'post', | |||
data: obj | |||
}) | |||
} | |||
/** | |||
* 通过id查询${comments} | |||
* @param id 主键 | |||
*/ | |||
export function getObj(id) { | |||
return request({ | |||
url: '/${moduleName}/${pathName}/' + id, | |||
method: 'get' | |||
}) | |||
} | |||
/** | |||
* 通过id删除${comments} | |||
* @param id 主键 | |||
*/ | |||
export function delObj(id) { | |||
return request({ | |||
url: '/${moduleName}/${pathName}/' + id, | |||
method: 'delete' | |||
}) | |||
} | |||
/** | |||
* 修改${comments} | |||
* @param id 主键 | |||
* @param obj ${comments} | |||
*/ | |||
export function putObj(id, obj) { | |||
return request({ | |||
url: '/${moduleName}/${pathName}/' + id, | |||
method: 'put', | |||
data: obj | |||
}) | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.xkcoding.codegen; | |||
import cn.hutool.core.io.IoUtil; | |||
import cn.hutool.db.Entity; | |||
import com.xkcoding.codegen.common.PageResult; | |||
import com.xkcoding.codegen.entity.GenConfig; | |||
import com.xkcoding.codegen.entity.TableRequest; | |||
import com.xkcoding.codegen.service.CodeGenService; | |||
import lombok.SneakyThrows; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.OutputStream; | |||
/** | |||
* <p> | |||
* 代码生成service测试 | |||
* </p> | |||
* | |||
* @package: com.xkcoding.codegen | |||
* @description: 代码生成service测试 | |||
* @author: yangkai.shen | |||
* @date: Created in 2019-03-22 10:34 | |||
* @copyright: Copyright (c) 2019 | |||
* @version: V1.0 | |||
* @modified: yangkai.shen | |||
*/ | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
@Slf4j | |||
public class CodeGenServiceTest { | |||
@Autowired | |||
private CodeGenService codeGenService; | |||
@Test | |||
public void testTablePage() { | |||
TableRequest request = new TableRequest(); | |||
request.setCurrentPage(1); | |||
request.setPageSize(10); | |||
request.setUrl("jdbc:mysql://127.0.0.1:3306/spring-boot-demo"); | |||
request.setUsername("root"); | |||
request.setPassword("root"); | |||
request.setTableName("sec_"); | |||
PageResult<Entity> pageResult = codeGenService.listTables(request); | |||
log.info("【pageResult】= {}", pageResult); | |||
} | |||
@Test | |||
@SneakyThrows | |||
public void testGeneratorCode() { | |||
GenConfig config = new GenConfig(); | |||
TableRequest request = new TableRequest(); | |||
request.setUrl("127.0.0.1:3306/spring-boot-demo"); | |||
request.setUsername("root"); | |||
request.setPassword("root"); | |||
request.setTableName("shiro_user"); | |||
config.setRequest(request); | |||
config.setModuleName("shiro"); | |||
config.setAuthor("Yangkai.Shen"); | |||
config.setComments("用户角色信息"); | |||
config.setPackageName("com.xkcoding"); | |||
config.setTablePrefix("shiro_"); | |||
byte[] zip = codeGenService.generatorCode(config); | |||
OutputStream outputStream = new FileOutputStream(new File("/Users/yangkai.shen/Desktop/" + request.getTableName() + ".zip")); | |||
IoUtil.write(outputStream, true, zip); | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.xkcoding.codegen; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class SpringBootDemoCodegenApplicationTests { | |||
@Test | |||
public void contextLoads() { | |||
} | |||
} |