parent
333bda2c68
commit
86bfbb20d9
@ -0,0 +1,119 @@
|
|||||||
|
<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>
|
||||||
|
|
||||||
|
<groupId>com.wb</groupId>
|
||||||
|
<artifactId>dbtool</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.0.3.RELEASE</version>
|
||||||
|
<relativePath/>
|
||||||
|
</parent>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven</id>
|
||||||
|
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<layout>default</layout>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>3.14</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml-schemas</artifactId>
|
||||||
|
<version>3.14</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.oracle.driver</groupId>
|
||||||
|
<artifactId>odbc</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${basedir}/attach/ojdbc8.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<!-- 项目名称 -->
|
||||||
|
<finalName>dbtool</finalName>
|
||||||
|
<!-- 默认的主代码目录 -->
|
||||||
|
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/src/main/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/mpr/*.xml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*.bat</include>
|
||||||
|
</includes>
|
||||||
|
<targetPath>${project.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-resources-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,30 @@
|
|||||||
|
package xyz.wbsite.dbtool;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.JavaFxApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
public class Application extends SpringBootServletInitializer {
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
return application.sources(Application.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||||
|
executorService.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
JavaFxApplication.main(args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,91 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ChoiceBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class ConnectInfoController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ChoiceBox databaseType;
|
||||||
|
@FXML
|
||||||
|
private TextField driver;
|
||||||
|
@FXML
|
||||||
|
private TextField url;
|
||||||
|
@FXML
|
||||||
|
private TextField userName;
|
||||||
|
@FXML
|
||||||
|
private TextField password;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button test;
|
||||||
|
@FXML
|
||||||
|
private Button load;
|
||||||
|
@FXML
|
||||||
|
private Button cancel;
|
||||||
|
|
||||||
|
public ChoiceBox getDatabaseType() {
|
||||||
|
return databaseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabaseType(ChoiceBox databaseType) {
|
||||||
|
this.databaseType = databaseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(TextField url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getDriver() {
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDriver(TextField driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(TextField userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(TextField password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getTest() {
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTest(Button test) {
|
||||||
|
this.test = test;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getLoad() {
|
||||||
|
return load;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoad(Button load) {
|
||||||
|
this.load = load;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getCancel() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancel(Button cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class DbDetailController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField moduleComment;
|
||||||
|
@FXML
|
||||||
|
private TextField modulePrefix;
|
||||||
|
@FXML
|
||||||
|
private TextField moduleName;
|
||||||
|
|
||||||
|
public TextField getModuleName() {
|
||||||
|
return moduleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModuleName(TextField moduleName) {
|
||||||
|
this.moduleName = moduleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getModuleComment() {
|
||||||
|
return moduleComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModuleComment(TextField moduleComment) {
|
||||||
|
this.moduleComment = moduleComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getModulePrefix() {
|
||||||
|
return modulePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModulePrefix(TextField modulePrefix) {
|
||||||
|
this.modulePrefix = modulePrefix;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
|
||||||
|
public class GenerateOptionController {
|
||||||
|
|
||||||
|
private GenerateOptionListener listener;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private CheckBox springmvc;
|
||||||
|
@FXML
|
||||||
|
private CheckBox mybatis;
|
||||||
|
@FXML
|
||||||
|
private ToggleGroup type;
|
||||||
|
@FXML
|
||||||
|
private ToggleGroup db;
|
||||||
|
@FXML
|
||||||
|
private Button ok;
|
||||||
|
@FXML
|
||||||
|
private Button cancel;
|
||||||
|
|
||||||
|
public String getDataBase() {
|
||||||
|
RadioButton value = (RadioButton) db.selectedToggleProperty().getValue();
|
||||||
|
String name = value.textProperty().getValue();
|
||||||
|
return name.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenerateOptionListener getListener() {
|
||||||
|
return listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListener(GenerateOptionListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getSpringmvc() {
|
||||||
|
return springmvc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpringmvc(CheckBox springmvc) {
|
||||||
|
this.springmvc = springmvc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getMybatis() {
|
||||||
|
return mybatis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMybatis(CheckBox mybatis) {
|
||||||
|
this.mybatis = mybatis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
RadioButton value = (RadioButton) type.selectedToggleProperty().getValue();
|
||||||
|
String name = value.textProperty().getValue();
|
||||||
|
System.out.println(name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getOk() {
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOk(Button ok) {
|
||||||
|
this.ok = ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getCancel() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancel(Button cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,193 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.scene.control.TreeView;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.DirectoryChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import xyz.wbsite.dbtool.javafx.JavaFxApplication;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Project;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Dialog;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MainController {
|
||||||
|
private ProjectManager dBmanger = ManagerFactory.getdBManager();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TreeView dbtree;
|
||||||
|
@FXML
|
||||||
|
private Pane detail;
|
||||||
|
@FXML
|
||||||
|
private TableView feilds;
|
||||||
|
@FXML
|
||||||
|
private Button add;
|
||||||
|
@FXML
|
||||||
|
private Button sub;
|
||||||
|
@FXML
|
||||||
|
private CheckBox addSysFields;
|
||||||
|
|
||||||
|
private JavaFxApplication main;
|
||||||
|
|
||||||
|
public ProjectManager getdBmanger() {
|
||||||
|
return dBmanger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setdBmanger(ProjectManager dBmanger) {
|
||||||
|
this.dBmanger = dBmanger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFxApplication getMain() {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMain(JavaFxApplication main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getAdd() {
|
||||||
|
return add;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdd(Button add) {
|
||||||
|
this.add = add;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getSub() {
|
||||||
|
return sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getAddSysFields() {
|
||||||
|
return addSysFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddSysFields(CheckBox addSysFields) {
|
||||||
|
this.addSysFields = addSysFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSub(Button sub) {
|
||||||
|
this.sub = sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableView getFeilds() {
|
||||||
|
return feilds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeilds(TableView feilds) {
|
||||||
|
this.feilds = feilds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeView getDbtree() {
|
||||||
|
return dbtree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDbtree(TreeView dbtree) {
|
||||||
|
this.dbtree = dbtree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pane getDetail() {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDetail(Pane detail) {
|
||||||
|
this.detail = detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void showFileChooser(ActionEvent actionEvent) {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
File file = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if (file != null && file.exists()) {
|
||||||
|
dBmanger.setPath(file.getAbsolutePath());
|
||||||
|
dBmanger.invalidate();
|
||||||
|
main.loadingProjectTree();
|
||||||
|
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean doSave(ActionEvent actionEvent) {
|
||||||
|
if (dBmanger.getPath() == null || "".equals(dBmanger.getPath())) {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
File file = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dBmanger.setPath(file.getAbsolutePath());
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
dBmanger.save();
|
||||||
|
System.out.println("自动保存成功");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void save(ActionEvent actionEvent) {
|
||||||
|
doSave(actionEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void saveAs(ActionEvent actionEvent) {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
File file = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if (file != null) {
|
||||||
|
dBmanger.setPath(file.getAbsolutePath());
|
||||||
|
dBmanger.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void clear(ActionEvent actionEvent) {
|
||||||
|
Project project = dBmanger.getProject();
|
||||||
|
project = new Project();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void showConnectInfo(ActionEvent actionEvent) {
|
||||||
|
Dialog.showDBConnectInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void generate(ActionEvent actionEvent) {
|
||||||
|
if (!this.doSave(null)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (dBmanger.doCheck()) {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
directoryChooser.setInitialDirectory(new File(dBmanger.getPath()));
|
||||||
|
Stage stage = new Stage();
|
||||||
|
File file = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if (file != null) {
|
||||||
|
//展示生成方式
|
||||||
|
Dialog.showGenerateOption(new GenerateOptionListener() {
|
||||||
|
@Override
|
||||||
|
public void onGenerate(String option, DataBase dataBase) {
|
||||||
|
System.out.println("生成目录:" + file.getAbsolutePath());
|
||||||
|
dBmanger.generate(file.getAbsolutePath(), option, dataBase);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void generateApi(ActionEvent actionEvent) {
|
||||||
|
Dialog.showApi();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class ProjectDetailController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField projectName;
|
||||||
|
@FXML
|
||||||
|
private TextField projectBasePackage;
|
||||||
|
@FXML
|
||||||
|
private TextField projectAuthor;
|
||||||
|
|
||||||
|
|
||||||
|
public TextField getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(TextField projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getProjectBasePackage() {
|
||||||
|
return projectBasePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectBasePackage(TextField projectBasePackage) {
|
||||||
|
this.projectBasePackage = projectBasePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getProjectAuthor() {
|
||||||
|
return projectAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectAuthor(TextField projectAuthor) {
|
||||||
|
this.projectAuthor = projectAuthor;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,548 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.customview.DBCheckBoxTableCell;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Api;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Dialog;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Tool;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.scene.control.cell.TextFieldTableCell;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import javafx.util.converter.DefaultStringConverter;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class SdkInfoController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField modulePath;
|
||||||
|
@FXML
|
||||||
|
private TextField sdkPath;
|
||||||
|
@FXML
|
||||||
|
private Button selectModulePath;
|
||||||
|
@FXML
|
||||||
|
private Button selectSdkPath;
|
||||||
|
@FXML
|
||||||
|
private Button start;
|
||||||
|
@FXML
|
||||||
|
private Button cancel;
|
||||||
|
@FXML
|
||||||
|
private CheckBox All;
|
||||||
|
@FXML
|
||||||
|
private CheckBox api;
|
||||||
|
@FXML
|
||||||
|
private CheckBox create;
|
||||||
|
@FXML
|
||||||
|
private CheckBox delete;
|
||||||
|
@FXML
|
||||||
|
private CheckBox update;
|
||||||
|
@FXML
|
||||||
|
private CheckBox find;
|
||||||
|
@FXML
|
||||||
|
private CheckBox search;
|
||||||
|
@FXML
|
||||||
|
private CheckBox get;
|
||||||
|
@FXML
|
||||||
|
private CheckBox getAll;
|
||||||
|
@FXML
|
||||||
|
private TableView apis;
|
||||||
|
@FXML
|
||||||
|
private List<Api> data = new ArrayList<>();
|
||||||
|
|
||||||
|
public Button getSelectModulePath() {
|
||||||
|
return selectModulePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectModulePath(Button selectModulePath) {
|
||||||
|
this.selectModulePath = selectModulePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getSelectSdkPath() {
|
||||||
|
return selectSdkPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectSdkPath(Button selectSdkPath) {
|
||||||
|
this.selectSdkPath = selectSdkPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Api> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getSearch() {
|
||||||
|
return search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getAll() {
|
||||||
|
return All;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAll(CheckBox all) {
|
||||||
|
All = all;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearch(CheckBox search) {
|
||||||
|
this.search = search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getCreate() {
|
||||||
|
return create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getApi() {
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApi(CheckBox api) {
|
||||||
|
this.api = api;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreate(CheckBox create) {
|
||||||
|
this.create = create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getDelete() {
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelete(CheckBox delete) {
|
||||||
|
this.delete = delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getUpdate() {
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdate(CheckBox update) {
|
||||||
|
this.update = update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getFind() {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFind(CheckBox find) {
|
||||||
|
this.find = find;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getGet() {
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGet(CheckBox get) {
|
||||||
|
this.get = get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(List<Api> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getModulePath() {
|
||||||
|
return modulePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModulePath(TextField modulePath) {
|
||||||
|
this.modulePath = modulePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getSdkPath() {
|
||||||
|
return sdkPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSdkPath(TextField sdkPath) {
|
||||||
|
this.sdkPath = sdkPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStart(Button start) {
|
||||||
|
this.start = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getCancel() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancel(Button cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableView getApis() {
|
||||||
|
return apis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getGetAll() {
|
||||||
|
return getAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGetAll(CheckBox getAll) {
|
||||||
|
this.getAll = getAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApis(TableView apis) {
|
||||||
|
this.apis = apis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
File moduleFile = new File(modulePath.getText());
|
||||||
|
String module = moduleFile.getName();
|
||||||
|
|
||||||
|
if (moduleFile.exists()) {
|
||||||
|
data.clear();
|
||||||
|
File reqs = new File(moduleFile.getAbsolutePath() + File.separator + "req");
|
||||||
|
|
||||||
|
if (!reqs.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog.showProgress("扫描API...");
|
||||||
|
for (File req : reqs.listFiles()) {
|
||||||
|
Api api = new Api();
|
||||||
|
api.setReq(req);
|
||||||
|
api.setTargetRequest(req.getName().replace(".java", ""));
|
||||||
|
|
||||||
|
//查找依赖ent
|
||||||
|
List<String> entities = findEntities(req);
|
||||||
|
for (String entity : entities) {
|
||||||
|
api.getDepEnt().add(entity);
|
||||||
|
}
|
||||||
|
//查找依赖enums
|
||||||
|
List<String> enums = findEnums(req);
|
||||||
|
for (String anEnum : enums) {
|
||||||
|
api.getDepEnum().add(anEnum);
|
||||||
|
}
|
||||||
|
//查找依赖req
|
||||||
|
List<String> reqss = findReq(req);
|
||||||
|
for (String string : reqss) {
|
||||||
|
api.getDepReq().add(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
//找response
|
||||||
|
File rsp = new File(moduleFile.getAbsolutePath() + File.separator + "rsp" + File.separator + req.getName().replace("Request", "Response"));
|
||||||
|
if (rsp.exists()) {
|
||||||
|
api.setRsp(rsp);
|
||||||
|
api.setTargetResponse(rsp.getName().replace(".java", ""));
|
||||||
|
|
||||||
|
//查找依赖ent
|
||||||
|
List<String> entities_ = findEntities(rsp);
|
||||||
|
for (String entity : entities_) {
|
||||||
|
api.getDepEnt().add(entity);
|
||||||
|
}
|
||||||
|
//查找依赖enums
|
||||||
|
List<String> enums_ = findEnums(rsp);
|
||||||
|
for (String anEnum : enums_) {
|
||||||
|
api.getDepEnum().add(anEnum);
|
||||||
|
}
|
||||||
|
//查找依赖req
|
||||||
|
List<String> reqss_ = findReq(rsp);
|
||||||
|
for (String string : reqss_) {
|
||||||
|
api.getDepReq().add(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api.setMethod("api." + module + "." + Tool.camelToPoint(req.getName().replaceAll("Request\\.java", "")));
|
||||||
|
|
||||||
|
|
||||||
|
if (api.getTargetRequest().startsWith("Api")){
|
||||||
|
api.setCheck(true);
|
||||||
|
}else {
|
||||||
|
api.setCheck(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (api.getRsp() == null || !api.getRsp().exists()) {
|
||||||
|
api.setError("响应不存在");
|
||||||
|
api.setCheck(false);
|
||||||
|
}
|
||||||
|
for (String s : api.getDepReq()) {
|
||||||
|
File en = new File(moduleFile.getAbsolutePath() + File.separator + "req" + File.separator + s + ".java");
|
||||||
|
if (!en.exists()) {
|
||||||
|
api.setError("依赖的" + s + "(Request)不存在、");
|
||||||
|
api.setCheck(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : api.getDepEnt()) {
|
||||||
|
File en = new File(moduleFile.getAbsolutePath() + File.separator + "ent" + File.separator + s + ".java");
|
||||||
|
if (!en.exists()) {
|
||||||
|
api.setError("依赖的" + s + "(Entity)不存在、");
|
||||||
|
api.setCheck(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : api.getDepEnum()) {
|
||||||
|
File en = new File(moduleFile.getAbsolutePath() + File.separator + "enums" + File.separator + s + ".java");
|
||||||
|
if (!en.exists()) {
|
||||||
|
api.setError("依赖的" + s + "(Enum)不存在、");
|
||||||
|
api.setCheck(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.add(api);
|
||||||
|
initData();
|
||||||
|
}
|
||||||
|
Dialog.stopPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findEntities(File file) {
|
||||||
|
ArrayList<String> strings = new ArrayList<>();
|
||||||
|
InputStreamReader read = null;//考虑到编码格式
|
||||||
|
try {
|
||||||
|
read = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(read);
|
||||||
|
String line = null;
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
//指定字符串判断处
|
||||||
|
if (line.contains(".ent.")) {
|
||||||
|
Pattern compile = Pattern.compile(".*\\.ent\\.(.*);");
|
||||||
|
|
||||||
|
Matcher matcher = compile.matcher(line);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
String group = matcher.group(1);
|
||||||
|
strings.add(group);
|
||||||
|
// System.out.println(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findEnums(File file) {
|
||||||
|
ArrayList<String> strings = new ArrayList<>();
|
||||||
|
InputStreamReader read = null;//考虑到编码格式
|
||||||
|
try {
|
||||||
|
read = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(read);
|
||||||
|
String line = null;
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
//指定字符串判断处
|
||||||
|
if (line.contains(".enums.")) {
|
||||||
|
Pattern compile = Pattern.compile(".*\\.enums\\.(.*);");
|
||||||
|
|
||||||
|
Matcher matcher = compile.matcher(line);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
String group = matcher.group(1);
|
||||||
|
strings.add(group);
|
||||||
|
// System.out.println(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findReq(File file) {
|
||||||
|
ArrayList<String> strings = new ArrayList<>();
|
||||||
|
InputStreamReader read = null;//考虑到编码格式
|
||||||
|
try {
|
||||||
|
read = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(read);
|
||||||
|
String line = null;
|
||||||
|
Pattern compile1 = Pattern.compile(".*private\\s([a-zA-Z_]*Request)\\s[a-zA-Z_]*Request;.*");
|
||||||
|
Pattern compile2 = Pattern.compile(".*private\\sList<([a-zA-Z_]*Request)>\\s[a-zA-Z_]*Requests;.*");
|
||||||
|
Pattern compile3 = Pattern.compile(".*private\\sList<([a-zA-Z_]*Request)>\\s[a-zA-Z_]*RequestList;.*");
|
||||||
|
|
||||||
|
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
//携带一个Request
|
||||||
|
if (line.matches(".*private\\s([a-zA-Z_]*Request)\\s[a-zA-Z_]*Request;.*")) {
|
||||||
|
Matcher matcher = compile1.matcher(line);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
String group = matcher.group(1);
|
||||||
|
|
||||||
|
strings.add(group);
|
||||||
|
System.out.println(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//携带一个List<*Request> *Requests;
|
||||||
|
if (line.matches(".*private\\sList<([a-zA-Z_]*Request)>\\s[a-zA-Z_]*Requests;.*")) {
|
||||||
|
Matcher matcher = compile2.matcher(line);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
String group = matcher.group(1);
|
||||||
|
|
||||||
|
strings.add(group);
|
||||||
|
System.out.println(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//携带一个List<*Request> *RequestList;
|
||||||
|
if (line.matches(".*private\\sList<([a-zA-Z_]*Request)>\\s[a-zA-Z_]*RequestList;.*")) {
|
||||||
|
Matcher matcher = compile3.matcher(line);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
String group = matcher.group(1);
|
||||||
|
|
||||||
|
strings.add(group);
|
||||||
|
System.out.println(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void initData() {
|
||||||
|
apis.setEditable(true);
|
||||||
|
apis.setSortPolicy(new Callback<TableView, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean call(TableView param) {
|
||||||
|
//禁止点击列头排序
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ObservableList<TableColumn> columns = apis.getColumns();
|
||||||
|
columns.get(0).setCellValueFactory(new PropertyValueFactory("check"));
|
||||||
|
columns.get(0).setCellFactory(new Callback<TableColumn, TableCell>() {
|
||||||
|
@Override
|
||||||
|
public TableCell call(TableColumn param) {
|
||||||
|
final DBCheckBoxTableCell checkBoxTableCell = new DBCheckBoxTableCell();
|
||||||
|
DBCheckBoxTableCell.sCallback sCallback = checkBoxTableCell.new sCallback() {
|
||||||
|
@Override
|
||||||
|
public ObservableValue<Boolean> call(Integer param) {
|
||||||
|
super.call(param);
|
||||||
|
// if (data.get(param).isCheck()) {
|
||||||
|
// checkBoxTableCell.setInvalid(true);
|
||||||
|
// } else {
|
||||||
|
// checkBoxTableCell.setInvalid(false);
|
||||||
|
// }
|
||||||
|
if (data.get(param).isCheck()) {
|
||||||
|
return new SimpleBooleanProperty(true);
|
||||||
|
} else {
|
||||||
|
return new SimpleBooleanProperty(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkBoxTableCell.setSelectedStateCallback(sCallback);
|
||||||
|
checkBoxTableCell.setOnChangeListener(new ChangeListener<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
|
int param1 = checkBoxTableCell.getParam();
|
||||||
|
Api api = data.get(param1);
|
||||||
|
api.setCheck(newValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return checkBoxTableCell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
columns.get(1).setCellValueFactory(new PropertyValueFactory("error"));
|
||||||
|
columns.get(1).setCellFactory(new Callback<TableColumn, TableCell>() {
|
||||||
|
@Override
|
||||||
|
public TableCell call(TableColumn param) {
|
||||||
|
// param.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
|
||||||
|
// @Override
|
||||||
|
// public void handle(TableColumn.CellEditEvent event) {
|
||||||
|
// int row = event.getTablePosition().getRow();
|
||||||
|
// Api api = data.get(row);
|
||||||
|
// api.setReqName((String) event.getNewValue());
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
|
||||||
|
@Override
|
||||||
|
public void updateItem(Object item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
textFieldTableCell.setEditable(false);
|
||||||
|
return textFieldTableCell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
columns.get(2).setCellValueFactory(new PropertyValueFactory("targetRequest"));
|
||||||
|
columns.get(2).setCellFactory(new Callback<TableColumn, TableCell>() {
|
||||||
|
@Override
|
||||||
|
public TableCell call(TableColumn param) {
|
||||||
|
// param.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
|
||||||
|
// @Override
|
||||||
|
// public void handle(TableColumn.CellEditEvent event) {
|
||||||
|
// int row = event.getTablePosition().getRow();
|
||||||
|
// Api api = data.get(row);
|
||||||
|
// api.setTargetRequest((String) event.getNewValue());
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
|
||||||
|
@Override
|
||||||
|
public void updateItem(Object item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
textFieldTableCell.setEditable(false);
|
||||||
|
return textFieldTableCell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
columns.get(3).setCellValueFactory(new PropertyValueFactory("targetResponse"));
|
||||||
|
columns.get(3).setCellFactory(new Callback<TableColumn, TableCell>() {
|
||||||
|
@Override
|
||||||
|
public TableCell call(TableColumn param) {
|
||||||
|
// param.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
|
||||||
|
// @Override
|
||||||
|
// public void handle(TableColumn.CellEditEvent event) {
|
||||||
|
// int row = event.getTablePosition().getRow();
|
||||||
|
// Api api = data.get(row);
|
||||||
|
// api.setTargetResponse((String) event.getNewValue());
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
|
||||||
|
@Override
|
||||||
|
public void updateItem(Object item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
textFieldTableCell.setEditable(false);
|
||||||
|
return textFieldTableCell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
columns.get(4).setCellValueFactory(new PropertyValueFactory("method"));
|
||||||
|
columns.get(4).setCellFactory(new Callback<TableColumn, TableCell>() {
|
||||||
|
@Override
|
||||||
|
public TableCell call(TableColumn param) {
|
||||||
|
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
|
||||||
|
@Override
|
||||||
|
public void updateItem(Object item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
textFieldTableCell.setEditable(false);
|
||||||
|
return textFieldTableCell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ObservableList<Api> ObservableList = FXCollections.observableArrayList();
|
||||||
|
ObservableList.addAll(data);
|
||||||
|
apis.setItems(ObservableList);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.ctrl;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class TableDetailController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField tablename;
|
||||||
|
@FXML
|
||||||
|
private TextField tablecomment;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private CheckBox create;
|
||||||
|
@FXML
|
||||||
|
private CheckBox delete;
|
||||||
|
@FXML
|
||||||
|
private CheckBox update;
|
||||||
|
@FXML
|
||||||
|
private CheckBox find;
|
||||||
|
@FXML
|
||||||
|
private CheckBox get;
|
||||||
|
@FXML
|
||||||
|
private CheckBox search;
|
||||||
|
@FXML
|
||||||
|
private CheckBox getAll;
|
||||||
|
|
||||||
|
public CheckBox getCreate() {
|
||||||
|
return create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreate(CheckBox create) {
|
||||||
|
this.create = create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getDelete() {
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelete(CheckBox delete) {
|
||||||
|
this.delete = delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getUpdate() {
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdate(CheckBox update) {
|
||||||
|
this.update = update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getFind() {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFind(CheckBox find) {
|
||||||
|
this.find = find;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getGet() {
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGet(CheckBox get) {
|
||||||
|
this.get = get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getSearch() {
|
||||||
|
return search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearch(CheckBox search) {
|
||||||
|
this.search = search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox getGetAll() {
|
||||||
|
return getAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGetAll(CheckBox getAll) {
|
||||||
|
this.getAll = getAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getTablename() {
|
||||||
|
return tablename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTablename(TextField tablename) {
|
||||||
|
this.tablename = tablename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextField getTablecomment() {
|
||||||
|
return tablecomment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTablecomment(TextField tablecomment) {
|
||||||
|
this.tablecomment = tablecomment;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.customview;
|
||||||
|
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.cell.CheckBoxTableCell;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public class DBCheckBoxTableCell extends CheckBoxTableCell {
|
||||||
|
|
||||||
|
private CheckBox checkBox = null;
|
||||||
|
private int param = 0;
|
||||||
|
|
||||||
|
public DBCheckBoxTableCell() {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBCheckBoxTableCell(Callback getSelectedProperty) {
|
||||||
|
super(getSelectedProperty);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInvalid(boolean value) {
|
||||||
|
super.setDisable(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBCheckBoxTableCell(Callback getSelectedProperty, StringConverter converter) {
|
||||||
|
super(getSelectedProperty, converter);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class sCallback implements Callback<Integer, ObservableValue<Boolean>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObservableValue<Boolean> call(Integer param) {
|
||||||
|
DBCheckBoxTableCell.this.param = param;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParam() {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParam(int param) {
|
||||||
|
this.param = param;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnChangeListener(ChangeListener<Boolean> changeListener) {
|
||||||
|
checkBox.selectedProperty().addListener(changeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
Class<?> superclass = this.getClass().getSuperclass();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field field = superclass.getDeclaredField("checkBox");
|
||||||
|
field.setAccessible(true);
|
||||||
|
checkBox = (CheckBox) field.get(this);
|
||||||
|
checkBox.setFocusTraversable(false);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateItem(Object item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.enumeration;
|
||||||
|
|
||||||
|
|
||||||
|
public enum DataBase {
|
||||||
|
ORACLE,
|
||||||
|
MYSQL
|
||||||
|
}
|
@ -0,0 +1,240 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.enumeration;
|
||||||
|
|
||||||
|
public enum FieldType {
|
||||||
|
Boolean(0),
|
||||||
|
Byte(0),
|
||||||
|
Bytes(0),
|
||||||
|
Short(0),
|
||||||
|
Integer(0),
|
||||||
|
Long(0),
|
||||||
|
Float(0),
|
||||||
|
Double(0),
|
||||||
|
Character(0),
|
||||||
|
String_1(1),
|
||||||
|
String_10(10),
|
||||||
|
String_var(20, false),
|
||||||
|
String_var50(50),
|
||||||
|
String_var100(100),
|
||||||
|
String_var255(255),
|
||||||
|
String_var500(500),
|
||||||
|
String_var2500(2500),
|
||||||
|
String_var4000(4000),
|
||||||
|
String_super(0),
|
||||||
|
Date(0),
|
||||||
|
BigDecimal(0);
|
||||||
|
|
||||||
|
private int defaultLength;
|
||||||
|
private boolean fix = true;
|
||||||
|
|
||||||
|
public boolean isFix() {
|
||||||
|
return fix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultLength() {
|
||||||
|
return defaultLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultLength(int defaultLength) {
|
||||||
|
this.defaultLength = defaultLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldType(int defaultLength) {
|
||||||
|
this.defaultLength = defaultLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldType(int defaultLength, boolean fix) {
|
||||||
|
this.defaultLength = defaultLength;
|
||||||
|
this.fix = fix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FieldType parse(String str) {
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FieldType fieldType = null;
|
||||||
|
try {
|
||||||
|
fieldType = FieldType.valueOf(str);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
tryGetsimilar(str, 0);
|
||||||
|
}
|
||||||
|
if (fieldType == null) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
}
|
||||||
|
return fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FieldType parse(String str, int length) {
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FieldType fieldType = null;
|
||||||
|
try {
|
||||||
|
fieldType = FieldType.valueOf(str);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
fieldType = tryGetsimilar(str, length);
|
||||||
|
}
|
||||||
|
if (fieldType == null) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
}
|
||||||
|
return fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FieldType tryGetsimilar(String str, int length) {
|
||||||
|
if (str.contains("CHAR")) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if (str.contains("NUMBER")) {
|
||||||
|
|
||||||
|
} else if (str.contains("DATE")) {
|
||||||
|
return FieldType.Date;
|
||||||
|
} else if (str.contains("BLOB")) {
|
||||||
|
return FieldType.Bytes;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (Boolean.name().equals(this.name())) {
|
||||||
|
return "boolean";
|
||||||
|
} else if (Byte.name().equals(this.name())) {
|
||||||
|
return "byte";
|
||||||
|
} else if (Short.name().equals(this.name())) {
|
||||||
|
return "short";
|
||||||
|
} else if (Integer.name().equals(this.name())) {
|
||||||
|
return "int";
|
||||||
|
} else if (Long.name().equals(this.name())) {
|
||||||
|
return "long";
|
||||||
|
} else if (Float.name().equals(this.name())) {
|
||||||
|
return "float";
|
||||||
|
} else if (Double.name().equals(this.name())) {
|
||||||
|
return "double";
|
||||||
|
} else if (Character.name().equals(this.name())) {
|
||||||
|
return "char";
|
||||||
|
} else if (Date.name().equals(this.name())) {
|
||||||
|
return "Date";
|
||||||
|
} else if (Bytes.name().equals(this.name())) {
|
||||||
|
return "byte[]";
|
||||||
|
} else if (BigDecimal.name().equals(this.name())) {
|
||||||
|
return "BigDecimal";
|
||||||
|
} else if (String_1.name().equals(this.name())) {
|
||||||
|
return "String_1";
|
||||||
|
} else if (String_10.name().equals(this.name())) {
|
||||||
|
return "String_10";
|
||||||
|
} else if (String_var.name().equals(this.name())) {
|
||||||
|
return "String_var";
|
||||||
|
} else if (String_var50.name().equals(this.name())) {
|
||||||
|
return "String_var50";
|
||||||
|
} else if (String_var100.name().equals(this.name())) {
|
||||||
|
return "String_var100";
|
||||||
|
} else if (String_var255.name().equals(this.name())) {
|
||||||
|
return "String_var255";
|
||||||
|
} else if (String_var500.name().equals(this.name())) {
|
||||||
|
return "String_var500";
|
||||||
|
} else if (String_var2500.name().equals(this.name())) {
|
||||||
|
return "String_var2500";
|
||||||
|
} else if (String_var4000.name().equals(this.name())) {
|
||||||
|
return "String_var4000";
|
||||||
|
} else if (String_super.name().equals(this.name())) {
|
||||||
|
return "String_super";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String javaType() {
|
||||||
|
if (Boolean.name().equals(this.name())) {
|
||||||
|
return "Boolean";
|
||||||
|
} else if (Byte.name().equals(this.name())) {
|
||||||
|
return "Byte";
|
||||||
|
} else if (Short.name().equals(this.name())) {
|
||||||
|
return "Short";
|
||||||
|
} else if (Integer.name().equals(this.name())) {
|
||||||
|
return "Integer";
|
||||||
|
} else if (Long.name().equals(this.name())) {
|
||||||
|
return "Long";
|
||||||
|
} else if (Float.name().equals(this.name())) {
|
||||||
|
return "Float";
|
||||||
|
} else if (Double.name().equals(this.name())) {
|
||||||
|
return "Double";
|
||||||
|
} else if (Character.name().equals(this.name())) {
|
||||||
|
return "Character";
|
||||||
|
} else if (Date.name().equals(this.name())) {
|
||||||
|
return "Date";
|
||||||
|
} else if (Bytes.name().equals(this.name())) {
|
||||||
|
return "Byte[]";
|
||||||
|
} else if (BigDecimal.name().equals(this.name())) {
|
||||||
|
return "BigDecimal";
|
||||||
|
} else if (String_1.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_10.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var50.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var100.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var255.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var500.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var2500.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_var4000.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else if (String_super.name().equals(this.name())) {
|
||||||
|
return "String";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String jdbcType() {
|
||||||
|
if (Boolean.name().equals(this.name())) {
|
||||||
|
return "BIT";
|
||||||
|
} else if (Byte.name().equals(this.name())) {
|
||||||
|
return "TINYINT";
|
||||||
|
} else if (Short.name().equals(this.name())) {
|
||||||
|
return "SMALLINT";
|
||||||
|
} else if (Integer.name().equals(this.name())) {
|
||||||
|
return "INTEGER";
|
||||||
|
} else if (Long.name().equals(this.name())) {
|
||||||
|
return "BIGINT";
|
||||||
|
} else if (Float.name().equals(this.name())) {
|
||||||
|
return "FLOAT";
|
||||||
|
} else if (Double.name().equals(this.name())) {
|
||||||
|
return "DOUBLE";
|
||||||
|
} else if (Character.name().equals(this.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (Date.name().equals(this.name())) {
|
||||||
|
return "TIMESTAMP";
|
||||||
|
} else if (Bytes.name().equals(this.name())) {
|
||||||
|
return "BINARY";
|
||||||
|
} else if (BigDecimal.name().equals(this.name())) {
|
||||||
|
return "DECIMAL";
|
||||||
|
} else if (String_1.name().equals(this.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (String_10.name().equals(this.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (String_var.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_var50.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_var100.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_var255.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_var500.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_var2500.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_var4000.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (String_super.name().equals(this.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.listener;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
|
||||||
|
public interface GenerateOptionListener {
|
||||||
|
void onGenerate(String option,DataBase dataBase);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger;
|
||||||
|
|
||||||
|
import freemarker.cache.*;
|
||||||
|
import freemarker.template.*;
|
||||||
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.ui.freemarker.SpringTemplateLoader;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||||
|
import org.springframework.web.util.UriTemplate;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class FreeMarkerManager {
|
||||||
|
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||||
|
|
||||||
|
public FreeMarkerManager() {
|
||||||
|
freeMarkerConfigurer = new FreeMarkerConfigurer();
|
||||||
|
// 初始化一些配置
|
||||||
|
Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
|
||||||
|
cfg.setDefaultEncoding("UTF-8");
|
||||||
|
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||||
|
cfg.setNumberFormat("0.##");
|
||||||
|
|
||||||
|
MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(new TemplateLoader[]{
|
||||||
|
new ClassTemplateLoader(ClassUtils.getDefaultClassLoader(), "/modules"),
|
||||||
|
});
|
||||||
|
|
||||||
|
cfg.setTemplateLoader(multiTemplateLoader);
|
||||||
|
freeMarkerConfigurer.setConfiguration(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void outputTemp(File outfile, String template, Object model) {
|
||||||
|
try {
|
||||||
|
if (!outfile.exists()) {
|
||||||
|
outfile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取连接
|
||||||
|
Configuration configuration = freeMarkerConfigurer.getConfiguration();
|
||||||
|
//设置编码
|
||||||
|
configuration.setDefaultEncoding("UTF-8");
|
||||||
|
//获取ftl,由于已经在配置文件中配置了路径所以在这里直接写模板名称就可以
|
||||||
|
Template temp = configuration.getTemplate(template);
|
||||||
|
//输出文件路径
|
||||||
|
Writer wr = new OutputStreamWriter(new FileOutputStream(outfile),"UTF-8");
|
||||||
|
//写入
|
||||||
|
temp.process(model, wr);
|
||||||
|
//关闭流
|
||||||
|
wr.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (TemplateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.JavaFxApplication;
|
||||||
|
|
||||||
|
public class ManagerFactory {
|
||||||
|
private static XmlManager xmlManager = null;
|
||||||
|
private static ReflashManager reflashManager =null;
|
||||||
|
private static ProjectManager dBManager;
|
||||||
|
private static FreeMarkerManager freeMarkerManager;
|
||||||
|
|
||||||
|
static {
|
||||||
|
xmlManager = new XmlManager();
|
||||||
|
dBManager = new ProjectManager();
|
||||||
|
freeMarkerManager = new FreeMarkerManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProjectManager getdBManager() {
|
||||||
|
return dBManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FreeMarkerManager getFreeMarkerManager() {
|
||||||
|
return freeMarkerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static XmlManager getXmlManager() {
|
||||||
|
return xmlManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ReflashManager getReflashManager(JavaFxApplication main) {
|
||||||
|
if (reflashManager == null){
|
||||||
|
reflashManager = new ReflashManager(main);
|
||||||
|
}
|
||||||
|
return reflashManager;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,476 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger;
|
||||||
|
|
||||||
|
import org.springframework.boot.system.ApplicationHome;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.FieldType;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.callable.SDKCallable;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.callable.SpringBootCallable;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.*;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Dialog;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
public class ProjectManager {
|
||||||
|
|
||||||
|
public static boolean isUpdate = false;
|
||||||
|
private XmlManager xmlService;
|
||||||
|
public static AbstractDBmapper dBmapper;
|
||||||
|
public static String path;
|
||||||
|
private Project project = new Project();
|
||||||
|
|
||||||
|
public ProjectManager() {
|
||||||
|
xmlService = ManagerFactory.getXmlManager();
|
||||||
|
try {
|
||||||
|
ApplicationHome home = new ApplicationHome(getClass());
|
||||||
|
File jarFile = home.getSource();
|
||||||
|
this.path = jarFile.getParent() + File.separator + "project";
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
this.path = System.getProperty("user.home") + File.separator + "project";
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Module findDBByDBName(String name) {
|
||||||
|
for (Module md : project.getModules()) {
|
||||||
|
if (md.getModuleName().equals(name)) {
|
||||||
|
return md;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeDBByDBName(String name) {
|
||||||
|
for (Module md : project.getModules()) {
|
||||||
|
if (md.getModuleName().equals(name)) {
|
||||||
|
project.getModules().remove(md);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table findTableByTableName(Module md, String name) {
|
||||||
|
for (Table t : md.getTables()) {
|
||||||
|
if (t.getTableName().equals(name)) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table getNewTableName(Module md) {
|
||||||
|
String base = "NEW_TABLE";
|
||||||
|
String name = base;
|
||||||
|
int k = 0;
|
||||||
|
do {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < md.getTables().size(); i++) {
|
||||||
|
if (name.equals(md.getTables().get(i).getTableName())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i < md.getTables().size()) {
|
||||||
|
k++;
|
||||||
|
name = base + "_" + k;
|
||||||
|
} else {
|
||||||
|
Table table = new Table(name);
|
||||||
|
table.setTableComment("注释");
|
||||||
|
table.setCreate(true);
|
||||||
|
table.setDelete(true);
|
||||||
|
table.setUpdate(true);
|
||||||
|
table.setFind(true);
|
||||||
|
table.setGet(true);
|
||||||
|
table.setSearch(false);
|
||||||
|
table.setGetAll(false);
|
||||||
|
|
||||||
|
md.putTable(table);
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewModuleName() {
|
||||||
|
String base = "example";
|
||||||
|
String name = base;
|
||||||
|
int k = 0;
|
||||||
|
do {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < project.getModules().size(); i++) {
|
||||||
|
if (name.equals(project.getModules().get(i).getModuleName())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i < project.getModules().size()) {
|
||||||
|
k++;
|
||||||
|
name = base + k;
|
||||||
|
} else {
|
||||||
|
Module md = new Module(name);
|
||||||
|
md.setModuleName(name);
|
||||||
|
md.setModuleComment("注释");
|
||||||
|
project.putModule(md);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewFieldName(List<Field> fields) {
|
||||||
|
String base = "NEW_FIELD";
|
||||||
|
String name = base;
|
||||||
|
int k = 0;
|
||||||
|
do {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < fields.size(); i++) {
|
||||||
|
if (name.equals(fields.get(i).getFieldName())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i < fields.size()) {
|
||||||
|
k++;
|
||||||
|
name = base + "_" + k;
|
||||||
|
} else {
|
||||||
|
Field field = new Field(name);
|
||||||
|
field.setDefaultValue("NULL");
|
||||||
|
field.setIsQuery(false);
|
||||||
|
field.setIsMust(false);
|
||||||
|
field.setIsPrimaryKey(false);
|
||||||
|
field.setFieldType(FieldType.String_var50);
|
||||||
|
field.setFieldLength(FieldType.String_var50.getDefaultLength());
|
||||||
|
int j = 0;
|
||||||
|
for (; j < fields.size(); j++) {
|
||||||
|
if (fields.get(j).getFieldName().equals("ROW_VERSION")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fields.add(j, field);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Module> getMds() {
|
||||||
|
return project.getModules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
if (path != null && !path.equals(this.path)) {
|
||||||
|
this.path = path;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean doCheck() {
|
||||||
|
if (project.getProjectName() == null || "".equals(project.getProjectName())) {
|
||||||
|
Dialog.showConfirmDialog("没有填写项目名!");
|
||||||
|
return false;
|
||||||
|
} else if (project.getProjectBasePackage() == null || "".equals(project.getProjectBasePackage())) {
|
||||||
|
Dialog.showConfirmDialog("没有填写基本域名!");
|
||||||
|
return false;
|
||||||
|
} else if (project.getProjectAuthor() == null || "".equals(project.getProjectAuthor())) {
|
||||||
|
Dialog.showConfirmDialog("没有填写作者!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (Module md : project.getModules()) {
|
||||||
|
if (md.getModuleName() == null || "".equals(md.getModuleName())) {
|
||||||
|
Dialog.showConfirmDialog("项目" + project.getProjectName() + "没有填写模块名!");
|
||||||
|
return false;
|
||||||
|
} else if (md.getModuleComment() == null || "".equals(md.getModuleComment())) {
|
||||||
|
Dialog.showConfirmDialog("项目" + project.getProjectName() + "没有模块注释!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存配置文件
|
||||||
|
*/
|
||||||
|
public void save() {
|
||||||
|
if (path != null) {
|
||||||
|
File file = new File(path);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
xmlService.save(path, project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clear(File f) {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
File[] files = f.listFiles();
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
clear(file);
|
||||||
|
boolean delete = file.delete();
|
||||||
|
|
||||||
|
System.out.println("删除" + file.getName() + (delete ? "成功" : "失败"));
|
||||||
|
} else {
|
||||||
|
boolean delete = file.delete();
|
||||||
|
|
||||||
|
System.out.println("删除" + file.getName() + (delete ? "成功" : "失败"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExecutorService service = Executors.newFixedThreadPool(1);
|
||||||
|
|
||||||
|
public void tryGetDBmapper(DataBase dataBase) {
|
||||||
|
if (dataBase.name().equals(DataBase.MYSQL.name())) {
|
||||||
|
dBmapper = new MySqlDBmapper(dataBase);
|
||||||
|
} else if (dataBase.name().equals(DataBase.ORACLE.name())) {
|
||||||
|
dBmapper = new OracleDBmapper(dataBase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成模板 入口
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
|
public void generate(final String path, final String option, final DataBase dataBase) {
|
||||||
|
tryGetDBmapper(dataBase);
|
||||||
|
|
||||||
|
File root = new File(path);
|
||||||
|
if (!root.exists()) {
|
||||||
|
Dialog.showTimedDialog(1000, "目录不存在!");
|
||||||
|
}
|
||||||
|
Dialog.showProgress("生成中...");
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Callable callback = null;
|
||||||
|
switch (option) {
|
||||||
|
case "SpringBoot":
|
||||||
|
callback = new SpringBootCallable(path, dataBase, project, option);
|
||||||
|
break;
|
||||||
|
case "SpringMVC_Mybatis":
|
||||||
|
// callback = new SpringMVCMybatisCallable(path, dataBase, project, option);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future submit = service.submit(callback);
|
||||||
|
try {
|
||||||
|
submit.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Dialog.stopPopup();
|
||||||
|
Dialog.showSuccess("生成完成.");
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void generateSDK(File module, File sdk, List<Api> apis) {
|
||||||
|
if (module.exists()) {
|
||||||
|
boolean mkdirs = sdk.mkdirs();
|
||||||
|
File reqList = new File(module.getAbsolutePath() + File.separator + "req");
|
||||||
|
File rspList = new File(module.getAbsolutePath() + File.separator + "rsp");
|
||||||
|
File entList = new File(module.getAbsolutePath() + File.separator + "ent");
|
||||||
|
File enumsList = new File(module.getAbsolutePath() + File.separator + "enums");
|
||||||
|
SDKCallable sdkCallable = new SDKCallable(sdk, reqList, rspList, entList, enumsList, apis);
|
||||||
|
Future submit = service.submit(sdkCallable);
|
||||||
|
try {
|
||||||
|
Boolean b = (Boolean) submit.get();
|
||||||
|
if (!b) {
|
||||||
|
Dialog.showError("请确认目录结构是否存在或正确!");
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog.showSuccess("Api生成完成.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void invalidate() {
|
||||||
|
project = xmlService.inflate(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean testConnect(Map<String, String> properties) {
|
||||||
|
|
||||||
|
String url = properties.get("url");
|
||||||
|
String username = properties.get("username");
|
||||||
|
String password = properties.get("password");
|
||||||
|
String driverClassName = properties.get("driverClassName");
|
||||||
|
|
||||||
|
try {
|
||||||
|
//加载MySql的驱动类
|
||||||
|
Class.forName(driverClassName);
|
||||||
|
|
||||||
|
Connection cn = DriverManager.getConnection(url, username, password);
|
||||||
|
cn.close();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean loadMD(Map<String, String> properties) {
|
||||||
|
|
||||||
|
String type = properties.get("type");
|
||||||
|
String url = properties.get("url");
|
||||||
|
String username = properties.get("username");
|
||||||
|
String password = properties.get("password");
|
||||||
|
String driverClassName = properties.get("driverClassName");
|
||||||
|
Connection cn = null;
|
||||||
|
|
||||||
|
if ("Orcale".equals(type)) {
|
||||||
|
try {
|
||||||
|
dBmapper = new OracleDBmapper(DataBase.ORACLE);
|
||||||
|
|
||||||
|
//加载驱动类
|
||||||
|
Class.forName(driverClassName);
|
||||||
|
cn = DriverManager.getConnection(url, username, password);
|
||||||
|
|
||||||
|
Module md = new Module(username);
|
||||||
|
//查询所有表
|
||||||
|
Statement statement = cn.createStatement();
|
||||||
|
ResultSet rs = statement.executeQuery("select t.table_name,c.comments from user_tables t LEFT JOIN user_tab_comments c ON t.table_name = c.table_name ORDER BY T .table_name");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Table table = new Table(rs.getString("table_name"), rs.getString("comments"));
|
||||||
|
md.putTable(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
String sql = "SELECT T.*,CASE WHEN C.POSITION='1' THEN '1' ELSE '0' END PrimaryKey FROM(select A.COLUMN_ID,A.COLUMN_NAME,A.DATA_TYPE,A.DATA_LENGTH,A .DATA_PRECISION,A .DATA_SCALE,A.NULLABLE,A.DATA_DEFAULT,B.comments from user_tab_columns A ,user_col_comments B where A.Table_Name='" + table.getTableName() + "' AND B.Table_Name='" + table.getTableName() + "' AND A.COLUMN_NAME=B.COLUMN_NAME) T LEFT JOIN user_cons_columns C ON T.COLUMN_NAME = C.COLUMN_NAME AND POSITION = '1' AND C.Table_Name='" + table.getTableName() + "' ORDER BY T .COLUMN_ID";
|
||||||
|
ResultSet set = statement.executeQuery(sql);
|
||||||
|
|
||||||
|
while (set.next()) {
|
||||||
|
Field field = new Field();
|
||||||
|
|
||||||
|
field.setFieldName(set.getString("COLUMN_NAME"));
|
||||||
|
|
||||||
|
String data_type = set.getString("DATA_TYPE");
|
||||||
|
int data_length = set.getInt("DATA_LENGTH");
|
||||||
|
int data_precision = set.getInt("DATA_PRECISION");
|
||||||
|
int data_scale = set.getInt("DATA_SCALE");
|
||||||
|
field.setFieldType(dBmapper.getType(data_type, data_length, data_precision, data_scale));
|
||||||
|
field.setFieldLength(set.getInt("DATA_LENGTH"));
|
||||||
|
String nullable = set.getString("NULLABLE");
|
||||||
|
field.setDefaultValue(set.getString("DATA_DEFAULT"));
|
||||||
|
field.setFieldComment(set.getString("COMMENTS"));
|
||||||
|
if ("N".equals(nullable)) {
|
||||||
|
field.setIsMust(true);
|
||||||
|
} else {
|
||||||
|
field.setIsMust(false);
|
||||||
|
}
|
||||||
|
String primarykey = set.getString("PRIMARYKEY");
|
||||||
|
if ("1".equals(primarykey)) {
|
||||||
|
field.setIsPrimaryKey(true);
|
||||||
|
} else {
|
||||||
|
field.setIsPrimaryKey(false);
|
||||||
|
}
|
||||||
|
field.setIsQuery(false);
|
||||||
|
|
||||||
|
table.putField(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ManagerFactory.getdBManager().project.putModule(md);
|
||||||
|
isUpdate = true;
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
cn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ("Mysql".equals(type)) {
|
||||||
|
try {
|
||||||
|
dBmapper = new MySqlDBmapper(DataBase.MYSQL);
|
||||||
|
|
||||||
|
//加载驱动类
|
||||||
|
Class.forName(driverClassName);
|
||||||
|
cn = DriverManager.getConnection(url, username, password);
|
||||||
|
|
||||||
|
String[] split = url.split("/");
|
||||||
|
String dbName = split[split.length - 1];
|
||||||
|
|
||||||
|
Module md = new Module(dbName);
|
||||||
|
//查询所有表
|
||||||
|
Statement statement = cn.createStatement();
|
||||||
|
ResultSet rs = statement.executeQuery("SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" + dbName + "'");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Table table = new Table(rs.getString("TABLE_NAME"), rs.getString("TABLE_COMMENT"));
|
||||||
|
md.putTable(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
String sql = "select COLUMN_NAME,COLUMN_COMMENT,COLUMN_KEY,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE, COLUMN_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.COLUMNS where table_name = '" + table.getTableName() + "' and table_schema = '" + dbName + "' ORDER BY ORDINAL_POSITION ASC";
|
||||||
|
ResultSet set = statement.executeQuery(sql);
|
||||||
|
|
||||||
|
while (set.next()) {
|
||||||
|
Field field = new Field();
|
||||||
|
|
||||||
|
field.setFieldName(set.getString("COLUMN_NAME"));
|
||||||
|
|
||||||
|
if ("NO".equals(set.getString("IS_NULLABLE"))) {
|
||||||
|
field.setIsMust(true);
|
||||||
|
} else {
|
||||||
|
field.setIsMust(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("PRI".equals(set.getString("COLUMN_KEY"))) {
|
||||||
|
field.setIsPrimaryKey(true);
|
||||||
|
} else {
|
||||||
|
field.setIsPrimaryKey(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
String data_type = set.getString("DATA_TYPE");
|
||||||
|
int data_length = set.getInt("CHARACTER_MAXIMUM_LENGTH");
|
||||||
|
field.setFieldType(dBmapper.getType(data_type, data_length, 0, 0));
|
||||||
|
field.setFieldLength(0);
|
||||||
|
if ("varchar".equals(data_type) || "char".equals(data_type)) {
|
||||||
|
int length = Integer.parseInt(set.getString("CHARACTER_MAXIMUM_LENGTH"));
|
||||||
|
field.setFieldLength(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
field.setDefaultValue(set.getString("COLUMN_DEFAULT"));
|
||||||
|
field.setFieldComment(set.getString("COLUMN_COMMENT"));
|
||||||
|
|
||||||
|
field.setIsQuery(false);
|
||||||
|
|
||||||
|
table.putField(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ManagerFactory.getdBManager().project.putModule(md);
|
||||||
|
isUpdate = true;
|
||||||
|
return true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.JavaFxApplication;
|
||||||
|
|
||||||
|
public class ReflashManager extends Thread{
|
||||||
|
private JavaFxApplication main;
|
||||||
|
|
||||||
|
public ReflashManager(JavaFxApplication main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true){
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (ProjectManager.isUpdate){
|
||||||
|
main.loadingProjectTree();
|
||||||
|
ProjectManager.isUpdate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,295 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.FieldType;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Field;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Module;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Project;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Table;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class XmlManager {
|
||||||
|
|
||||||
|
public Project inflate(String path) {
|
||||||
|
Project project = new Project();
|
||||||
|
|
||||||
|
if (path == null || "".equals(path)) {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
File file = new File(path);
|
||||||
|
if (!file.exists()) {
|
||||||
|
System.err.println("目录不存在!");
|
||||||
|
} else {
|
||||||
|
File dbFile = new File(path);
|
||||||
|
|
||||||
|
if (!dbFile.exists()) {
|
||||||
|
dbFile.mkdir();
|
||||||
|
} else {
|
||||||
|
File[] files = dbFile.listFiles(new FilenameFilter() {
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.endsWith(".xml") || name.endsWith(".XML");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//开始解析
|
||||||
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
for (File xml : files) {
|
||||||
|
FileInputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(xml);
|
||||||
|
Document document = documentBuilderFactory.newDocumentBuilder().parse(inputStream);
|
||||||
|
|
||||||
|
Element dbElement = document.getDocumentElement();
|
||||||
|
|
||||||
|
if ("project".endsWith(dbElement.getNodeName())) {
|
||||||
|
System.out.println("发现项目:" + xml.getName());
|
||||||
|
|
||||||
|
NodeList projectName = dbElement.getElementsByTagName("projectName");
|
||||||
|
if (projectName.getLength() == 1) {
|
||||||
|
project.setProjectName(projectName.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList projectBasePackage = dbElement.getElementsByTagName("projectBasePackage");
|
||||||
|
if (projectBasePackage.getLength() == 1) {
|
||||||
|
project.setProjectBasePackage(projectBasePackage.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList projectAuthor = dbElement.getElementsByTagName("projectAuthor");
|
||||||
|
if (projectAuthor.getLength() == 1) {
|
||||||
|
project.setProjectAuthor(projectAuthor.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList modules = dbElement.getElementsByTagName("module");
|
||||||
|
if (modules.getLength() > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < modules.getLength(); i++) {
|
||||||
|
Module module = new Module();
|
||||||
|
Element moduleElement = (Element) modules.item(i);
|
||||||
|
|
||||||
|
NodeList moduleName = moduleElement.getElementsByTagName("moduleName");
|
||||||
|
if (moduleName.getLength() == 1) {
|
||||||
|
module.setModuleName(moduleName.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList moduleComment = moduleElement.getElementsByTagName("moduleComment");
|
||||||
|
if (moduleComment.getLength() == 1) {
|
||||||
|
module.setModuleComment(moduleComment.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList modulePrefix = moduleElement.getElementsByTagName("modulePrefix");
|
||||||
|
if (modulePrefix.getLength() == 1) {
|
||||||
|
module.setModulePrefix(modulePrefix.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList hasSysFields = moduleElement.getElementsByTagName("hasSysFields");
|
||||||
|
if (hasSysFields.getLength() == 1) {
|
||||||
|
module.setHasSysFields(Boolean.parseBoolean(hasSysFields.item(0).getTextContent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList tables = moduleElement.getElementsByTagName("table");
|
||||||
|
if (tables.getLength() > 0) {
|
||||||
|
for (int j = 0; j < tables.getLength(); j++) {
|
||||||
|
Element tableElement = (Element) tables.item(j);
|
||||||
|
Table table = new Table();
|
||||||
|
table.setdBhandle(module);
|
||||||
|
table.setTableName(tableElement.getAttribute("tableName"));
|
||||||
|
table.setTableComment(tableElement.getAttribute("tableComment"));
|
||||||
|
table.setCreate(Boolean.parseBoolean(tableElement.getAttribute("create")));
|
||||||
|
table.setDelete(Boolean.parseBoolean(tableElement.getAttribute("delete")));
|
||||||
|
table.setUpdate(Boolean.parseBoolean(tableElement.getAttribute("update")));
|
||||||
|
table.setFind(Boolean.parseBoolean(tableElement.getAttribute("find")));
|
||||||
|
table.setGet(Boolean.parseBoolean(tableElement.getAttribute("get")));
|
||||||
|
table.setSearch(Boolean.parseBoolean(tableElement.getAttribute("search")));
|
||||||
|
table.setGetAll(Boolean.parseBoolean(tableElement.getAttribute("getAll")));
|
||||||
|
|
||||||
|
NodeList fields = tableElement.getElementsByTagName("field");
|
||||||
|
|
||||||
|
if (fields.getLength() > 0) {
|
||||||
|
for (int k = 0; k < fields.getLength(); k++) {
|
||||||
|
Element fieldElement = (Element) fields.item(k);
|
||||||
|
Field field = new Field();
|
||||||
|
field.setFieldName(fieldElement.getAttribute("fieldName"));
|
||||||
|
field.setFieldType(FieldType.parse(fieldElement.getAttribute("fieldType")));
|
||||||
|
field.setFieldLength(Integer.parseInt(fieldElement.getAttribute("fieldLength")));
|
||||||
|
field.setFieldComment(fieldElement.getAttribute("fieldComment"));
|
||||||
|
field.setDefaultValue(fieldElement.getAttribute("defaultValue"));
|
||||||
|
field.setIsSystem(Boolean.parseBoolean(fieldElement.getAttribute("IsSystem")));
|
||||||
|
field.setIsMust(Boolean.parseBoolean(fieldElement.getAttribute("isMust")));
|
||||||
|
field.setIsPrimaryKey(Boolean.parseBoolean(fieldElement.getAttribute("isPrimaryKey")));
|
||||||
|
field.setIsQuery(Boolean.parseBoolean(fieldElement.getAttribute("isQuery")));
|
||||||
|
field.setIsSearch(Boolean.parseBoolean(fieldElement.getAttribute("isSearch")));
|
||||||
|
table.putField(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.putTable(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
project.putModule(module);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("数据初始化成功...");
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("文件:'" + xml.getName() + "'解析失败!请检查语法是否正确!");
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveAs(String path, Project project) {
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder;
|
||||||
|
//生成DOM模型
|
||||||
|
try {
|
||||||
|
builder = dbFactory.newDocumentBuilder();
|
||||||
|
Document doc = builder.newDocument();
|
||||||
|
|
||||||
|
Element rootProject = doc.createElement("project");
|
||||||
|
doc.appendChild(rootProject);
|
||||||
|
|
||||||
|
Element projectName = doc.createElement("projectName");
|
||||||
|
projectName.setTextContent(project.getProjectName());
|
||||||
|
Element projectBasePackage = doc.createElement("projectBasePackage");
|
||||||
|
projectBasePackage.setTextContent(project.getProjectBasePackage());
|
||||||
|
Element projectAuthor = doc.createElement("projectAuthor");
|
||||||
|
projectAuthor.setTextContent(project.getProjectAuthor());
|
||||||
|
rootProject.appendChild(projectName);
|
||||||
|
rootProject.appendChild(projectBasePackage);
|
||||||
|
rootProject.appendChild(projectAuthor);
|
||||||
|
|
||||||
|
Element modules = doc.createElement("modules");
|
||||||
|
rootProject.appendChild(modules);
|
||||||
|
|
||||||
|
//region Description
|
||||||
|
for (Module md : project.getModules()) {
|
||||||
|
Element module = doc.createElement("module");
|
||||||
|
|
||||||
|
Element moduleName = doc.createElement("moduleName");
|
||||||
|
Element moduleComment = doc.createElement("moduleComment");
|
||||||
|
Element modulePrefix = doc.createElement("modulePrefix");
|
||||||
|
Element hasSysFields = doc.createElement("hasSysFields");
|
||||||
|
moduleName.setTextContent(md.getModuleName());
|
||||||
|
moduleComment.setTextContent(md.getModuleComment());
|
||||||
|
modulePrefix.setTextContent(md.getModulePrefix());
|
||||||
|
hasSysFields.setTextContent(String.valueOf(md.isHasSysFields()));
|
||||||
|
module.appendChild(moduleComment);
|
||||||
|
module.appendChild(modulePrefix);
|
||||||
|
module.appendChild(moduleName);
|
||||||
|
module.appendChild(hasSysFields);
|
||||||
|
|
||||||
|
Element tables = doc.createElement("tables");
|
||||||
|
module.appendChild(tables);
|
||||||
|
for (Table t : md.getTables()) {
|
||||||
|
Element table = doc.createElement("table");
|
||||||
|
table.setAttribute("tableName", t.getTableName());
|
||||||
|
table.setAttribute("tableComment", t.getTableComment());
|
||||||
|
table.setAttribute("create", t.getCreate().toString());
|
||||||
|
table.setAttribute("delete", t.getDelete().toString());
|
||||||
|
table.setAttribute("update", t.getUpdate().toString());
|
||||||
|
table.setAttribute("find", t.getFind().toString());
|
||||||
|
table.setAttribute("get", t.getGet().toString());
|
||||||
|
table.setAttribute("search", t.getSearch().toString());
|
||||||
|
table.setAttribute("getAll", t.getGetAll().toString());
|
||||||
|
|
||||||
|
Element fields = doc.createElement("fields");
|
||||||
|
|
||||||
|
table.appendChild(fields);
|
||||||
|
|
||||||
|
for (Field f : t.getFields()) {
|
||||||
|
Element field = doc.createElement("field");
|
||||||
|
field.setAttribute("fieldName", f.getFieldName());
|
||||||
|
if (f.getFieldType() != null) {
|
||||||
|
field.setAttribute("fieldType", f.getFieldType().name());
|
||||||
|
}
|
||||||
|
if (f.getFieldLength() != null) {
|
||||||
|
field.setAttribute("fieldLength", f.getFieldLength().toString());
|
||||||
|
}
|
||||||
|
field.setAttribute("fieldComment", f.getFieldComment());
|
||||||
|
field.setAttribute("defaultValue", f.getDefaultValue());
|
||||||
|
if (f.getIsMust() != null) {
|
||||||
|
field.setAttribute("isMust", f.getIsMust().toString());
|
||||||
|
}
|
||||||
|
field.setAttribute("isQuery", f.getIsQuery().toString());
|
||||||
|
field.setAttribute("isSearch", f.getIsSearch().toString());
|
||||||
|
if (f.getIsPrimaryKey() != null) {
|
||||||
|
field.setAttribute("isPrimaryKey", f.getIsPrimaryKey().toString());
|
||||||
|
}
|
||||||
|
if (f.getIsSystem() != null) {
|
||||||
|
field.setAttribute("IsSystem", f.getIsSystem().toString());
|
||||||
|
}
|
||||||
|
fields.appendChild(field);
|
||||||
|
}
|
||||||
|
tables.appendChild(table);
|
||||||
|
}
|
||||||
|
modules.appendChild(module);
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//输出文件
|
||||||
|
FileOutputStream stream = null;
|
||||||
|
try {
|
||||||
|
Transformer t = TransformerFactory.newInstance().newTransformer();
|
||||||
|
|
||||||
|
//设置换行和缩进
|
||||||
|
t.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
t.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||||
|
|
||||||
|
File dbFile = new File(path);
|
||||||
|
if (!dbFile.exists()) {
|
||||||
|
dbFile.mkdirs();
|
||||||
|
}
|
||||||
|
File file = new File(dbFile.getAbsolutePath() + File.separator + project.getProjectName() + ".xml");
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
stream = new FileOutputStream(file);
|
||||||
|
t.transform(new DOMSource(doc), new StreamResult(stream));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
if (stream != null) {
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean save(String path, Project project) {
|
||||||
|
File projectFile = new File(path);
|
||||||
|
saveAs(projectFile.getAbsolutePath(), project);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,748 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger.callable;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Api;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.JavaClassReader;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.JavaEnumReader;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Tool;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
|
||||||
|
|
||||||
|
public class SDKCallable implements Callable {
|
||||||
|
|
||||||
|
private File sdk;
|
||||||
|
private File req;
|
||||||
|
private File rsp;
|
||||||
|
private File ent;
|
||||||
|
private File enums;
|
||||||
|
private List<Api> apis;
|
||||||
|
private Tool tool = new Tool();
|
||||||
|
|
||||||
|
private FreeMarkerManager freeMarkerManager;
|
||||||
|
|
||||||
|
public SDKCallable(File sdk, File req, File rsp, File ent, File enums, List<Api> apis) {
|
||||||
|
this.sdk = sdk;
|
||||||
|
this.req = req;
|
||||||
|
this.rsp = rsp;
|
||||||
|
this.ent = ent;
|
||||||
|
this.enums = enums;
|
||||||
|
this.apis = apis;
|
||||||
|
this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AbstractDBmapper dBmapper;
|
||||||
|
|
||||||
|
public Boolean call() throws Exception {
|
||||||
|
if (!sdk.exists()) {
|
||||||
|
sdk.mkdir();
|
||||||
|
} else {
|
||||||
|
clear(sdk);
|
||||||
|
}
|
||||||
|
|
||||||
|
dBmapper = ProjectManager.dBmapper;
|
||||||
|
|
||||||
|
{
|
||||||
|
System.out.println("生成模块:Pom");
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("sdk", sdk.getName().toLowerCase());
|
||||||
|
File file = new File(sdk.getAbsolutePath() + File.separator + "pom.xml");
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/pom.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
File frameWork = null;
|
||||||
|
String domain = null;
|
||||||
|
String module = null;
|
||||||
|
Set<String> managerList = new HashSet<>();
|
||||||
|
List<Method> methodList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Api api : apis) {
|
||||||
|
if (api.isCheck()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
//region 生成request
|
||||||
|
JavaClassReader javaClassReader = new JavaClassReader(api.getReq());
|
||||||
|
|
||||||
|
Method method = new Method();
|
||||||
|
method.setStringMethod(api.getMethod());
|
||||||
|
method.setRequest(javaClassReader.getClassName());
|
||||||
|
method.setTarget(Tool.getRequestTarget(javaClassReader.getClassName()));
|
||||||
|
method.setMethod(Tool.getRequestAction(javaClassReader.getClassName()));
|
||||||
|
method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager");
|
||||||
|
methodList.add(method);
|
||||||
|
StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
stringBuffer.append("src" + File.separator);
|
||||||
|
stringBuffer.append("main" + File.separator);
|
||||||
|
stringBuffer.append("java" + File.separator);
|
||||||
|
|
||||||
|
String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
|
||||||
|
managerList.add(method.getManager());
|
||||||
|
|
||||||
|
for (String s1 : split) {
|
||||||
|
stringBuffer.append(s1 + File.separator);
|
||||||
|
}
|
||||||
|
if (frameWork == null) {
|
||||||
|
frameWork = new File(stringBuffer.toString());
|
||||||
|
frameWork.mkdirs();
|
||||||
|
}
|
||||||
|
if (domain == null) {
|
||||||
|
domain = javaClassReader.getDomainName();
|
||||||
|
}
|
||||||
|
if (module == null) {
|
||||||
|
module = javaClassReader.getModuleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
|
||||||
|
File request = new File(stringBuffer.toString() + File.separator + "request");
|
||||||
|
request.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
ctx.put("className", javaClassReader.getClassName().replaceAll("Request", ""));
|
||||||
|
ctx.put("body", javaClassReader.getBody());
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
ctx.put("hasList", javaClassReader.isHasList());
|
||||||
|
ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag());
|
||||||
|
File file = new File(request.getAbsolutePath() + File.separator + api.getReq().getName());
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/request/request.ftl", ctx);
|
||||||
|
System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
//region 生成response
|
||||||
|
JavaClassReader javaClassReader = new JavaClassReader(api.getRsp());
|
||||||
|
|
||||||
|
StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
stringBuffer.append("src" + File.separator);
|
||||||
|
stringBuffer.append("main" + File.separator);
|
||||||
|
stringBuffer.append("java" + File.separator);
|
||||||
|
|
||||||
|
String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
|
||||||
|
|
||||||
|
for (String s1 : split) {
|
||||||
|
stringBuffer.append(s1 + File.separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
|
||||||
|
File response = new File(stringBuffer.toString() + File.separator + "response");
|
||||||
|
response.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
ctx.put("className", javaClassReader.getClassName().replaceAll("Response", ""));
|
||||||
|
ctx.put("body", javaClassReader.getBody());
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
ctx.put("hasList", javaClassReader.isHasList());
|
||||||
|
ctx.put("Tclass", javaClassReader.getTclass());
|
||||||
|
File file = new File(response.getAbsolutePath() + File.separator + api.getRsp().getName().replaceAll("Request", "Response"));
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/response/response.ftl", ctx);
|
||||||
|
System.out.println("生成文件" + api.getRsp().getName() + "成功");
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : api.getDepReq()) {
|
||||||
|
try {
|
||||||
|
File f = new File(req.getAbsolutePath() + File.separator + s + ".java");
|
||||||
|
if (!f.exists()) {
|
||||||
|
System.err.println("文件" + f.getAbsolutePath() + "不存在");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JavaClassReader javaClassReader = new JavaClassReader(f);
|
||||||
|
|
||||||
|
Method method = new Method();
|
||||||
|
method.setStringMethod(api.getMethod());
|
||||||
|
method.setRequest(javaClassReader.getClassName());
|
||||||
|
method.setTarget(Tool.getRequestTarget(javaClassReader.getClassName()));
|
||||||
|
method.setMethod(Tool.getRequestAction(javaClassReader.getClassName()));
|
||||||
|
method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager");
|
||||||
|
|
||||||
|
StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
stringBuffer.append("src" + File.separator);
|
||||||
|
stringBuffer.append("main" + File.separator);
|
||||||
|
stringBuffer.append("java" + File.separator);
|
||||||
|
|
||||||
|
String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
|
||||||
|
for (String s1 : split) {
|
||||||
|
stringBuffer.append(s1 + File.separator);
|
||||||
|
}
|
||||||
|
if (frameWork == null) {
|
||||||
|
frameWork = new File(stringBuffer.toString());
|
||||||
|
frameWork.mkdirs();
|
||||||
|
}
|
||||||
|
if (domain == null) {
|
||||||
|
domain = javaClassReader.getDomainName();
|
||||||
|
}
|
||||||
|
if (module == null) {
|
||||||
|
module = javaClassReader.getModuleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
|
||||||
|
File request = new File(stringBuffer.toString() + File.separator + "request");
|
||||||
|
request.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
ctx.put("className", javaClassReader.getClassName().replaceAll("Request", ""));
|
||||||
|
ctx.put("body", javaClassReader.getBody());
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
ctx.put("hasList", javaClassReader.isHasList());
|
||||||
|
ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag());
|
||||||
|
File file = new File(request.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/request/request.ftl", ctx);
|
||||||
|
System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
File f = new File(rsp.getAbsolutePath() + File.separator + s.replaceAll("Request", "Response.java"));
|
||||||
|
if (!f.exists()){
|
||||||
|
System.err.println("文件" + f.getAbsolutePath() + "不存在");
|
||||||
|
}
|
||||||
|
JavaClassReader javaClassReader = new JavaClassReader(f);
|
||||||
|
|
||||||
|
StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
stringBuffer.append("src" + File.separator);
|
||||||
|
stringBuffer.append("main" + File.separator);
|
||||||
|
stringBuffer.append("java" + File.separator);
|
||||||
|
|
||||||
|
String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
|
||||||
|
|
||||||
|
for (String s1 : split) {
|
||||||
|
stringBuffer.append(s1 + File.separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
|
||||||
|
File response = new File(stringBuffer.toString() + File.separator + "response");
|
||||||
|
response.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
ctx.put("className", javaClassReader.getClassName().replaceAll("Response", ""));
|
||||||
|
ctx.put("body", javaClassReader.getBody());
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
ctx.put("hasList", javaClassReader.isHasList());
|
||||||
|
ctx.put("Tclass", javaClassReader.getTclass());
|
||||||
|
File file = new File(response.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/response/response.ftl", ctx);
|
||||||
|
System.out.println("生成文件" + api.getRsp().getName() + "成功");
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : api.getDepEnt()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
File f = new File(ent.getAbsolutePath() + File.separator + s + ".java");
|
||||||
|
if (!f.exists()) {
|
||||||
|
System.out.println("文件" + f.getAbsolutePath() + "不存在");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JavaClassReader javaClassReader = new JavaClassReader(f);
|
||||||
|
|
||||||
|
StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
stringBuffer.append("src" + File.separator);
|
||||||
|
stringBuffer.append("main" + File.separator);
|
||||||
|
stringBuffer.append("java" + File.separator);
|
||||||
|
|
||||||
|
String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
|
||||||
|
|
||||||
|
for (String s1 : split) {
|
||||||
|
stringBuffer.append(s1 + File.separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
|
||||||
|
File entity = new File(stringBuffer.toString() + File.separator + "entity");
|
||||||
|
entity.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
ctx.put("className", javaClassReader.getClassName().replaceAll("Entity", ""));
|
||||||
|
ctx.put("body", javaClassReader.getBody());
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
File file = new File(entity.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/entity/entity.ftl", ctx);
|
||||||
|
System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : api.getDepEnum()) {
|
||||||
|
try {
|
||||||
|
File f = new File(enums.getAbsolutePath() + File.separator + s + ".java");
|
||||||
|
if (!f.exists()) {
|
||||||
|
System.err.println("文件" + f.getAbsolutePath() + "不存在");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JavaEnumReader javaEnumReader = new JavaEnumReader(f);
|
||||||
|
|
||||||
|
StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
stringBuffer.append("src" + File.separator);
|
||||||
|
stringBuffer.append("main" + File.separator);
|
||||||
|
stringBuffer.append("java" + File.separator);
|
||||||
|
|
||||||
|
String[] split = javaEnumReader.getDomainName().split("\\.");
|
||||||
|
|
||||||
|
|
||||||
|
for (String s1 : split) {
|
||||||
|
stringBuffer.append(s1 + File.separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer.append(javaEnumReader.getModuleName());
|
||||||
|
|
||||||
|
File enums_ = new File(stringBuffer.toString() + File.separator + "enums");
|
||||||
|
enums_.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("package", "package " + javaEnumReader.getDomainName() + "." + javaEnumReader.getModuleName() + "." + "enums;");
|
||||||
|
ctx.put("domain", javaEnumReader.getDomainName());
|
||||||
|
ctx.put("module", javaEnumReader.getModuleName());
|
||||||
|
ctx.put("annotation", javaEnumReader.getAnnotationList());
|
||||||
|
ctx.put("className", javaEnumReader.getClassName());
|
||||||
|
ctx.put("body", javaEnumReader.getBody());
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
|
||||||
|
File file = new File(enums_.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/enums/type.ftl", ctx);
|
||||||
|
System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (req.exists() && rsp.exists() && ent.exists()) {
|
||||||
|
// File[] files = req.listFiles();
|
||||||
|
// System.out.println("生成模块:Request,Response,Entity");
|
||||||
|
// for (File f : files) {
|
||||||
|
// try {
|
||||||
|
// //region 生成request
|
||||||
|
// JavaClassReader javaClassReader = new JavaClassReader(f);
|
||||||
|
//
|
||||||
|
// Method method = new Method();
|
||||||
|
// method.setStringMethod("api." + javaClassReader.getModuleName() + "." + Tool.camelToPoint(javaClassReader.getClassName().replaceAll("Request", "")));
|
||||||
|
// method.setRequest(javaClassReader.getClassName());
|
||||||
|
// method.setTarget(Tool.getRequestTarget(javaClassReader.getClassName()));
|
||||||
|
// method.setMethod(Tool.getRequestAction(javaClassReader.getClassName()));
|
||||||
|
// method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager");
|
||||||
|
// methodList.add(method);
|
||||||
|
// StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
// stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
// stringBuffer.append("src" + File.separator);
|
||||||
|
// stringBuffer.append("main" + File.separator);
|
||||||
|
// stringBuffer.append("java" + File.separator);
|
||||||
|
//
|
||||||
|
// String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// for (String s1 : split) {
|
||||||
|
// stringBuffer.append(s1 + File.separator);
|
||||||
|
// }
|
||||||
|
// if (frameWork == null) {
|
||||||
|
// frameWork = new File(stringBuffer.toString());
|
||||||
|
// frameWork.mkdirs();
|
||||||
|
// }
|
||||||
|
// if (domain == null) {
|
||||||
|
// domain = javaClassReader.getDomainName();
|
||||||
|
// }
|
||||||
|
// if (module == null) {
|
||||||
|
// module = javaClassReader.getModuleName();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
//
|
||||||
|
// File request = new File(stringBuffer.toString() + File.separator + "request");
|
||||||
|
// request.mkdirs();
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
// ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
// ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
// ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
// ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
// ctx.put("className", javaClassReader.getClassName().replaceAll("Request", ""));
|
||||||
|
// ctx.put("body", javaClassReader.getBody());
|
||||||
|
// ctx.put("tool", tool);
|
||||||
|
// ctx.put("hasList", javaClassReader.isHasList());
|
||||||
|
// ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag());
|
||||||
|
// File file = new File(request.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(file, "Java_api/module/request/request.ftl", ctx);
|
||||||
|
// System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
// }
|
||||||
|
// //endregion
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// //region 生成response
|
||||||
|
// File r = new File(f.getParent().replaceAll("req", "rsp") + File.separator + f.getName().replaceAll("Request", "Response"));
|
||||||
|
// JavaClassReader javaClassReader = new JavaClassReader(r);
|
||||||
|
//
|
||||||
|
// StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
// stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
// stringBuffer.append("src" + File.separator);
|
||||||
|
// stringBuffer.append("main" + File.separator);
|
||||||
|
// stringBuffer.append("java" + File.separator);
|
||||||
|
//
|
||||||
|
// String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// for (String s1 : split) {
|
||||||
|
// stringBuffer.append(s1 + File.separator);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
//
|
||||||
|
// File response = new File(stringBuffer.toString() + File.separator + "response");
|
||||||
|
// response.mkdirs();
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
// ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
// ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
// ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
// ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
// ctx.put("className", javaClassReader.getClassName().replaceAll("Response", ""));
|
||||||
|
// ctx.put("body", javaClassReader.getBody());
|
||||||
|
// ctx.put("tool", tool);
|
||||||
|
// ctx.put("hasList", javaClassReader.isHasList());
|
||||||
|
// ctx.put("Tclass", javaClassReader.getTclass());
|
||||||
|
// File file = new File(response.getAbsolutePath() + File.separator + f.getName().replaceAll("Request", "Response"));
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(file, "Java_api/module/response/response.ftl", ctx);
|
||||||
|
// System.out.println("生成文件" + r.getName() + "成功");
|
||||||
|
// }
|
||||||
|
// //endregion
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (File f : ent.listFiles()) {
|
||||||
|
// try {
|
||||||
|
// //region 生成entity
|
||||||
|
// JavaClassReader javaClassReader = new JavaClassReader(f);
|
||||||
|
// managerList.add(javaClassReader.getClassName() + "Manager");
|
||||||
|
//
|
||||||
|
// StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
// stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
// stringBuffer.append("src" + File.separator);
|
||||||
|
// stringBuffer.append("main" + File.separator);
|
||||||
|
// stringBuffer.append("java" + File.separator);
|
||||||
|
//
|
||||||
|
// String[] split = javaClassReader.getDomainName().split("\\.");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// for (String s1 : split) {
|
||||||
|
// stringBuffer.append(s1 + File.separator);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer.append(javaClassReader.getModuleName());
|
||||||
|
//
|
||||||
|
// File entity = new File(stringBuffer.toString() + File.separator + "entity");
|
||||||
|
// entity.mkdirs();
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
|
||||||
|
// ctx.put("domain", javaClassReader.getDomainName());
|
||||||
|
// ctx.put("module", javaClassReader.getModuleName());
|
||||||
|
// ctx.put("importList", javaClassReader.getImportList());
|
||||||
|
// ctx.put("annotation", javaClassReader.getAnnotationList());
|
||||||
|
// ctx.put("className", javaClassReader.getClassName().replaceAll("Entity", ""));
|
||||||
|
// ctx.put("body", javaClassReader.getBody());
|
||||||
|
// ctx.put("tool", tool);
|
||||||
|
// File file = new File(entity.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
// freeMarkerManager.outputTemp(file, "Java_api/module/entity/entity.ftl", ctx);
|
||||||
|
// System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
// }
|
||||||
|
// //endregion
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (enums.exists()) {
|
||||||
|
// System.out.println("生成模块:Enums");
|
||||||
|
// for (File f : enums.listFiles()) {
|
||||||
|
// try {
|
||||||
|
// //region 生成enums
|
||||||
|
// JavaEnumReader javaEnumReader = new JavaEnumReader(f);
|
||||||
|
//
|
||||||
|
// StringBuffer stringBuffer = new StringBuffer("");
|
||||||
|
// stringBuffer.append(sdk.getPath() + File.separator);
|
||||||
|
// stringBuffer.append("src" + File.separator);
|
||||||
|
// stringBuffer.append("main" + File.separator);
|
||||||
|
// stringBuffer.append("java" + File.separator);
|
||||||
|
//
|
||||||
|
// String[] split = javaEnumReader.getDomainName().split("\\.");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// for (String s1 : split) {
|
||||||
|
// stringBuffer.append(s1 + File.separator);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer.append(javaEnumReader.getModuleName());
|
||||||
|
//
|
||||||
|
// File enums_ = new File(stringBuffer.toString() + File.separator + "enums");
|
||||||
|
// enums_.mkdirs();
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("package", "package " + javaEnumReader.getDomainName() + "." + javaEnumReader.getModuleName() + "." + "enums;");
|
||||||
|
// ctx.put("domain", javaEnumReader.getDomainName());
|
||||||
|
// ctx.put("module", javaEnumReader.getModuleName());
|
||||||
|
// ctx.put("annotation", javaEnumReader.getAnnotationList());
|
||||||
|
// ctx.put("className", javaEnumReader.getClassName());
|
||||||
|
// ctx.put("body", javaEnumReader.getBody());
|
||||||
|
// ctx.put("tool", tool);
|
||||||
|
//
|
||||||
|
// File file = new File(enums_.getAbsolutePath() + File.separator + f.getName());
|
||||||
|
// freeMarkerManager.outputTemp(file, "Java_api/module/enums/type.ftl", ctx);
|
||||||
|
// System.out.println("生成文件" + file.getName() + "成功");
|
||||||
|
// }
|
||||||
|
// //endregion
|
||||||
|
//
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
{
|
||||||
|
System.out.println("生成模块:ApiController");
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("tool", tool);
|
||||||
|
ctx.put("domain", domain);
|
||||||
|
ctx.put("module", module);
|
||||||
|
ctx.put("managerList", managerList);
|
||||||
|
ctx.put("methodList", methodList);
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + module + File.separator + "ApiController.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "Java_api/module/controller/ApiController.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("生成基础类");
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("domain", domain);
|
||||||
|
ctx.put("module", module);
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiEntity.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiEntity.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "AESUtil.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/AESUtil.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiClient.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiClient.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiRequest.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiRequest.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiFindRequest.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiFindRequest.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiSearchRequest.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiSearchRequest.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiResponse.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiResponse.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiFindResponse.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ApiFindResponse.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "Base64Util.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/Base64Util.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "DownloadUtil.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/DownloadUtil.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "Error.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/Error.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ErrorType.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ErrorType.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "FileUploadRequest.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/FileUploadRequest.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "FileUploadResponse.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/FileUploadResponse.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "MapperUtil.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/MapperUtil.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "MD5Util.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/MD5Util.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "RSAUtil.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/RSAUtil.ftl", ctx);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "ProgressRequestBody.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/ProgressRequestBody.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "SortType.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/SortType.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
File file = new File(frameWork.getAbsolutePath() + File.separator + "StringUtils.java");
|
||||||
|
freeMarkerManager.outputTemp(file, "/Java_api/StringUtils.ftl", ctx);
|
||||||
|
}
|
||||||
|
//4.0.1 去掉验证 减少体积
|
||||||
|
// {
|
||||||
|
// File file = new File(frameWork.getAbsolutePath() + File.separator + "ValidationUtil.java");
|
||||||
|
// freeMarkerManager.outputTemp(file, "/Java_api/ValidationUtil.ftl", ctx);
|
||||||
|
// }
|
||||||
|
System.out.println("finish");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class Method {
|
||||||
|
private String request;
|
||||||
|
private String stringMethod;
|
||||||
|
private String manager;
|
||||||
|
private String method;
|
||||||
|
private String target;
|
||||||
|
|
||||||
|
public String getRequest() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequest(String request) {
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(String target) {
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringMethod() {
|
||||||
|
return stringMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringMethod(String stringMethod) {
|
||||||
|
this.stringMethod = stringMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getManager() {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManager(String manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod(String method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,705 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.manger.callable;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.XmlManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Module;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Project;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Table;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Tool;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
|
||||||
|
|
||||||
|
public class SpringBootCallable implements Callable {
|
||||||
|
|
||||||
|
private String root;
|
||||||
|
private DataBase dataBase;
|
||||||
|
private Project project;
|
||||||
|
private String option;
|
||||||
|
|
||||||
|
private FreeMarkerManager freeMarkerManager;
|
||||||
|
|
||||||
|
public SpringBootCallable(String root, DataBase dataBase, Project project, String option) {
|
||||||
|
this.root = root;
|
||||||
|
this.dataBase = dataBase;
|
||||||
|
this.project = project;
|
||||||
|
this.option = option;
|
||||||
|
this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AbstractDBmapper dBmapper;
|
||||||
|
|
||||||
|
public Boolean call() throws Exception {
|
||||||
|
dBmapper = ProjectManager.dBmapper;
|
||||||
|
|
||||||
|
// 创建项目文件夹
|
||||||
|
File projectDir = new File(root + File.separator + project.getProjectName());
|
||||||
|
if (!projectDir.exists()) {
|
||||||
|
projectDir.mkdir();
|
||||||
|
} else {
|
||||||
|
clear(projectDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成POM
|
||||||
|
generatePom(projectDir, project, dataBase, option);
|
||||||
|
|
||||||
|
// 生成Maven-java及域名目录
|
||||||
|
String basePackage = project.getProjectBasePackage();
|
||||||
|
String[] split = basePackage.split("\\.");
|
||||||
|
StringBuffer stringBuffer = new StringBuffer(projectDir.getAbsolutePath() + File.separator + "src" + File.separator + "main");
|
||||||
|
stringBuffer.append(File.separator).append("java");
|
||||||
|
for (String s : split) {
|
||||||
|
stringBuffer.append(File.separator).append(s);
|
||||||
|
}
|
||||||
|
File src = new File(stringBuffer.toString());
|
||||||
|
if (!src.exists()) {
|
||||||
|
src.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成资源目录
|
||||||
|
stringBuffer = new StringBuffer(projectDir.getAbsolutePath() + File.separator + "src" + File.separator + "main");
|
||||||
|
stringBuffer.append(File.separator).append("resources");
|
||||||
|
File resources = new File(stringBuffer.toString());
|
||||||
|
if (!resources.exists()) {
|
||||||
|
resources.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成单元测试java目录
|
||||||
|
stringBuffer = new StringBuffer(projectDir.getAbsolutePath());
|
||||||
|
stringBuffer.append(File.separator).append("src").append(File.separator).append("test").append(File.separator).append("java");
|
||||||
|
for (String s : split) {
|
||||||
|
stringBuffer.append(File.separator).append(s);
|
||||||
|
}
|
||||||
|
File testSrc = new File(stringBuffer.toString());
|
||||||
|
if (!testSrc.exists()) {
|
||||||
|
testSrc.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成单元测试resources目录
|
||||||
|
stringBuffer = new StringBuffer(projectDir.getAbsolutePath());
|
||||||
|
stringBuffer.append(File.separator).append("src").append(File.separator).append("test").append(File.separator).append("resources");
|
||||||
|
File testResources = new File(stringBuffer.toString());
|
||||||
|
if (!testResources.exists()) {
|
||||||
|
testResources.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
{//生成java文件
|
||||||
|
//生成Controller
|
||||||
|
System.out.println("生成模块:action");
|
||||||
|
generateController(new File(src.getAbsolutePath(), "action"), project, dataBase, option);
|
||||||
|
|
||||||
|
//module
|
||||||
|
{
|
||||||
|
for (Module module : project.getModules()) {
|
||||||
|
module.setProjectAuthor(project.getProjectAuthor());
|
||||||
|
module.setProjectBasePackage(project.getProjectBasePackage());
|
||||||
|
module.setProjectName(project.getProjectName());
|
||||||
|
|
||||||
|
File modulePath = new File(src.getAbsolutePath(), module.getModuleName());
|
||||||
|
modulePath.mkdirs();
|
||||||
|
|
||||||
|
System.out.println("生成模块:Entity");
|
||||||
|
generateEntity(new File(modulePath.getAbsolutePath(), "ent"), module, dataBase, option);
|
||||||
|
System.out.println("生成模块:Enums");
|
||||||
|
generateEnums(new File(modulePath.getAbsolutePath(), "enums"), module, dataBase, option);
|
||||||
|
System.out.println("生成模块:Mapper");
|
||||||
|
generateMapper(new File(modulePath.getAbsolutePath(), "mpr"), module, dataBase, option);
|
||||||
|
System.out.println("生成模块:Manager");
|
||||||
|
generateManager(new File(modulePath.getAbsolutePath(), "mgr"), module, dataBase, option);
|
||||||
|
System.out.println("生成模块:Requset");
|
||||||
|
generateRequset(new File(modulePath.getAbsolutePath(), "req"), module, dataBase, option);
|
||||||
|
System.out.println("生成模块:Response");
|
||||||
|
generateResponse(new File(modulePath.getAbsolutePath(), "rsp"), module, dataBase, option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//framework
|
||||||
|
System.out.println("生成模块:framework");
|
||||||
|
generateFramework(new File(src.getAbsolutePath(), "framework"), project, dataBase, option);
|
||||||
|
|
||||||
|
System.out.println("生成模块:Application");
|
||||||
|
generateApplication(new File(src.getAbsolutePath()), project, dataBase, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
{//生成resources文件
|
||||||
|
System.out.println("生成模块:Resources");
|
||||||
|
generateResources(resources, project, dataBase, option);
|
||||||
|
for (Module module : project.getModules()) {
|
||||||
|
generateResourcesSQL(resources, module, dataBase, option);
|
||||||
|
}
|
||||||
|
System.out.println("生成模块:Static");
|
||||||
|
generateStatic(resources, project, dataBase, option);
|
||||||
|
System.out.println("生成模块:Templates");
|
||||||
|
generateTemplates(resources, project, dataBase, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
{//生成test
|
||||||
|
System.out.println("生成模块:Test");
|
||||||
|
generateTest(testSrc, project, dataBase, option);
|
||||||
|
generateTestResources(testResources, project, dataBase, option);
|
||||||
|
}
|
||||||
|
System.out.println("finish");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成POM.xml
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generatePom(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("projectName", project.getProjectName());
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("dataBase", dataBase.toString());
|
||||||
|
|
||||||
|
File file = new File(root.getAbsolutePath(), "pom.xml");
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, option + "/pom.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成Controller类
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generateController(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("author", project.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
ctx.put("modules", project.getModules());
|
||||||
|
|
||||||
|
File control = new File(root.getAbsolutePath(), "control");
|
||||||
|
control.mkdirs();
|
||||||
|
freeMarkerManager.outputTemp(new File(control.getAbsolutePath(), "Footer.java"), option + "/java/action/control/Footer.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(control.getAbsolutePath(), "Header.java"), option + "/java/action/control/Header.java", ctx);
|
||||||
|
|
||||||
|
File screen = new File(root.getAbsolutePath(), "screen");
|
||||||
|
screen.mkdirs();
|
||||||
|
freeMarkerManager.outputTemp(new File(screen.getAbsolutePath(), "Index.java"), option + "/java/action/screen/Index.java", ctx);
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "GlobalController.java"), option + "/java/action/GlobalController.ftl", ctx);
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "AjaxController.java"), option + "/java/action/AjaxController.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成entity
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param md
|
||||||
|
*/
|
||||||
|
public void generateEntity(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("table", table);
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
|
||||||
|
File file = new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + ".java");
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, option + "/java/ent/entity.ftl", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成Enums
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param md
|
||||||
|
*/
|
||||||
|
public void generateEnums(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
|
||||||
|
File file = new File(root.getAbsolutePath(), "Type.java");
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(file, option + "/java/enums/Type.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成Mapper
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param md
|
||||||
|
*/
|
||||||
|
public void generateMapper(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("module", md);
|
||||||
|
ctx.put("dataBase", dataBase.toString());
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
ctx.put("table", table);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), option + "/java/mpr/mapperJava.ftl", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper.ftl", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateManager(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiManager" + ".java"), option + "/java/mgr/ApiManager.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiManagerImpl" + ".java"), option + "/java/mgr/ApiManagerImpl.java", ctx);
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
ctx.put("table", table);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/mgr/manager.ftl", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), option + "/java/mgr/managerImpl.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成Requset
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param md
|
||||||
|
*/
|
||||||
|
public void generateRequset(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiExampleRequest" + ".java"), option + "/java/req/ApiExampleRequest.java", ctx);
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
ctx.put("table", table);
|
||||||
|
|
||||||
|
if (table.getCreate() != null && table.getCreate()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateRequest" + ".java"), option + "/java/req/createRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getDelete() != null && table.getDelete()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteRequest" + ".java"), option + "/java/req/deleteRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getUpdate() != null && table.getUpdate()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateRequest" + ".java"), option + "/java/req/updateRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getFind() != null && table.getFind()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindRequest" + ".java"), option + "/java/req/findRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getGet() != null && table.getGet()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetRequest" + ".java"), option + "/java/req/getRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getSearch() != null && table.getSearch()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchRequest" + ".java"), option + "/java/req/searchRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
if (table.getGetAll() != null && table.getGetAll()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetAllRequest" + ".java"), option + "/java/req/getAllRequestClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一般文件
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param md
|
||||||
|
*/
|
||||||
|
public void generateResponse(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiExampleResponse" + ".java"), option + "/java/rsp/ApiExampleResponse.java", ctx);
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
ctx.put("table", table);
|
||||||
|
|
||||||
|
if (table.getCreate() != null && table.getCreate()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateResponse" + ".java"), option + "/java/rsp/createResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getDelete() != null && table.getDelete()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteResponse" + ".java"), option + "/java/rsp/deleteResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getUpdate() != null && table.getUpdate()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateResponse" + ".java"), option + "/java/rsp/updateResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getFind() != null && table.getFind()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindResponse" + ".java"), option + "/java/rsp/findResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getGet() != null && table.getGet()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetResponse" + ".java"), option + "/java/rsp/getResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.getSearch() != null && table.getSearch()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchResponse" + ".java"), option + "/java/rsp/searchResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
if (table.getGetAll() != null && table.getGetAll()) {
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetAllResponse" + ".java"), option + "/java/rsp/getAllResponseClass.ftl", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成framework类
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generateFramework(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
if (!root.exists()) {
|
||||||
|
root.mkdirs();
|
||||||
|
} else {
|
||||||
|
clear(root);
|
||||||
|
}
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", project.getProjectName());
|
||||||
|
ctx.put("timestamp", new Date().getTime());
|
||||||
|
|
||||||
|
File base = new File(root.getAbsolutePath(), "base");
|
||||||
|
base.mkdirs();
|
||||||
|
File config = new File(root.getAbsolutePath(), "config");
|
||||||
|
config.mkdirs();
|
||||||
|
File freemarker = new File(root.getAbsolutePath(), "freemarker");
|
||||||
|
freemarker.mkdirs();
|
||||||
|
File springmvc = new File(root.getAbsolutePath(), "springmvc");
|
||||||
|
springmvc.mkdirs();
|
||||||
|
File utils = new File(root.getAbsolutePath(), "utils");
|
||||||
|
utils.mkdirs();
|
||||||
|
|
||||||
|
//base
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseEntity.java"), option + "/java/framework/base/BaseEntity.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseFindRequest.java"), option + "/java/framework/base/BaseFindRequest.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseFindResponse.java"), option + "/java/framework/base/BaseFindResponse.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseGetAllRequest.java"), option + "/java/framework/base/BaseGetAllRequest.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseRequest.java"), option + "/java/framework/base/BaseRequest.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseResponse.java"), option + "/java/framework/base/BaseResponse.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseSearchRequest.java"), option + "/java/framework/base/BaseSearchRequest.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseUpdateRequest.java"), option + "/java/framework/base/BaseUpdateRequest.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Control.java"), option + "/java/framework/base/Control.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Error.java"), option + "/java/framework/base/Error.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "ErrorType.java"), option + "/java/framework/base/ErrorType.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "FileUploadResponse.java"), option + "/java/framework/base/FileUploadResponse.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Screen.java"), option + "/java/framework/base/Screen.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "SortType.java"), option + "/java/framework/base/SortType.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Token.java"), option + "/java/framework/base/Token.java", ctx);
|
||||||
|
|
||||||
|
//config
|
||||||
|
freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "BeanDefinitionRegistryConfig.java"), option + "/java/framework/config/BeanDefinitionRegistryConfig.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "SecurityConfig.java"), option + "/java/framework/config/SecurityConfig.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "TaskConfig.java"), option + "/java/framework/config/TaskConfig.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "ThreadPoolConfig.java"), option + "/java/framework/config/ThreadPoolConfig.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "WebMvcConfig.java"), option + "/java/framework/config/WebMvcConfig.java", ctx);
|
||||||
|
|
||||||
|
//freemarker
|
||||||
|
freeMarkerManager.outputTemp(new File(freemarker.getAbsolutePath(), "ViewNameTranslator.java"), option + "/java/framework/freemarker/ViewNameTranslator.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(freemarker.getAbsolutePath(), "Layout.java"), option + "/java/framework/freemarker/Layout.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(freemarker.getAbsolutePath(), "Uri.java"), option + "/java/framework/freemarker/Uri.java", ctx);
|
||||||
|
|
||||||
|
//springmvc
|
||||||
|
freeMarkerManager.outputTemp(new File(springmvc.getAbsolutePath(), "GlobalHandlerInterceptor.java"), option + "/java/framework/springmvc/GlobalHandlerInterceptor.java", ctx);
|
||||||
|
|
||||||
|
//uitls
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "Base64Util.java"), option + "/java/framework/utils/Base64Util.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "AESUtil.java"), option + "/java/framework/utils/AESUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "CookieUtil.java"), option + "/java/framework/utils/CookieUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "LogUtil.java"), option + "/java/framework/utils/LogUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/framework/utils/MapperUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/framework/utils/MD5Util.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/framework/utils/ProcessUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "RSAUtil.java"), option + "/java/framework/utils/RSAUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ValidationUtil.java"), option + "/java/framework/utils/ValidationUtil.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "WebUtils.java"), option + "/java/framework/utils/WebUtils.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "LocalData.java"), option + "/java/framework/utils/LocalData.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "IDgenerator.java"), option + "/java/framework/utils/IDgenerator.java", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "Message.java"), option + "/java/framework/utils/Message.java", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成base类
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generateApplication(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", project.getProjectName());
|
||||||
|
ctx.put("timestamp", new Date().getTime());
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "Application.java"), option + "/java/Application.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成properties
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generateResources(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("dataBase", dataBase.toString());
|
||||||
|
ctx.put("author", project.getProjectAuthor());
|
||||||
|
ctx.put("dBmapper", dBmapper);
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
ctx.put("projectName", project.getProjectName());
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "start-dev.bat"), option + "/resources/start-dev.bat", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "start-prod.bat"), option + "/resources/start-prod.bat", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "application-dev.properties"), option + "/resources/application-dev.ftl", ctx);
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "application-prod.properties"), option + "/resources/application-prod.ftl", ctx);
|
||||||
|
Tool.outputResource(option + "/resources/banner.txt", new File(root.getAbsolutePath(), "banner.txt"));
|
||||||
|
Tool.outputResource(option + "/resources/logback-config.xml", new File(root.getAbsolutePath(), "logback-config.xml"));
|
||||||
|
|
||||||
|
File lib = new File(root.getAbsolutePath(), "lib");
|
||||||
|
lib.mkdirs();
|
||||||
|
Tool.outputResource(option + "/resources/lib/ojdbc7-12.1.0.2.jar", new File(lib.getAbsolutePath(), "ojdbc7-12.1.0.2.jar"));
|
||||||
|
|
||||||
|
File dbtool = new File(root.getAbsolutePath(), "dbtool");
|
||||||
|
dbtool.mkdirs();
|
||||||
|
{
|
||||||
|
XmlManager xmlManager = ManagerFactory.getXmlManager();
|
||||||
|
xmlManager.saveAs(dbtool.getAbsolutePath(), project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成properties
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param md
|
||||||
|
*/
|
||||||
|
public void generateResourcesSQL(File root, Module md, DataBase dataBase, String option) {
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("dataBase", dataBase.toString());
|
||||||
|
ctx.put("module", md);
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("dBmapper", dBmapper);
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
|
||||||
|
File tableDir = new File(root.getAbsolutePath(), md.getModuleName() + "_table");
|
||||||
|
tableDir.mkdirs();
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
ctx.put("table", table);
|
||||||
|
freeMarkerManager.outputTemp(new File(tableDir.getAbsolutePath(), table.getTableName() + ".sql"), option + "/resources/table.ftl", ctx);
|
||||||
|
}
|
||||||
|
freeMarkerManager.outputTemp(new File(tableDir.getAbsolutePath(), "ALL_TABLE.sql"), option + "/resources/tableAll.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateTestResources(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", project.getProjectName());
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("dataBase", dataBase.toString());
|
||||||
|
ctx.put("author", project.getProjectAuthor());
|
||||||
|
ctx.put("dBmapper", dBmapper);
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "application.properties"), option + "/test/application.properties", ctx);
|
||||||
|
Tool.outputResource(option + "/test/logback-config.xml", new File(root.getAbsolutePath(), "logback-config.xml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成static
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generateStatic(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("author", project.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
ctx.put("modules", project.getModules());
|
||||||
|
|
||||||
|
File static_ = new File(root.getAbsolutePath(), "static");
|
||||||
|
boolean mkdirs = static_.mkdirs();
|
||||||
|
File css = new File(static_.getAbsolutePath(), "css");
|
||||||
|
boolean mkdirs1 = css.mkdirs();
|
||||||
|
File js = new File(static_.getAbsolutePath(), "js");
|
||||||
|
boolean mkdirs2 = js.mkdirs();
|
||||||
|
File img = new File(static_.getAbsolutePath(), "img");
|
||||||
|
boolean mkdirs3 = img.mkdirs();
|
||||||
|
|
||||||
|
File dist = new File(static_.getAbsolutePath(), "dist");
|
||||||
|
boolean mkdirs4 = dist.mkdirs();
|
||||||
|
|
||||||
|
{//css文件
|
||||||
|
freeMarkerManager.outputTemp(new File(css.getAbsolutePath(), "base.css"), option + "/resources/static/css/base.css", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
{//js文件
|
||||||
|
freeMarkerManager.outputTemp(new File(js.getAbsolutePath(), "ajax.js"), option + "/resources/static/js/ajax.ftl", ctx);
|
||||||
|
}
|
||||||
|
{//img
|
||||||
|
Tool.outputResource(option + "/resources/static/img/favicon.ico", new File(img.getAbsolutePath(), "favicon.ico"));
|
||||||
|
Tool.outputResource(option + "/resources/static/img/logo.png", new File(img.getAbsolutePath(), "logo.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{//dist文件
|
||||||
|
|
||||||
|
Tool.outputResource(option + "/resources/static/dist/lib.min.css", new File(dist.getAbsolutePath(), "lib.min.css"));
|
||||||
|
Tool.outputResource(option + "/resources/static/dist/lib.min.js", new File(dist.getAbsolutePath(), "lib.min.js"));
|
||||||
|
|
||||||
|
|
||||||
|
File fonts = new File(dist.getAbsolutePath(), "fonts");
|
||||||
|
fonts.mkdirs();
|
||||||
|
|
||||||
|
Tool.outputResource(option + "/resources/static/dist/fonts/element-icons.woff", new File(fonts.getAbsolutePath(), "element-icons.woff"));
|
||||||
|
Tool.outputResource(option + "/resources/static/dist/fonts/w-e-icon.woff", new File(fonts.getAbsolutePath(), "w-e-icon.woff"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成static
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void generateTemplates(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
{//生成
|
||||||
|
File templates = new File(root.getAbsolutePath(), "templates");
|
||||||
|
templates.mkdirs();
|
||||||
|
|
||||||
|
File control = new File(templates.getAbsolutePath(), "control");
|
||||||
|
control.mkdirs();
|
||||||
|
File layout = new File(templates.getAbsolutePath(), "layout");
|
||||||
|
layout.mkdirs();
|
||||||
|
File screen = new File(templates.getAbsolutePath(), "screen");
|
||||||
|
screen.mkdirs();
|
||||||
|
Tool.outputResource(option + "/resources/templates/control/nav.ftl", new File(control.getAbsolutePath(), "nav.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/control/header.ftl", new File(control.getAbsolutePath(), "header.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/control/footer.ftl", new File(control.getAbsolutePath(), "footer.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/control/macro.ftl", new File(control.getAbsolutePath(), "macro.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/layout/default.ftl", new File(layout.getAbsolutePath(), "default.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/layout/wap.ftl", new File(layout.getAbsolutePath(), "wap.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/screen/demo.ftl", new File(screen.getAbsolutePath(), "demo.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/screen/index.ftl", new File(screen.getAbsolutePath(), "index.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/403.ftl", new File(templates.getAbsolutePath(), "403.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/404.ftl", new File(templates.getAbsolutePath(), "404.ftl"));
|
||||||
|
Tool.outputResource(option + "/resources/templates/500.ftl", new File(templates.getAbsolutePath(), "500.ftl"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateTest(File root, Project project, DataBase dataBase, String option) {
|
||||||
|
|
||||||
|
File config = new File(root.getAbsolutePath(), "config");
|
||||||
|
config.mkdirs();
|
||||||
|
|
||||||
|
{
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", project.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", project.getProjectName());
|
||||||
|
ctx.put("author", project.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "TestConfig" + ".java"), option + "/test/TestConfig.ftl", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Module md : project.getModules()) {
|
||||||
|
File module = new File(root.getAbsolutePath(), md.getModuleName());
|
||||||
|
module.mkdirs();
|
||||||
|
|
||||||
|
for (Table table : md.getTables()) {
|
||||||
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
ctx.put("tool", Tool.class);
|
||||||
|
ctx.put("basePackage", md.getProjectBasePackage());
|
||||||
|
ctx.put("moduleName", md.getModuleName());
|
||||||
|
ctx.put("table", table);
|
||||||
|
ctx.put("author", md.getProjectAuthor());
|
||||||
|
ctx.put("date", new Date());
|
||||||
|
|
||||||
|
freeMarkerManager.outputTemp(new File(module.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Test" + ".java"), option + "/test/test.ftl", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,666 @@
|
|||||||
|
//package xyz.wbsite.dbtool.javafx.manger.callable;
|
||||||
|
//
|
||||||
|
//import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.manger.XmlManager;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.po.Module;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.po.Table;
|
||||||
|
//import xyz.wbsite.dbtool.javafx.tool.Tool;
|
||||||
|
//
|
||||||
|
//import java.io.*;
|
||||||
|
//import java.util.ArrayList;
|
||||||
|
//import java.util.Date;
|
||||||
|
//import java.util.HashMap;
|
||||||
|
//import java.util.concurrent.Callable;
|
||||||
|
//
|
||||||
|
//import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
|
||||||
|
//
|
||||||
|
//public class SpringMVCMybatisCallable implements Callable {
|
||||||
|
//
|
||||||
|
// private String root;
|
||||||
|
// private DataBase dataBase;
|
||||||
|
// private Module md;
|
||||||
|
// private String option;
|
||||||
|
// private Tool tool = new Tool();
|
||||||
|
//
|
||||||
|
// private FreeMarkerManager freeMarkerManager;
|
||||||
|
//
|
||||||
|
// public SpringMVCMybatisCallable(String root, DataBase dataBase, Module md, String option) {
|
||||||
|
// this.root = root;
|
||||||
|
// this.dataBase = dataBase;
|
||||||
|
// this.md = md;
|
||||||
|
// this.option = option;
|
||||||
|
// this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private AbstractDBmapper dBmapper;
|
||||||
|
//
|
||||||
|
// public Boolean call() throws Exception {
|
||||||
|
//
|
||||||
|
// File module = new File(root + File.separator + md.getModuleName());
|
||||||
|
// if (!module.exists()) {
|
||||||
|
// module.mkdir();
|
||||||
|
// } else {
|
||||||
|
// clear(module);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// dBmapper = ProjectManager.dBmapper;
|
||||||
|
//
|
||||||
|
// String basePackage = md.getBasePackage();
|
||||||
|
//
|
||||||
|
// String[] split = basePackage.split("\\.");
|
||||||
|
//
|
||||||
|
// System.out.println("生成模块:Pom");
|
||||||
|
// generatePom(module, md, dataBase, option);
|
||||||
|
// StringBuffer stringBuffer = new StringBuffer(module.getAbsolutePath() + File.separator + "src" + File.separator + "main");
|
||||||
|
// stringBuffer.append(File.separator).append("java");
|
||||||
|
// for (String s : split) {
|
||||||
|
// stringBuffer.append(File.separator).append(s);
|
||||||
|
// }
|
||||||
|
// stringBuffer.append(File.separator).append(md.getModuleName());
|
||||||
|
//
|
||||||
|
// File src = new File(stringBuffer.toString());
|
||||||
|
// if (!src.exists()) {
|
||||||
|
// src.mkdirs();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer = new StringBuffer(module.getAbsolutePath() + File.separator + "src" + File.separator + "main");
|
||||||
|
// stringBuffer.append(File.separator).append("resources");
|
||||||
|
// File resources = new File(stringBuffer.toString());
|
||||||
|
// if (!resources.exists()) {
|
||||||
|
// resources.mkdirs();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer = new StringBuffer(module.getAbsolutePath() + File.separator + "src" + File.separator + "main");
|
||||||
|
// stringBuffer.append(File.separator).append("webapp");
|
||||||
|
// File webapp = new File(stringBuffer.toString());
|
||||||
|
// if (!webapp.exists()) {
|
||||||
|
// webapp.mkdirs();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer = new StringBuffer(module.getAbsolutePath());
|
||||||
|
// stringBuffer.append(File.separator).append("src").append(File.separator).append("test").append(File.separator).append("java");
|
||||||
|
// for (String s : split) {
|
||||||
|
// stringBuffer.append(File.separator).append(s);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// File testSrc = new File(stringBuffer.toString());
|
||||||
|
// if (!testSrc.exists()) {
|
||||||
|
// testSrc.mkdirs();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stringBuffer = new StringBuffer(module.getAbsolutePath());
|
||||||
|
// stringBuffer.append(File.separator).append("src").append(File.separator).append("test").append(File.separator).append("resources");
|
||||||
|
// File testResources = new File(stringBuffer.toString());
|
||||||
|
// if (!testResources.exists()) {
|
||||||
|
// testResources.mkdirs();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //生成java文件
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// //生成Controller
|
||||||
|
// System.out.println("生成模块:controller");
|
||||||
|
// generateController(new File(src.getParentFile().getAbsolutePath() + File.separator + "controller"), md, dataBase, option);
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// //module
|
||||||
|
// System.out.println("生成模块:Entity");
|
||||||
|
// generateEntity(new File(src.getAbsolutePath() + File.separator + "ent"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:Enums");
|
||||||
|
// generateEnums(new File(src.getAbsolutePath() + File.separator + "enums"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:Filter");
|
||||||
|
// generateFilter(new File(src.getAbsolutePath() + File.separator + "filter"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:Mapper");
|
||||||
|
// generateMapper(new File(src.getAbsolutePath() + File.separator + "mpr"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:Manager");
|
||||||
|
// generateManager(new File(src.getAbsolutePath() + File.separator + "mgr"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:Requset");
|
||||||
|
// generateRequset(new File(src.getAbsolutePath() + File.separator + "req"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:Response");
|
||||||
|
// generateResponse(new File(src.getAbsolutePath() + File.separator + "rsp"), md, dataBase, option);
|
||||||
|
// System.out.println("生成模块:framework");
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //framework
|
||||||
|
// System.out.println("生成模块:framework");
|
||||||
|
// generateBase(new File(src.getParentFile().getAbsolutePath() + File.separator + "framework"), md, dataBase, option);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {//生成resources文件
|
||||||
|
// System.out.println("生成模块:Resources");
|
||||||
|
// generateResources(resources, md, dataBase, option);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {//生成webapp
|
||||||
|
// System.out.println("生成模块:Webapp");
|
||||||
|
// generateWebapp(webapp, md, dataBase, option);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {//生成test 和 testResources
|
||||||
|
// System.out.println("生成模块:Test 和 TestResources");
|
||||||
|
// generateResources(testResources, md, dataBase, option);
|
||||||
|
// generateTest(testSrc, md, dataBase, option);
|
||||||
|
// }
|
||||||
|
// System.out.println("finish");
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成POM.xml
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generatePom(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "pom.xml"), option + "/pom.ftl", ctx);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成entity
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateEntity(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("table", table);
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + ".java"), option + "/java/ent/entity.ftl", ctx);
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成Enums
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateEnums(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "Type.java"), option + "/java/enums/Type.ftl", ctx);
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成Filter
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateFilter(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
//
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "Authorizations" + ".java"), option + "/java/filter/Authorizations.ftl", ctx);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成Mapper
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateMapper(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
//
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("db", db);
|
||||||
|
// ctx.put("dataBase", dataBase.toString());
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// try {
|
||||||
|
// ctx.put("table", table);
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), option + "/java/mpr/mapperJava.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper.ftl", ctx);
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void generateManager(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
//
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// ctx.put("table", table);
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/mgr/manager.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), option + "/java/mgr/managerImpl.ftl", ctx);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成Requset
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateRequset(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
//
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// ctx.put("table", table);
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "CreateRequest" + ".java"), option + "/java/req/createRequestClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "DeleteRequest" + ".java"), option + "/java/req/deleteRequestClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "UpdateRequest" + ".java"), option + "/java/req/updateRequestClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "FindRequest" + ".java"), option + "/java/req/findRequestClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "SearchRequest" + ".java"), option + "/java/req/searchRequestClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "GetAllRequest" + ".java"), option + "/java/req/GetAllRequestClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "GetRequest" + ".java"), option + "/java/req/getRequestClass.ftl", ctx);
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成一般文件
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateResponse(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// ctx.put("table", table);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "CreateResponse" + ".java"), option + "/java/rsp/createResponseClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "DeleteResponse" + ".java"), option + "/java/rsp/deleteResponseClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "UpdateResponse" + ".java"), option + "/java/rsp/updateResponseClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "FindResponse" + ".java"), option + "/java/rsp/findResponseClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "SearchResponse" + ".java"), option + "/java/rsp/searchResponseClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "GetAllResponse" + ".java"), option + "/java/rsp/GetAllResponseClass.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "GetResponse" + ".java"), option + "/java/rsp/getResponseClass.ftl", ctx);
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成base类
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateBase(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("timestamp", new Date().getTime());
|
||||||
|
//
|
||||||
|
// File base = new File(root.getAbsolutePath() + File.separator + "base");
|
||||||
|
// base.mkdirs();
|
||||||
|
// File freemarker = new File(root.getAbsolutePath() + File.separator + "freemarker");
|
||||||
|
// freemarker.mkdirs();
|
||||||
|
// File springmvc = new File(root.getAbsolutePath() + File.separator + "springmvc");
|
||||||
|
// springmvc.mkdirs();
|
||||||
|
// File utils = new File(root.getAbsolutePath() + File.separator + "utils");
|
||||||
|
// utils.mkdirs();
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseEntity.java"), option + "/java/framework/base/BaseEntity.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseFindRequest.java"), option + "/java/framework/base/BaseFindRequest.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseFindResponse.java"), option + "/java/framework/base/BaseFindResponse.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseGetAllRequest.java"), option + "/java/framework/base/BaseGetAllRequest.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseRequest.java"), option + "/java/framework/base/BaseRequest.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseResponse.java"), option + "/java/framework/base/BaseResponse.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseSearchRequest.java"), option + "/java/framework/base/BaseSearchRequest.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "BaseUpdateRequest.java"), option + "/java/framework/base/BaseUpdateRequest.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "Error.java"), option + "/java/framework/base/Error.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "ErrorType.java"), option + "/java/framework/base/ErrorType.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "SortType.java"), option + "/java/framework/base/SortType.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(base.getAbsolutePath() + File.separator + "Token.java"), option + "/java/framework/base/Token.java", ctx);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "AESUtil.java"), option + "/java/framework/utils/AESUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "Base64Util.java"), option + "/java/framework/utils/Base64Util.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "CookieUtil.java"), option + "/java/framework/utils/CookieUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "IDgenerator.java"), option + "/java/framework/utils/IDgenerator.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "LocalData.java"), option + "/java/framework/utils/LocalData.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "LogUtil.java"), option + "/java/framework/utils/LogUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "MapperUtil.java"), option + "/java/framework/utils/MapperUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "MD5Util.java"), option + "/java/framework/utils/MD5Util.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "Message.java"), option + "/java/framework/utils/Message.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "ProcessUtil.java"), option + "/java/framework/utils/ProcessUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "RSAUtil.java"), option + "/java/framework/utils/RSAUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "ValidationUtil.java"), option + "/java/framework/utils/ValidationUtil.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(utils.getAbsolutePath() + File.separator + "WebUtils.java"), option + "/java/framework/utils/WebUtils.java", ctx);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(freemarker.getAbsolutePath() + File.separator + "ViewNameTranslator.java"), option + "/java/framework/freemarker/ViewNameTranslator.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(freemarker.getAbsolutePath() + File.separator + "Layout.java"), option + "/java/framework/freemarker/Layout.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(freemarker.getAbsolutePath() + File.separator + "Url.java"), option + "/java/framework/freemarker/Url.java", ctx);
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(springmvc.getAbsolutePath() + File.separator + "GlobalHandlerInterceptor.java"), option + "/java/framework/springmvc/GlobalHandlerInterceptor.java", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(springmvc.getAbsolutePath() + File.separator + "GlobalObjectMapper.java"), option + "/java/framework/springmvc/GlobalObjectMapper.java", ctx);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成Controller类
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateController(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// root.mkdirs();
|
||||||
|
// } else {
|
||||||
|
// clear(root);
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("db", db);
|
||||||
|
// ctx.put("table", md.getTables());
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "AjaxController.java"), option + "/java/controller/AjaxController.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "GlobalController.java"), option + "/java/controller/GlobalController.ftl", ctx);
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 生成Resources spring,spring-mvc,mybatis,jdbc
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// */
|
||||||
|
// public void generateResources(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
//
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// if (root.getAbsolutePath().contains("test")) {
|
||||||
|
// ctx.put("isTest", true);
|
||||||
|
// } else {
|
||||||
|
// ctx.put("isTest", false);
|
||||||
|
// }
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "spring.xml"), option + "/resources/spring.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "spring-mvc.xml"), option + "/resources/spring-mvc.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "spring-mybatis.xml"), option + "/resources/spring-mybatis.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "logback.xml"), option + "/resources/logback.ftl", ctx);
|
||||||
|
// freeMarkerManager.outputTemp(new File(root.getAbsolutePath() + File.separator + "jdbc.properties"), option + "/resources/jdbc.properties.ftl", ctx);
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!root.getAbsolutePath().contains("test")) {
|
||||||
|
// File tableDir = new File(root.getAbsolutePath() + File.separator + md.getModuleName() + "_table");
|
||||||
|
// tableDir.mkdirs();
|
||||||
|
// File dbtool = new File(root.getAbsolutePath() + File.separator + "dbtool");
|
||||||
|
// dbtool.mkdirs();
|
||||||
|
// {
|
||||||
|
// XmlManager xmlManager = ManagerFactory.getXmlManager();
|
||||||
|
// ArrayList<Module> dbs = new ArrayList<>();
|
||||||
|
// dbs.add(db);
|
||||||
|
// xmlManager.saveAs(dbtool.getAbsolutePath(), dbs);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("dataBase", dataBase.toString());
|
||||||
|
// ctx.put("db", db);
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("dBmapper", dBmapper);
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
//
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// ctx.put("table", table);
|
||||||
|
// freeMarkerManager.outputTemp(new File(tableDir.getAbsolutePath() + File.separator + table.getTableName() + ".sql"), option + "/resources/table.ftl", ctx);
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("dataBase", dataBase.toString());
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("db", db);
|
||||||
|
// ctx.put("dBmapper", dBmapper);
|
||||||
|
//
|
||||||
|
// freeMarkerManager.outputTemp(new File(tableDir.getAbsolutePath() + File.separator + "ALL_TABLE.sql"), option + "/resources/tableAll.ftl", ctx);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void generateTest(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// File module = new File(root.getAbsolutePath() + File.separator + md.getModuleName());
|
||||||
|
// module.mkdirs();
|
||||||
|
//
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("tool", tool);
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
// for (Table table : md.getTables()) {
|
||||||
|
// ctx.put("table", table);
|
||||||
|
// freeMarkerManager.outputTemp(new File(module.getAbsolutePath() + File.separator + Tool.lineToClassName(table.getTableName()) + "Test" + ".java"), option + "/test/test.ftl", ctx);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * webapp文件夹及文件生成
|
||||||
|
// *
|
||||||
|
// * @param root
|
||||||
|
// * @param db
|
||||||
|
// * @param option
|
||||||
|
// */
|
||||||
|
// public void generateWebapp(File root, Module db, DataBase dataBase, String option) {
|
||||||
|
// HashMap<String, Object> ctx = new HashMap<String, Object>();
|
||||||
|
// ctx.put("basePackage", md.getBasePackage());
|
||||||
|
// ctx.put("moduleName", md.getModuleName());
|
||||||
|
// ctx.put("tool", Tool.class);
|
||||||
|
// ctx.put("db", db);
|
||||||
|
// ctx.put("author", md.getAuthor());
|
||||||
|
// ctx.put("date", new Date());
|
||||||
|
// try {
|
||||||
|
//
|
||||||
|
// File static_ = new File(root.getAbsolutePath() + File.separator + "static");
|
||||||
|
// boolean mkdirs = static_.mkdirs();
|
||||||
|
// File css = new File(static_.getAbsolutePath() + File.separator + "css");
|
||||||
|
// boolean mkdirs1 = css.mkdirs();
|
||||||
|
// File dist = new File(static_.getAbsolutePath() + File.separator + "dist");
|
||||||
|
// boolean mkdirs5 = dist.mkdirs();
|
||||||
|
// File fonts = new File(static_.getAbsolutePath() + File.separator + "fonts");
|
||||||
|
// boolean mkdirs6 = fonts.mkdirs();
|
||||||
|
// File js = new File(static_.getAbsolutePath() + File.separator + "js");
|
||||||
|
// boolean mkdirs2 = js.mkdirs();
|
||||||
|
// File img = new File(static_.getAbsolutePath() + File.separator + "img");
|
||||||
|
// boolean mkdirs3 = img.mkdirs();
|
||||||
|
//
|
||||||
|
// File lib = new File(static_.getAbsolutePath() + File.separator + "lib");
|
||||||
|
// boolean mkdirs4 = lib.mkdirs();
|
||||||
|
//
|
||||||
|
// {//css文件
|
||||||
|
// freeMarkerManager.outputTemp(new File(css.getAbsolutePath() + File.separator + "base.css"), option + "/webapp/static/css/base.css", ctx);
|
||||||
|
// }
|
||||||
|
// {//dist文件
|
||||||
|
//
|
||||||
|
// Tool.outputResource(option + "/webapp/static/dist/lib.min.css", new File(dist.getAbsolutePath() + File.separator + "lib.min.css"));
|
||||||
|
// Tool.outputResource(option + "/webapp/static/dist/lib.min.js", new File(dist.getAbsolutePath() + File.separator + "lib.min.js"));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Tool.outputResource(option + "/webapp/static/dist/fonts/element-icons.woff", new File(fonts.getAbsolutePath() + File.separator + "element-icons.woff"));
|
||||||
|
// Tool.outputResource(option + "/webapp/static/dist/fonts/w-e-icon.woff", new File(fonts.getAbsolutePath() + File.separator + "w-e-icon.woff"));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {//js文件
|
||||||
|
// freeMarkerManager.outputTemp(new File(js.getAbsolutePath() + File.separator + "services.js"), option + "/webapp/static/js/services.ftl", ctx);
|
||||||
|
// }
|
||||||
|
// {//img
|
||||||
|
// Tool.outputResource(option + "/webapp/static/img/favicon.ico", new File(img.getAbsolutePath() + File.separator + "favicon.ico"));
|
||||||
|
// Tool.outputResource(option + "/webapp/static/img/logo.png", new File(img.getAbsolutePath() + File.separator + "logo.png"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// File WEB_INF_DIR = new File(root.getAbsolutePath() + File.separator + "WEB-INF");
|
||||||
|
// WEB_INF_DIR.mkdirs();
|
||||||
|
//
|
||||||
|
// {//生成WEB-INF下的web.xml等文件
|
||||||
|
// freeMarkerManager.outputTemp(new File(WEB_INF_DIR.getAbsolutePath() + File.separator + "web.xml"), option + "/webapp/WEB-INF/web.ftl", ctx);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {//生成WEB-INF下的文件夹
|
||||||
|
// File views = new File(root.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "views");
|
||||||
|
// views.mkdirs();
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/views/index.ftl", new File(views.getAbsolutePath() + File.separator + "index.jsp"));
|
||||||
|
//
|
||||||
|
// File include = new File(views.getAbsolutePath() + File.separator + "include");
|
||||||
|
// include.mkdirs();
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/views/include/top.ftl", new File(include.getAbsolutePath() + File.separator + "top.jsp"));
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/views/include/foot.ftl", new File(include.getAbsolutePath() + File.separator + "foot.jsp"));
|
||||||
|
//
|
||||||
|
// File ftl = new File(root.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "ftl");
|
||||||
|
// ftl.mkdirs();
|
||||||
|
// File control = new File(ftl.getAbsolutePath() + File.separator + "control");
|
||||||
|
// control.mkdirs();
|
||||||
|
// File layout = new File(ftl.getAbsolutePath() + File.separator + "layout");
|
||||||
|
// layout.mkdirs();
|
||||||
|
// File screen = new File(ftl.getAbsolutePath() + File.separator + "screen");
|
||||||
|
// screen.mkdirs();
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/ftl/control/header.ftl", new File(control.getAbsolutePath() + File.separator + "header.ftl"));
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/ftl/control/footer.ftl", new File(control.getAbsolutePath() + File.separator + "footer.ftl"));
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/ftl/control/macro.ftl", new File(control.getAbsolutePath() + File.separator + "macro.ftl"));
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/ftl/layout/default.ftl", new File(layout.getAbsolutePath() + File.separator + "default.ftl"));
|
||||||
|
// Tool.outputResource(option + "/webapp/WEB-INF/ftl/screen/index.ftl", new File(screen.getAbsolutePath() + File.separator + "index.ftl"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,25 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.FieldType;
|
||||||
|
|
||||||
|
public abstract class AbstractDBmapper {
|
||||||
|
DataBase mDataBase = null;
|
||||||
|
|
||||||
|
private AbstractDBmapper(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractDBmapper(DataBase mDataBase) {
|
||||||
|
this.mDataBase = mDataBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataBase getDataBase(){
|
||||||
|
return mDataBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getDataBaseType(FieldType type,int lenght);
|
||||||
|
public abstract String getDataBaseType(FieldType type);
|
||||||
|
abstract String getFieldSql(Field field);
|
||||||
|
public abstract FieldType getType(String type, int lenght, int precision, int scale);
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Api {
|
||||||
|
private boolean check;
|
||||||
|
|
||||||
|
//目标请求对象
|
||||||
|
private String targetRequest;
|
||||||
|
//目标请求响应
|
||||||
|
private String targetResponse;
|
||||||
|
//方法
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
private File req;
|
||||||
|
private File rsp;
|
||||||
|
|
||||||
|
private Set<String> depReq = new HashSet<>();
|
||||||
|
private Set<String> depEnt = new HashSet<>();
|
||||||
|
private Set<String> depEnum = new HashSet<>();
|
||||||
|
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
public String getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError(String error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCheck() {
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheck(boolean check) {
|
||||||
|
this.check = check;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetRequest() {
|
||||||
|
return targetRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetRequest(String targetRequest) {
|
||||||
|
this.targetRequest = targetRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetResponse() {
|
||||||
|
return targetResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetResponse(String targetResponse) {
|
||||||
|
this.targetResponse = targetResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod(String method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getReq() {
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReq(File req) {
|
||||||
|
this.req = req;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getRsp() {
|
||||||
|
return rsp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRsp(File rsp) {
|
||||||
|
this.rsp = rsp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getDepReq() {
|
||||||
|
return depReq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDepReq(Set<String> depReq) {
|
||||||
|
this.depReq = depReq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getDepEnt() {
|
||||||
|
return depEnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDepEnt(Set<String> depEnt) {
|
||||||
|
this.depEnt = depEnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getDepEnum() {
|
||||||
|
return depEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDepEnum(Set<String> depEnum) {
|
||||||
|
this.depEnum = depEnum;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import javafx.scene.control.TreeItem;
|
||||||
|
|
||||||
|
|
||||||
|
public class DTreeItem extends TreeItem {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.FieldType;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Tool;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class Field extends Table {
|
||||||
|
|
||||||
|
public Field() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Field(String fieldName) {
|
||||||
|
this.fieldName = fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名
|
||||||
|
*/
|
||||||
|
private String fieldName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private FieldType fieldType = FieldType.String_var50;
|
||||||
|
/**
|
||||||
|
* 字段长度
|
||||||
|
*/
|
||||||
|
private int fieldLength = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段注释
|
||||||
|
*/
|
||||||
|
private String fieldComment = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认值
|
||||||
|
*/
|
||||||
|
private String defaultValue = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可为NULL
|
||||||
|
*/
|
||||||
|
private Boolean isMust = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是主键
|
||||||
|
*/
|
||||||
|
private Boolean isPrimaryKey = false;
|
||||||
|
/**
|
||||||
|
* 是否作为查询条件
|
||||||
|
*/
|
||||||
|
private Boolean isQuery = false;
|
||||||
|
|
||||||
|
|
||||||
|
private Boolean isSearch = false;
|
||||||
|
|
||||||
|
private Boolean isSystem = false;
|
||||||
|
|
||||||
|
public String getTestValue() {
|
||||||
|
String value = "";
|
||||||
|
if (fieldType.name().matches("String_\\d+")) {
|
||||||
|
Pattern compile = Pattern.compile("String_(\\d+)");
|
||||||
|
Matcher matcher = compile.matcher(fieldType.name());
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
int len = Integer.parseInt(matcher.group(1));
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(this.fieldComment)) {
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
sb.append("A");
|
||||||
|
}
|
||||||
|
value = sb.toString();
|
||||||
|
} else {
|
||||||
|
value = "\"" + this.fieldComment.substring(0, this.fieldComment.length() > this.fieldLength ? this.fieldLength : this.fieldComment.length()) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (fieldType.name().matches("String_var\\d+")) {
|
||||||
|
Pattern compile = Pattern.compile("String_var(\\d+)");
|
||||||
|
Matcher matcher = compile.matcher(fieldType.name());
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
int len = Integer.parseInt(matcher.group(1));
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(this.fieldComment)) {
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
sb.append("\"");
|
||||||
|
sb.append("A");
|
||||||
|
sb.append("\"");
|
||||||
|
value = sb.toString();
|
||||||
|
} else {
|
||||||
|
value = "\"" + this.fieldComment.substring(0, this.fieldComment.length() > this.fieldLength ? this.fieldLength : this.fieldComment.length()) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (fieldType.name().equals("String_var")) {
|
||||||
|
int len = fieldLength;
|
||||||
|
if (StringUtils.isEmpty(this.fieldComment)) {
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
sb.append("\"");
|
||||||
|
sb.append("A");
|
||||||
|
sb.append("\"");
|
||||||
|
value = sb.toString();
|
||||||
|
} else {
|
||||||
|
value = "\"" + this.fieldComment.substring(0, this.fieldComment.length() > this.fieldLength ? this.fieldLength : this.fieldComment.length()) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (fieldType.name().matches("Boolean")) {
|
||||||
|
value = "true";
|
||||||
|
} else if (fieldType.name().matches("Byte|Short|Integer")) {
|
||||||
|
value = "1";
|
||||||
|
} else if (fieldType.name().matches("Bytes")) {
|
||||||
|
value = "null";
|
||||||
|
} else if (fieldType.name().matches("Long")) {
|
||||||
|
value = "1L";
|
||||||
|
} else if (fieldType.name().matches("Float")) {
|
||||||
|
value = "1.0f";
|
||||||
|
} else if (fieldType.name().matches("Double")) {
|
||||||
|
value = "1.0";
|
||||||
|
} else if (fieldType.name().matches("Character")) {
|
||||||
|
value = "'A'";
|
||||||
|
} else if (fieldType.name().matches("Date")) {
|
||||||
|
value = "new Date()";
|
||||||
|
} else if (fieldType.name().matches("Date")) {
|
||||||
|
value = "new Date()";
|
||||||
|
} else if (fieldType.name().matches("BigDecimal")) {
|
||||||
|
value = "new BigDecimal()";
|
||||||
|
} else if (fieldType.name().matches("String_super")) {
|
||||||
|
value = "\"content\"";
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsSearch() {
|
||||||
|
return isSearch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsSearch(Boolean isSearch) {
|
||||||
|
this.isSearch = isSearch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsSystem() {
|
||||||
|
return isSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsSystem(Boolean isSystem) {
|
||||||
|
this.isSystem = isSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getterName() {
|
||||||
|
return "get" + Tool.lineToClassName(this.fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setterName() {
|
||||||
|
return "set" + Tool.lineToClassName(this.fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsQuery() {
|
||||||
|
return isQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsQuery(Boolean isQuery) {
|
||||||
|
this.isQuery = isQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldName() {
|
||||||
|
return fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldName(String fieldName) {
|
||||||
|
this.fieldName = fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldType getFieldType() {
|
||||||
|
return fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldType(FieldType fieldType) {
|
||||||
|
this.fieldType = fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFieldLength() {
|
||||||
|
return fieldLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldLength(Integer fieldLength) {
|
||||||
|
this.fieldLength = fieldLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldComment() {
|
||||||
|
return fieldComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldComment(String fieldComment) {
|
||||||
|
this.fieldComment = fieldComment != null ? fieldComment : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultValue(String defaultValue) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsMust() {
|
||||||
|
return isMust;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsMust(Boolean isMust) {
|
||||||
|
this.isMust = isMust;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsPrimaryKey() {
|
||||||
|
return isPrimaryKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsPrimaryKey(Boolean isPrimaryKey) {
|
||||||
|
this.isPrimaryKey = isPrimaryKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFName() {
|
||||||
|
return Tool.lineToFieldName(this.fieldName);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import javafx.scene.control.TreeItem;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Module extends TreeItem {
|
||||||
|
public Module() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Module(String moduleName) {
|
||||||
|
this.moduleName = moduleName;
|
||||||
|
this.setValue(moduleName);
|
||||||
|
setExpanded(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块注释
|
||||||
|
*/
|
||||||
|
private String moduleComment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块前缀
|
||||||
|
*/
|
||||||
|
private String modulePrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象
|
||||||
|
*/
|
||||||
|
private List<Table> tables = new ArrayList();
|
||||||
|
|
||||||
|
private String moduleName;
|
||||||
|
private boolean hasSysFields;
|
||||||
|
private String projectName;
|
||||||
|
private String projectBasePackage;
|
||||||
|
private String projectAuthor;
|
||||||
|
|
||||||
|
public boolean isHasSysFields() {
|
||||||
|
return hasSysFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasSysFields(boolean hasSysFields) {
|
||||||
|
this.hasSysFields = hasSysFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModuleName() {
|
||||||
|
return moduleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModuleName(String moduleName) {
|
||||||
|
this.moduleName = moduleName;
|
||||||
|
this.setValue(moduleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean putTable(Table table) {
|
||||||
|
if (tables == null) {
|
||||||
|
tables = new ArrayList<Table>();
|
||||||
|
}
|
||||||
|
tables.add(table);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Table> getTables() {
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTables(List<Table> tables) {
|
||||||
|
this.tables = tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModuleComment() {
|
||||||
|
return moduleComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModuleComment(String moduleComment) {
|
||||||
|
this.moduleComment = moduleComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModulePrefix() {
|
||||||
|
return modulePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModulePrefix(String modulePrefix) {
|
||||||
|
this.modulePrefix = modulePrefix!=null?modulePrefix:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectBasePackage() {
|
||||||
|
return projectBasePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectBasePackage(String projectBasePackage) {
|
||||||
|
this.projectBasePackage = projectBasePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectAuthor() {
|
||||||
|
return projectAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectAuthor(String projectAuthor) {
|
||||||
|
this.projectAuthor = projectAuthor;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,232 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.FieldType;
|
||||||
|
|
||||||
|
public class MySqlDBmapper extends AbstractDBmapper {
|
||||||
|
|
||||||
|
public MySqlDBmapper(DataBase mDataBase) {
|
||||||
|
super(mDataBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDataBaseType(FieldType type, int lenght) {
|
||||||
|
if (FieldType.Boolean.name().equals(type.name())) {
|
||||||
|
return "BIT";
|
||||||
|
} else if (FieldType.Byte.name().equals(type.name())) {
|
||||||
|
return "TINYINT";
|
||||||
|
} else if (FieldType.Short.name().equals(type.name())) {
|
||||||
|
return "SMALLINT";
|
||||||
|
} else if (FieldType.Integer.name().equals(type.name())) {
|
||||||
|
return "INTEGER";
|
||||||
|
} else if (FieldType.Long.name().equals(type.name())) {
|
||||||
|
return "NUMERIC";
|
||||||
|
} else if (FieldType.Float.name().equals(type.name())) {
|
||||||
|
return "REAL";
|
||||||
|
} else if (FieldType.Double.name().equals(type.name())) {
|
||||||
|
return "FLOAT";
|
||||||
|
} else if (FieldType.Character.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_1.name().equals(type.name())) {
|
||||||
|
return "CAHR";
|
||||||
|
} else if (FieldType.String_10.name().equals(type.name())) {
|
||||||
|
return "CAHR";
|
||||||
|
} else if (FieldType.String_var.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var50.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var100.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var255.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var2500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var4000.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.Date.name().equals(type.name())) {
|
||||||
|
return "DATE";
|
||||||
|
} else if (FieldType.Bytes.name().equals(type.name())) {
|
||||||
|
return "BLOB";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFieldSql(Field field) {
|
||||||
|
StringBuffer sb = new StringBuffer("");
|
||||||
|
sb.append("`").append(field.getFieldName()).append("` ");
|
||||||
|
|
||||||
|
FieldType type = field.getFieldType();
|
||||||
|
|
||||||
|
if (FieldType.Boolean.name().equals(type.name())) {
|
||||||
|
sb.append("TINYINT(1)");
|
||||||
|
} else if (FieldType.Byte.name().equals(type.name())) {
|
||||||
|
sb.append("TINYINT(3)");
|
||||||
|
} else if (FieldType.Short.name().equals(type.name())) {
|
||||||
|
sb.append("SMALLINT(5)");
|
||||||
|
} else if (FieldType.Integer.name().equals(type.name())) {
|
||||||
|
sb.append("INTEGER(10)");
|
||||||
|
} else if (FieldType.Long.name().equals(type.name())) {
|
||||||
|
sb.append("BIGINT(20)");
|
||||||
|
} else if (FieldType.Float.name().equals(type.name())) {
|
||||||
|
sb.append("FLOAT");
|
||||||
|
} else if (FieldType.Double.name().equals(type.name())) {
|
||||||
|
sb.append("DOUBLE");
|
||||||
|
} else if (FieldType.Date.name().equals(type.name())) {
|
||||||
|
sb.append("DATETIME");
|
||||||
|
} else if (FieldType.Bytes.name().equals(type.name())) {
|
||||||
|
sb.append("BLOB");
|
||||||
|
} else if (FieldType.String_1.name().equals(type.name())) {
|
||||||
|
sb.append("CHAR(1)");
|
||||||
|
} else if (FieldType.String_10.name().equals(type.name())) {
|
||||||
|
sb.append("CHAR(10)");
|
||||||
|
} else if (FieldType.String_var.name().equals(type.name())) {
|
||||||
|
Integer fieldLength = field.getFieldLength();
|
||||||
|
sb.append("VARCHAR(" + fieldLength + ")");
|
||||||
|
} else if (FieldType.String_var50.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR(50)");
|
||||||
|
} else if (FieldType.String_var100.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR(100)");
|
||||||
|
} else if (FieldType.String_var255.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR(250)");
|
||||||
|
} else if (FieldType.String_var500.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR(500)");
|
||||||
|
} else if (FieldType.String_var2500.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR(2500)");
|
||||||
|
} else if (FieldType.String_var4000.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR(4000)");
|
||||||
|
} else if (FieldType.String_super.name().equals(type.name())) {
|
||||||
|
sb.append("TEXT");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!field.getIsSystem() && field.getIsMust() && (field.getDefaultValue() == null || field.getDefaultValue().toUpperCase().equals("NULL"))) {
|
||||||
|
sb.append(" NOT NULL");
|
||||||
|
} else if (!field.getIsSystem() && field.getIsMust() && field.getDefaultValue() != null && !field.getDefaultValue().toUpperCase().equals("NULL")) {
|
||||||
|
if (field.getFieldType().name().contains("String")) {//默认字符
|
||||||
|
sb.append(" NOT NULL").append(" DEFAULT '" + field.getDefaultValue() + "'");
|
||||||
|
} else {//不是字符就是数字,目前只考虑两张情况
|
||||||
|
sb.append(" NOT NULL").append(" DEFAULT " + field.getDefaultValue() + "");
|
||||||
|
}
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("ID")) {
|
||||||
|
sb.append(" NOT NULL");
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("ROW_VERSION")) {
|
||||||
|
sb.append(" NOT NULL").append(" DEFAULT 0");
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("IS_DELETED")) {
|
||||||
|
sb.append(" NOT NULL").append(" DEFAULT 0");
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("CREATE_BY")) {
|
||||||
|
sb.append(" NOT NULL");
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("CREATE_TIME")) {
|
||||||
|
sb.append(" NOT NULL");
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("LAST_UPDATE_BY")) {
|
||||||
|
sb.append(" DEFAULT NULL");
|
||||||
|
} else if (field.getIsSystem() && field.getFieldName().equals("LAST_UPDATE_TIME")) {
|
||||||
|
sb.append(" DEFAULT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.getFieldComment() != null) {
|
||||||
|
sb.append(" COMMENT '" + field.getFieldComment() + "'");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
DataBase getDataBase() {
|
||||||
|
return super.getDataBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDataBaseType(FieldType type) {
|
||||||
|
if (FieldType.Boolean.name().equals(type.name())) {
|
||||||
|
return "TINYINT";
|
||||||
|
} else if (FieldType.Byte.name().equals(type.name())) {
|
||||||
|
return "TINYINT";
|
||||||
|
} else if (FieldType.Short.name().equals(type.name())) {
|
||||||
|
return "SMALLINT";
|
||||||
|
} else if (FieldType.Integer.name().equals(type.name())) {
|
||||||
|
return "INTEGER";
|
||||||
|
} else if (FieldType.Long.name().equals(type.name())) {
|
||||||
|
return "NUMERIC";
|
||||||
|
} else if (FieldType.Float.name().equals(type.name())) {
|
||||||
|
return "REAL";
|
||||||
|
} else if (FieldType.Double.name().equals(type.name())) {
|
||||||
|
return "FLOAT";
|
||||||
|
} else if (FieldType.Character.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_1.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.String_10.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.String_var.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var50.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var100.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var255.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var2500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.String_var4000.name().equals(type.name())) {
|
||||||
|
return "VARCHAR";
|
||||||
|
} else if (FieldType.Date.name().equals(type.name())) {
|
||||||
|
return "DATETIME";
|
||||||
|
} else if (FieldType.Bytes.name().equals(type.name())) {
|
||||||
|
return "BLOB";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldType getType(String type, int lenght, int precision, int scale) {
|
||||||
|
if ("bigint".equals(type)) {
|
||||||
|
return FieldType.Long;
|
||||||
|
} else if ("varchar".equals(type) && lenght == 50) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if ("varchar".equals(type) && lenght == 100) {
|
||||||
|
return FieldType.String_var100;
|
||||||
|
} else if ("varchar".equals(type) && lenght == 255) {
|
||||||
|
return FieldType.String_var255;
|
||||||
|
} else if ("varchar".equals(type) && lenght == 500) {
|
||||||
|
return FieldType.String_var500;
|
||||||
|
} else if ("varchar".equals(type) && lenght == 2500) {
|
||||||
|
return FieldType.String_var2500;
|
||||||
|
} else if ("varchar".equals(type) && lenght == 4000) {
|
||||||
|
return FieldType.String_var4000;
|
||||||
|
} else if ("varchar".equals(type)) {
|
||||||
|
return FieldType.String_var;
|
||||||
|
} else if ("date".equals(type)) {
|
||||||
|
return FieldType.Date;
|
||||||
|
} else if ("datetime".equals(type)) {
|
||||||
|
return FieldType.Date;
|
||||||
|
} else if ("timestamp".equals(type)) {
|
||||||
|
return FieldType.Date;
|
||||||
|
} else if ("char".equals(type) && lenght == 1) {
|
||||||
|
return FieldType.String_1;
|
||||||
|
} else if ("char".equals(type) && lenght == 10) {
|
||||||
|
return FieldType.String_10;
|
||||||
|
} else if ("char".equals(type)) {
|
||||||
|
return FieldType.String_var;
|
||||||
|
} else if ("tinyint".equals(type)) {
|
||||||
|
return FieldType.Integer;
|
||||||
|
} else if ("smallint".equals(type)) {
|
||||||
|
return FieldType.Integer;
|
||||||
|
} else if ("mediumint".equals(type)) {
|
||||||
|
return FieldType.Integer;
|
||||||
|
} else if ("int".equals(type)) {
|
||||||
|
return FieldType.Integer;
|
||||||
|
} else if ("bigint".equals(type)) {
|
||||||
|
return FieldType.Long;
|
||||||
|
} else if ("float".equals(type)) {
|
||||||
|
return FieldType.Float;
|
||||||
|
} else if ("double".equals(type)) {
|
||||||
|
return FieldType.Double;
|
||||||
|
}
|
||||||
|
return FieldType.String_var50;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,209 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.FieldType;
|
||||||
|
|
||||||
|
public class OracleDBmapper extends AbstractDBmapper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFieldSql(Field field) {
|
||||||
|
StringBuffer sb = new StringBuffer("");
|
||||||
|
sb.append("\"").append(field.getFieldName()).append("\" ");
|
||||||
|
|
||||||
|
FieldType type = field.getFieldType();
|
||||||
|
|
||||||
|
if (FieldType.Boolean.name().equals(type.name())) {
|
||||||
|
sb.append("CHAR(1)");
|
||||||
|
} else if (FieldType.Byte.name().equals(type.name())) {
|
||||||
|
sb.append("NUMBER(3)");
|
||||||
|
} else if (FieldType.Short.name().equals(type.name())) {
|
||||||
|
sb.append("NUMBER(5)");
|
||||||
|
} else if (FieldType.Integer.name().equals(type.name())) {
|
||||||
|
sb.append("NUMBER(10)");
|
||||||
|
} else if (FieldType.Long.name().equals(type.name())) {
|
||||||
|
sb.append("NUMBER(19)");
|
||||||
|
} else if (FieldType.Float.name().equals(type.name())) {
|
||||||
|
sb.append("NUMBER");
|
||||||
|
} else if (FieldType.Double.name().equals(type.name())) {
|
||||||
|
sb.append("NUMBER");
|
||||||
|
} else if (FieldType.Date.name().equals(type.name())) {
|
||||||
|
sb.append("DATE");
|
||||||
|
} else if (FieldType.Bytes.name().equals(type.name())) {
|
||||||
|
sb.append("BLOB");
|
||||||
|
} else if (FieldType.String_1.name().equals(type.name())) {
|
||||||
|
sb.append("CHAR(1)");
|
||||||
|
} else if (FieldType.String_10.name().equals(type.name())) {
|
||||||
|
sb.append("CHAR(10)");
|
||||||
|
} else if (FieldType.String_var.name().equals(type.name())) {
|
||||||
|
Integer fieldLength = field.getFieldLength();
|
||||||
|
sb.append("VARCHAR2(" + fieldLength + ")");
|
||||||
|
} else if (FieldType.String_var50.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR2(50)");
|
||||||
|
} else if (FieldType.String_var100.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR2(100)");
|
||||||
|
} else if (FieldType.String_var255.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR2(250)");
|
||||||
|
} else if (FieldType.String_var500.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR2(500)");
|
||||||
|
} else if (FieldType.String_var2500.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR2(2500)");
|
||||||
|
} else if (FieldType.String_var4000.name().equals(type.name())) {
|
||||||
|
sb.append("VARCHAR2(4000)");
|
||||||
|
} else if (FieldType.String_super.name().equals(type.name())) {
|
||||||
|
//Oracle中LONG最大支持2G字节
|
||||||
|
sb.append("LONG");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.getIsMust() && field.getIsSystem()) {
|
||||||
|
sb.append(" NOT NULL");
|
||||||
|
} else {
|
||||||
|
sb.append(" NULL");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OracleDBmapper(DataBase mDataBase) {
|
||||||
|
super(mDataBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDataBaseType(FieldType type, int lenght) {
|
||||||
|
if (FieldType.Boolean.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.Byte.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Short.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Integer.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Long.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Float.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Double.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Date.name().equals(type.name())) {
|
||||||
|
return "TIMESTAMP";
|
||||||
|
} else if (FieldType.Bytes.name().equals(type.name())) {
|
||||||
|
return "BLOB";
|
||||||
|
} else if (FieldType.String_1.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.String_10.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.String_var.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var50.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var100.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var255.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var2500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var4000.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_super.name().equals(type.name())) {
|
||||||
|
//Oracle中LONG最大支持2G字节
|
||||||
|
return "LONG";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDataBaseType(FieldType type) {
|
||||||
|
if (FieldType.Boolean.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.Byte.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Short.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Integer.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Long.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Float.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Double.name().equals(type.name())) {
|
||||||
|
return "NUMBER";
|
||||||
|
} else if (FieldType.Date.name().equals(type.name())) {
|
||||||
|
return "TIMESTAMP";
|
||||||
|
} else if (FieldType.Bytes.name().equals(type.name())) {
|
||||||
|
return "BLOB";
|
||||||
|
} else if (FieldType.String_1.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.String_10.name().equals(type.name())) {
|
||||||
|
return "CHAR";
|
||||||
|
} else if (FieldType.String_var.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var50.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var255.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var2500.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_var4000.name().equals(type.name())) {
|
||||||
|
return "VARCHAR2";
|
||||||
|
} else if (FieldType.String_super.name().equals(type.name())) {
|
||||||
|
//Oracle中LONG最大支持2G字节
|
||||||
|
return "LONG";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldType getType(String type, int lenght, int precision, int scale) {
|
||||||
|
if ("CHAR".equals(type) && lenght == 1) {
|
||||||
|
return FieldType.String_1;
|
||||||
|
} else if ("CHAR".equals(type) && lenght == 10) {
|
||||||
|
return FieldType.String_10;
|
||||||
|
} else if ("CHAR".equals(type)) {
|
||||||
|
return FieldType.String_var;
|
||||||
|
} else if ("VARCHAR".equals(type) && lenght == 50) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if ("NVARCHAR".equals(type)) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if ("VARCHAR2".equals(type) && lenght == 50) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if ("VARCHAR2".equals(type) && lenght == 100) {
|
||||||
|
return FieldType.String_var100;
|
||||||
|
} else if ("VARCHAR2".equals(type) && lenght == 255) {
|
||||||
|
return FieldType.String_var255;
|
||||||
|
} else if ("VARCHAR2".equals(type) && lenght == 500) {
|
||||||
|
return FieldType.String_var500;
|
||||||
|
} else if ("VARCHAR2".equals(type) && lenght == 2500) {
|
||||||
|
return FieldType.String_var2500;
|
||||||
|
} else if ("VARCHAR2".equals(type) && lenght == 4000) {
|
||||||
|
return FieldType.String_var4000;
|
||||||
|
} else if ("VARCHAR2".equals(type)) {
|
||||||
|
return FieldType.String_var;
|
||||||
|
} else if ("NVARCHAR2".equals(type)) {
|
||||||
|
return FieldType.String_var100;
|
||||||
|
} else if ("CLOB".equals(type)) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if ("NCLOB".equals(type)) {
|
||||||
|
return FieldType.String_var50;
|
||||||
|
} else if ("LONG".equals(type)) {
|
||||||
|
return FieldType.String_super;
|
||||||
|
} else if ("NUMBER".equals(type)) {
|
||||||
|
if (precision > 18 && scale == 0) {
|
||||||
|
return FieldType.Long;
|
||||||
|
} else if (precision >= 10 && precision <= 18 && scale == 0) {
|
||||||
|
return FieldType.Long;
|
||||||
|
} else if (precision >= 1 && precision <= 9 && scale == 0) {
|
||||||
|
return FieldType.Integer;
|
||||||
|
} else if (scale > 0) {
|
||||||
|
return FieldType.Double;
|
||||||
|
} else {
|
||||||
|
return FieldType.Long;
|
||||||
|
}
|
||||||
|
} else if ("DATE".equals(type)) {
|
||||||
|
return FieldType.Date;
|
||||||
|
} else if ("TIMESTAMP".equals(type)) {
|
||||||
|
return FieldType.Date;
|
||||||
|
}
|
||||||
|
return FieldType.String_var50;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import javafx.scene.control.TreeItem;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Project extends TreeItem{
|
||||||
|
|
||||||
|
public Project() {
|
||||||
|
this.projectName = "EXAMPLE-WEB";
|
||||||
|
this.projectBasePackage = "com.example";
|
||||||
|
this.projectAuthor = "author";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
setValue(projectName);
|
||||||
|
setExpanded(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String projectName;
|
||||||
|
private String projectBasePackage;
|
||||||
|
private String projectAuthor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象
|
||||||
|
*/
|
||||||
|
private List<Module> modules = new ArrayList();
|
||||||
|
|
||||||
|
public boolean putModule(Module module) {
|
||||||
|
modules.add(module);
|
||||||
|
this.getChildren().add(module);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
this.setValue(projectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectBasePackage() {
|
||||||
|
return projectBasePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectBasePackage(String projectBasePackage) {
|
||||||
|
this.projectBasePackage = projectBasePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectAuthor() {
|
||||||
|
return projectAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectAuthor(String projectAuthor) {
|
||||||
|
this.projectAuthor = projectAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Module> getModules() {
|
||||||
|
return modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModules(List<Module> modules) {
|
||||||
|
this.modules = modules;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,186 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.po;
|
||||||
|
|
||||||
|
import javafx.scene.control.TreeItem;
|
||||||
|
import xyz.wbsite.dbtool.javafx.tool.Tool;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Table extends TreeItem {
|
||||||
|
private Module dBhandle;
|
||||||
|
|
||||||
|
public Table() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table(String tableName) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
setValue(tableName);
|
||||||
|
setExpanded(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table(String tableName, String tableComment) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
this.tableComment = tableComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象名
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象注释
|
||||||
|
*/
|
||||||
|
private String tableComment;
|
||||||
|
|
||||||
|
private Boolean create = true;
|
||||||
|
private Boolean delete = true;
|
||||||
|
private Boolean update = true;
|
||||||
|
private Boolean find = true;
|
||||||
|
private Boolean get = true;
|
||||||
|
private Boolean search = false;
|
||||||
|
private Boolean getAll = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象字段
|
||||||
|
*/
|
||||||
|
private List<Field> fields = new ArrayList();
|
||||||
|
|
||||||
|
public boolean has(String type) {
|
||||||
|
for (Field field : fields) {
|
||||||
|
if (field.getFieldType().name().equals(type) && !field.getIsSystem()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImport() {
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
if (has("Date")) {
|
||||||
|
sb.append("import java.util.Date;\n");
|
||||||
|
}
|
||||||
|
if (has("BigDecimal")) {
|
||||||
|
sb.append("import java.math.BigDecimal;\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean putField(Field field) {
|
||||||
|
if (fields == null) {
|
||||||
|
fields = new ArrayList<Field>();
|
||||||
|
}
|
||||||
|
fields.add(field);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean putFirstField(Field field) {
|
||||||
|
if (fields == null) {
|
||||||
|
fields = new ArrayList<Field>();
|
||||||
|
}
|
||||||
|
fields.add(0, field);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCName() {
|
||||||
|
return Tool.lineToClassName(this.tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFName() {
|
||||||
|
return Tool.lineToFieldName(this.tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLName() {
|
||||||
|
return Tool.lineToLPoint(this.tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTableName() {
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableName(String tableName) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
setValue(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTableComment() {
|
||||||
|
return tableComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableComment(String tableComment) {
|
||||||
|
this.tableComment = tableComment!=null?tableComment:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Field> getFields() {
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFields(List<Field> fields) {
|
||||||
|
this.fields = fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Module getdBhandle() {
|
||||||
|
return dBhandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setdBhandle(Module dBhandle) {
|
||||||
|
this.dBhandle = dBhandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getCreate() {
|
||||||
|
return create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreate(Boolean create) {
|
||||||
|
this.create = create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getDelete() {
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelete(Boolean delete) {
|
||||||
|
this.delete = delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getUpdate() {
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdate(Boolean update) {
|
||||||
|
this.update = update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getFind() {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFind(Boolean find) {
|
||||||
|
this.find = find;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getGet() {
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGet(Boolean get) {
|
||||||
|
this.get = get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getSearch() {
|
||||||
|
return search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearch(Boolean search) {
|
||||||
|
this.search = search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getGetAll() {
|
||||||
|
return getAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGetAll(Boolean getAll) {
|
||||||
|
this.getAll = getAll;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,569 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.tool;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.Application;
|
||||||
|
import xyz.wbsite.dbtool.javafx.ctrl.ConnectInfoController;
|
||||||
|
import xyz.wbsite.dbtool.javafx.ctrl.GenerateOptionController;
|
||||||
|
import xyz.wbsite.dbtool.javafx.ctrl.SdkInfoController;
|
||||||
|
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
|
||||||
|
import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
|
||||||
|
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Api;
|
||||||
|
import xyz.wbsite.dbtool.javafx.po.Module;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.DirectoryChooser;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.WindowEvent;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Dialog {
|
||||||
|
|
||||||
|
private static Stage popup;
|
||||||
|
|
||||||
|
public static void showTimedDialog(final long time, String message) {
|
||||||
|
popup = new Stage();
|
||||||
|
popup.setAlwaysOnTop(true);
|
||||||
|
popup.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
final Button closeBtn = new Button("知道了");
|
||||||
|
closeBtn.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
VBox root = new VBox();
|
||||||
|
root.setPadding(new Insets(20));
|
||||||
|
root.setAlignment(Pos.BASELINE_CENTER);
|
||||||
|
root.setSpacing(20);
|
||||||
|
root.getChildren().addAll(new Label(message), closeBtn);
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
popup.setScene(scene);
|
||||||
|
popup.setTitle("提示信息");
|
||||||
|
popup.show();
|
||||||
|
|
||||||
|
Thread thread = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(time);
|
||||||
|
if (popup.isShowing()) {
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (Exception exp) {
|
||||||
|
exp.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showConfirmDialog(String message) {
|
||||||
|
popup = new Stage();
|
||||||
|
popup.setAlwaysOnTop(true);
|
||||||
|
popup.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
final Button closeBtn = new Button("确认");
|
||||||
|
closeBtn.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
VBox root = new VBox();
|
||||||
|
root.setPadding(new Insets(20));
|
||||||
|
root.setAlignment(Pos.BASELINE_CENTER);
|
||||||
|
root.setSpacing(20);
|
||||||
|
Label label = new Label(message);
|
||||||
|
root.getChildren().addAll(label, closeBtn);
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
popup.setScene(scene);
|
||||||
|
popup.setTitle("提示信息");
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showError(String message) {
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("错误");
|
||||||
|
alert.setHeaderText("");
|
||||||
|
alert.setContentText(message);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showSuccess(String message) {
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle("消息");
|
||||||
|
alert.setHeaderText("");
|
||||||
|
alert.setContentText(message);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showProgress(String message) {
|
||||||
|
if (popup != null) {
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
popup = new Stage();
|
||||||
|
popup.setAlwaysOnTop(true);
|
||||||
|
popup.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
ProgressIndicator indicator = new ProgressIndicator();
|
||||||
|
indicator.setPrefSize(30, 30);
|
||||||
|
|
||||||
|
VBox root = new VBox();
|
||||||
|
root.setPadding(new Insets(50, 80, 50, 80));
|
||||||
|
root.setAlignment(Pos.BASELINE_CENTER);
|
||||||
|
root.setSpacing(20);
|
||||||
|
|
||||||
|
Label label = new Label(message);
|
||||||
|
root.getChildren().addAll(indicator, label);
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
|
||||||
|
popup.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WindowEvent event) {
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popup.setScene(scene);
|
||||||
|
popup.setTitle("提示");
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopPopup() {
|
||||||
|
if (popup != null) {
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showGenerateOption(GenerateOptionListener listener) {
|
||||||
|
FXMLLoader dbdetailloader = new FXMLLoader(Application.class.getResource("../../../fxml/generateOption.fxml"));
|
||||||
|
try {
|
||||||
|
dbdetailloader.load();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Parent root = dbdetailloader.getRoot();
|
||||||
|
GenerateOptionController controller = dbdetailloader.getController();
|
||||||
|
controller.setListener(listener);
|
||||||
|
controller.getCancel().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
stopPopup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getOk().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
listener.onGenerate(controller.getType(), DataBase.valueOf(controller.getDataBase().toUpperCase()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
popup = new Stage();
|
||||||
|
popup.setAlwaysOnTop(true);
|
||||||
|
popup.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
|
||||||
|
popup.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WindowEvent event) {
|
||||||
|
stopPopup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popup.setScene(scene);
|
||||||
|
popup.setTitle("配置");
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDBConnectInput() {
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.setAlwaysOnTop(true);
|
||||||
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
FXMLLoader dbdetailloader = new FXMLLoader(Application.class.getResource("../../../fxml/connectInfo.fxml"));
|
||||||
|
try {
|
||||||
|
dbdetailloader.load();
|
||||||
|
Parent root = dbdetailloader.getRoot();
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.setTitle("连接信息");
|
||||||
|
|
||||||
|
ConnectInfoController controller = dbdetailloader.getController();
|
||||||
|
|
||||||
|
ChoiceBox databaseType = controller.getDatabaseType();
|
||||||
|
ObservableList<String> data = FXCollections.observableArrayList();
|
||||||
|
data.add("Orcale");
|
||||||
|
data.add("Mysql");
|
||||||
|
databaseType.setItems(data);
|
||||||
|
databaseType.setValue("Orcale");
|
||||||
|
databaseType.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
String value = (String) databaseType.getValue();
|
||||||
|
|
||||||
|
if ("Orcale".equals(value)) {
|
||||||
|
controller.getDriver().setText("oracle.jdbc.OracleDriver");
|
||||||
|
controller.getUrl().setText("jdbc:oracle:thin:@127.0.0.1:1521:orcl");
|
||||||
|
} else if ("Mysql".equals(value)) {
|
||||||
|
controller.getDriver().setText("com.mysql.jdbc.Driver");
|
||||||
|
controller.getUrl().setText("jdbc:mysql://127.0.0.1:3306/tableName");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
TextField driver = controller.getDriver();
|
||||||
|
driver.setText(Info.orcle.driver);
|
||||||
|
TextField url = controller.getUrl();
|
||||||
|
url.setText(Info.orcle.url);
|
||||||
|
|
||||||
|
Button test = controller.getTest();
|
||||||
|
test.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
String type = (String) controller.getDatabaseType().getValue();
|
||||||
|
String driver = controller.getDriver().getText();
|
||||||
|
String url = controller.getUrl().getText();
|
||||||
|
String userName = controller.getUserName().getText();
|
||||||
|
String password = controller.getPassword().getText();
|
||||||
|
|
||||||
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
map.put("type", type);
|
||||||
|
map.put("url", url);
|
||||||
|
map.put("username", userName);
|
||||||
|
map.put("password", password);
|
||||||
|
map.put("driverClassName", driver);
|
||||||
|
boolean b = ProjectManager.testConnect(map);
|
||||||
|
if (b) {
|
||||||
|
Dialog.showConfirmDialog("连接成功!");
|
||||||
|
} else {
|
||||||
|
Dialog.showConfirmDialog("连接失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Button load = controller.getLoad();
|
||||||
|
load.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
String type = (String) controller.getDatabaseType().getValue();
|
||||||
|
String driver = controller.getDriver().getText();
|
||||||
|
String url = controller.getUrl().getText();
|
||||||
|
String userName = controller.getUserName().getText();
|
||||||
|
String password = controller.getPassword().getText();
|
||||||
|
|
||||||
|
if (driver == null || driver.equals("")) {
|
||||||
|
Dialog.showConfirmDialog("驱动名称不能为空!");
|
||||||
|
return;
|
||||||
|
} else if (url == null || url.equals("")) {
|
||||||
|
Dialog.showConfirmDialog("连接不能为空!");
|
||||||
|
return;
|
||||||
|
} else if (userName == null || userName.equals("")) {
|
||||||
|
Dialog.showConfirmDialog("用户名不能为空!");
|
||||||
|
return;
|
||||||
|
} else if (password == null || password.equals("")) {
|
||||||
|
Dialog.showConfirmDialog("密码不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Module db : ManagerFactory.getdBManager().getMds()) {
|
||||||
|
if (db.getModuleName().equals(userName)) {
|
||||||
|
Dialog.showConfirmDialog("已经存的模块!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
map.put("type", type);
|
||||||
|
map.put("url", url);
|
||||||
|
map.put("username", userName);
|
||||||
|
map.put("password", password);
|
||||||
|
map.put("driverClassName", driver);
|
||||||
|
|
||||||
|
Dialog.showProgress("加载中,请稍等...");
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (popup.isShowing() && ProjectManager.loadMD(map)) {
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Dialog.stopPopup();
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Button cancel = controller.getCancel();
|
||||||
|
cancel.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
stage.show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showApi() {
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
FXMLLoader dbdetailloader = new FXMLLoader(Application.class.getResource("../../../fxml/api.fxml"));
|
||||||
|
try {
|
||||||
|
dbdetailloader.load();
|
||||||
|
Parent root = dbdetailloader.getRoot();
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.setTitle("API生成");
|
||||||
|
|
||||||
|
SdkInfoController controller = dbdetailloader.getController();
|
||||||
|
TextField modulePath = controller.getModulePath();
|
||||||
|
TextField sdkPath = controller.getSdkPath();
|
||||||
|
TableView apis = controller.getApis();
|
||||||
|
|
||||||
|
controller.getSelectModulePath().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.setAlwaysOnTop(true);
|
||||||
|
File file = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modulePath.setText(file.getAbsolutePath());
|
||||||
|
|
||||||
|
|
||||||
|
File api = new File(sdkPath.getText());
|
||||||
|
sdkPath.setText(new File(api.getParentFile().getAbsolutePath(),file.getName()+"-api").getAbsolutePath());
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.getSelectSdkPath().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
File file = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String text = modulePath.getText();
|
||||||
|
File moduleFile = new File(text);
|
||||||
|
|
||||||
|
sdkPath.setText(new File(file.getAbsolutePath(),moduleFile.getName()+"-api").getAbsolutePath());
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.getAll().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getAll().isSelected(), "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getApi().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getApi().isSelected(), ".api.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getCreate().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getCreate().isSelected(), ".create");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getDelete().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getDelete().isSelected(), ".delete");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getUpdate().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getUpdate().isSelected(), ".update");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getFind().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getFind().isSelected(), ".find");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getSearch().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getSearch().isSelected(), ".search");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getGet().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getGet().isSelected(), ".get");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.getGetAll().setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
check(controller, controller.getGetAll().isSelected(), ".get.all");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sdkPath.requestFocus();
|
||||||
|
modulePath.textProperty().addListener(new ChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||||
|
controller.load();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ProjectManager dBmanger = ManagerFactory.getdBManager();
|
||||||
|
String path = dBmanger.getPath();
|
||||||
|
|
||||||
|
File file = new File(path);
|
||||||
|
File[] files = file.listFiles();
|
||||||
|
s:
|
||||||
|
for (File f : files) {
|
||||||
|
if (!f.getName().contains(".")) {
|
||||||
|
File modul = findModul(f);
|
||||||
|
if (modul == null) {
|
||||||
|
modulePath.setText("");
|
||||||
|
sdkPath.setText("");
|
||||||
|
} else {
|
||||||
|
modulePath.setText(modul.getAbsolutePath());
|
||||||
|
sdkPath.setText(new File(f.getParentFile().getAbsolutePath(),modul.getName() + "-api").getAbsolutePath());
|
||||||
|
break s;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button start = controller.getStart();
|
||||||
|
start.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
String module = controller.getModulePath().getText();
|
||||||
|
String sdk = controller.getSdkPath().getText();
|
||||||
|
|
||||||
|
if (new File(module).exists()) {
|
||||||
|
Dialog.showProgress("生成中...");
|
||||||
|
dBmanger.generateSDK(new File(module), new File(sdk), controller.getData());
|
||||||
|
Dialog.stopPopup();
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Dialog.showConfirmDialog("项目不存在!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button cancel = controller.getCancel();
|
||||||
|
cancel.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
stage.show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void check(SdkInfoController controller, boolean check, String key) {
|
||||||
|
for (Api api : controller.getData()) {
|
||||||
|
if (api.getMethod().endsWith(key) || (key.equals(".api.") && api.getMethod().contains(".api."))) {
|
||||||
|
api.setCheck(check);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
controller.initData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasChild(File file, String child) {
|
||||||
|
if (file == null || child == null || "".equals(child) || file.listFiles() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File f : file.listFiles()) {
|
||||||
|
if (f.getName().equals(child)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File findModul(File file) {
|
||||||
|
if (file == null) {
|
||||||
|
return null;
|
||||||
|
} else if (hasChild(file, "ent") && hasChild(file, "req") && hasChild(file, "rsp")) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.listFiles() != null) {
|
||||||
|
for (File f : file.listFiles()) {
|
||||||
|
File modul = findModul(f);
|
||||||
|
if (modul != null) {
|
||||||
|
return modul;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.tool;
|
||||||
|
|
||||||
|
public class Info {
|
||||||
|
static DBInfo orcle = new DBInfo();
|
||||||
|
static DBInfo mysql = new DBInfo();
|
||||||
|
|
||||||
|
static {
|
||||||
|
orcle.url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
|
||||||
|
orcle.userName = "userName";
|
||||||
|
orcle.password = "";
|
||||||
|
orcle.driver = "oracle.jdbc.OracleDriver";
|
||||||
|
mysql.url = "jdbc:mysql://119.23.203.111:3306/test";
|
||||||
|
mysql.userName = "userName";
|
||||||
|
mysql.password = "";
|
||||||
|
mysql.driver = "com.mysql.jdbc.Driver";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
class DBInfo{
|
||||||
|
String url;
|
||||||
|
String userName;
|
||||||
|
String password;
|
||||||
|
String driver;
|
||||||
|
}
|
@ -0,0 +1,356 @@
|
|||||||
|
package xyz.wbsite.dbtool.javafx.tool;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class Tool {
|
||||||
|
|
||||||
|
public static final char UNDERLINE = '_';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* abbCdd --> abb_cdd
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String camelToUnderline(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
int len = param.length();
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = param.charAt(i);
|
||||||
|
if (Character.isUpperCase(c)) {
|
||||||
|
sb.append(UNDERLINE);
|
||||||
|
sb.append(Character.toLowerCase(c));
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* abbCdd --> abb.cdd
|
||||||
|
* AbbCdd --> abb.cdd
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String camelToPoint(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
param = Character.toLowerCase(param.charAt(0)) + param.substring(1, param.length());
|
||||||
|
int len = param.length();
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = param.charAt(i);
|
||||||
|
if (Character.isUpperCase(c)) {
|
||||||
|
sb.append(".");
|
||||||
|
sb.append(Character.toLowerCase(c));
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileCreateRequest -> file
|
||||||
|
*
|
||||||
|
* @param requestName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getRequestTarget(String requestName) {
|
||||||
|
if (requestName.contains("GetAllRequest")) {
|
||||||
|
return Abb2abb(requestName.substring(0, requestName.indexOf("GetAllRequest")));
|
||||||
|
}
|
||||||
|
if (requestName.startsWith("Api")) {
|
||||||
|
return "api";
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = camelToPoint(requestName);
|
||||||
|
String[] split = s.split("\\.");
|
||||||
|
if (split.length > 2) {
|
||||||
|
String target = split[0];
|
||||||
|
for (int i = 1; i < split.length - 2; i++) {
|
||||||
|
target += abb2Abb(split[i]);
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileCreateRequest -> create
|
||||||
|
*
|
||||||
|
* @param requestName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getRequestAction(String requestName) {
|
||||||
|
String s = camelToPoint(requestName);
|
||||||
|
|
||||||
|
if (requestName.contains("GetAllRequest")) {
|
||||||
|
return "getAll";
|
||||||
|
}
|
||||||
|
if (requestName.startsWith("Api")) {
|
||||||
|
return Abb2abb(requestName.substring(3, requestName.indexOf("Request")));
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] split = s.split("\\.");
|
||||||
|
if (split.length > 2) {
|
||||||
|
String action = split[split.length - 2];
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String Abb2abb(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
param = Character.toLowerCase(param.charAt(0)) + param.substring(1, param.length());
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String abb2Abb(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
param = Character.toUpperCase(param.charAt(0)) + param.substring(1, param.length());
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下划线转首字母大写驼峰式
|
||||||
|
* ABB_CDD --> AbbCdd
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String lineToClassName(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
//全部转小写
|
||||||
|
param = param.toLowerCase();
|
||||||
|
int len = param.length();
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = param.charAt(i);
|
||||||
|
if (c == UNDERLINE) {
|
||||||
|
if (++i < len) {
|
||||||
|
sb.append(Character.toUpperCase(param.charAt(i)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//首字符转大写
|
||||||
|
return (new StringBuilder()).append(Character.toUpperCase(sb.charAt(0))).append(sb.substring(1)).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下划线转首字母小写驼峰样式
|
||||||
|
* ABB_CDD --> abbCdd
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String lineToFieldName(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
//全部转小写
|
||||||
|
param = param.toLowerCase();
|
||||||
|
int len = param.length();
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = param.charAt(i);
|
||||||
|
if (c == UNDERLINE) {
|
||||||
|
if (++i < len) {
|
||||||
|
sb.append(Character.toUpperCase(param.charAt(i)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下划线转首字母小写驼峰样式
|
||||||
|
* ABB_CDD --> abbcdd
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String lineToLowercase(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
//全部转小写
|
||||||
|
param = param.toLowerCase();
|
||||||
|
int len = param.length();
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = param.charAt(i);
|
||||||
|
if (c == UNDERLINE) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下划线转点分割小写样式
|
||||||
|
* ABB_CDD --> abb.cdd
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String lineToLPoint(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
//全部转小写
|
||||||
|
param = param.toLowerCase();
|
||||||
|
int len = param.length();
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char c = param.charAt(i);
|
||||||
|
if (c == UNDERLINE) {
|
||||||
|
sb.append(".");
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String lineToCamel2(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder(param);
|
||||||
|
Matcher mc = Pattern.compile("_").matcher(param);
|
||||||
|
int i = 0;
|
||||||
|
while (mc.find()) {
|
||||||
|
int position = mc.end() - (i++);
|
||||||
|
//String.valueOf(Character.toUpperCase(sb.charAt(position)));
|
||||||
|
sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String pointToPath(String param) {
|
||||||
|
if (param == null || "".equals(param.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return param.replaceAll("\\.", "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String print(String param) {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void outputResource(String url, File file) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (url != null && url.startsWith("/")) {
|
||||||
|
url = url.substring(1);
|
||||||
|
}
|
||||||
|
url = "modules/" + url;
|
||||||
|
|
||||||
|
InputStream resourceAsStream = null;
|
||||||
|
FileOutputStream fileOutputStream = null;
|
||||||
|
try {
|
||||||
|
URL resource = Tool.class.getClassLoader().getResource("/");
|
||||||
|
resourceAsStream = Tool.class.getClassLoader().getResourceAsStream(url);
|
||||||
|
fileOutputStream = new FileOutputStream(file);
|
||||||
|
if (resourceAsStream == null) {
|
||||||
|
resourceAsStream = Tool.class.getResourceAsStream("../../../../" + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
int b = -1;
|
||||||
|
|
||||||
|
while ((b = resourceAsStream.read()) != -1) {
|
||||||
|
fileOutputStream.write(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
resourceAsStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
fileOutputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear(File f) {
|
||||||
|
clear(f, ".idea|.*iml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param f 目录
|
||||||
|
* @param exclude 排除
|
||||||
|
*/
|
||||||
|
public static void clear(File f, String exclude) {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
File[] files = f.listFiles(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if (exclude == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !pathname.getName().matches(exclude);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
clear(file, exclude);
|
||||||
|
System.out.println("删除文件夹" + file.getName() + (file.delete() ? "成功" : "失败"));
|
||||||
|
} else {
|
||||||
|
System.out.println("删除" + file.getName() + (file.delete() ? "成功" : "失败"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void exchange(List list, int i, int j) {
|
||||||
|
Object o1 = list.get(i);
|
||||||
|
Object o2 = list.get(j);
|
||||||
|
|
||||||
|
list.add(i, o2);
|
||||||
|
list.remove(i + 1);
|
||||||
|
list.add(j, o1);
|
||||||
|
list.remove(j + 1);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.controller;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.web.framework.LocalData;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.Message;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.base.BaseResponse;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.base.Error;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.base.ErrorType;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.base.Token;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.utils.LogUtil;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.utils.MapperUtil;
|
||||||
|
import com.fasterxml.jackson.core.TreeNode;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class AjaxController {
|
||||||
|
|
||||||
|
@RequestMapping("/ajax")
|
||||||
|
public BaseResponse ajax(@RequestParam("method") String method, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
|
||||||
|
BaseResponse baseResponse = new BaseResponse();
|
||||||
|
String line = null;
|
||||||
|
TreeNode treeNode = null;
|
||||||
|
try {
|
||||||
|
if (method == null) {
|
||||||
|
baseResponse.addError(new xyz.wbsite.dbtool.web.framework.base.Error(ErrorType.BUSINESS_ERROR, "请求方法不能为空!"));
|
||||||
|
return baseResponse;
|
||||||
|
}
|
||||||
|
Token token = LocalData.getToken();
|
||||||
|
if (token == null) {
|
||||||
|
token = LocalData.getTempToken();
|
||||||
|
}
|
||||||
|
if (!token.hasResource(method)) {
|
||||||
|
baseResponse.addError(new Error(ErrorType.BUSINESS_ERROR, "无权调用该接口!"));
|
||||||
|
return baseResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStreamReader isr = new InputStreamReader(request.getInputStream());
|
||||||
|
BufferedReader in = new BufferedReader(isr);
|
||||||
|
line = in.readLine();
|
||||||
|
treeNode = MapperUtil.toTree(line);
|
||||||
|
|
||||||
|
switch (method) {
|
||||||
|
// 创建注释
|
||||||
|
case "ajax.example.user.create":
|
||||||
|
// baseResponse = createUser(treeNode, token);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
baseResponse.addError(ErrorType.INVALID_PARAMETER, Message.NOT_EXIST_METHOD);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
baseResponse.addError(ErrorType.SYSTEM_ERROR, Message.ERROR_500);
|
||||||
|
LogUtil.dumpException(ex);
|
||||||
|
} finally {
|
||||||
|
if (baseResponse.hasError()) {
|
||||||
|
LogUtil.e("请求方法" + method + ", 请求参数:" + line);
|
||||||
|
LogUtil.e("返回结果包含异常" + MapperUtil.toJson(baseResponse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return baseResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework;
|
||||||
|
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.web.framework.base.Token;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LocalData - 本地数据存放类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class LocalData implements Serializable{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static Token temp = null;
|
||||||
|
|
||||||
|
static {
|
||||||
|
temp = new Token();
|
||||||
|
temp.setId(-1);
|
||||||
|
temp.setUserId(-1);
|
||||||
|
temp.setUserName("游客");
|
||||||
|
temp.putResource("/");
|
||||||
|
temp.putResource("/index");
|
||||||
|
temp.putResource("/login");
|
||||||
|
temp.putResource("/ajax");
|
||||||
|
temp.putResource("ajax.example.example");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Token getTempToken(){
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前用户的通行证
|
||||||
|
*/
|
||||||
|
private static final ThreadLocal<Token> tokenHolder = new ThreadLocal();
|
||||||
|
|
||||||
|
public static Token getToken() {
|
||||||
|
return tokenHolder.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setToken(Token token) {
|
||||||
|
tokenHolder.set(token);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,507 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static byte[] decode(char[] sArr) {
|
||||||
|
// Check special case
|
||||||
|
int sLen = sArr != null ? sArr.length : 0;
|
||||||
|
if(sLen == 0)
|
||||||
|
return new byte[0];
|
||||||
|
|
||||||
|
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
|
||||||
|
// so we don't have to reallocate & copy it later.
|
||||||
|
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
|
||||||
|
for(int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
|
||||||
|
if(IA[sArr[i]] < 0)
|
||||||
|
sepCnt++;
|
||||||
|
|
||||||
|
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
|
||||||
|
if((sLen - sepCnt) % 4 != 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
int pad = 0;
|
||||||
|
for(int i = sLen; i > 1 && IA[sArr[--i]] <= 0; )
|
||||||
|
if(sArr[i] == '=')
|
||||||
|
pad++;
|
||||||
|
|
||||||
|
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
|
||||||
|
|
||||||
|
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
|
||||||
|
|
||||||
|
for(int s = 0, d = 0; d < len; ) {
|
||||||
|
// Assemble three bytes into an int from four "valid" characters.
|
||||||
|
int i = 0;
|
||||||
|
for(int j = 0; j < 4; j++) { // j only increased if a valid char was found.
|
||||||
|
int c = IA[sArr[s++]];
|
||||||
|
if(c >= 0)
|
||||||
|
i |= c << (18 - j * 6);
|
||||||
|
else
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
// Add the bytes
|
||||||
|
dArr[d++] = (byte) (i >> 16);
|
||||||
|
if(d < len) {
|
||||||
|
dArr[d++] = (byte) (i >> 8);
|
||||||
|
if(d < len)
|
||||||
|
dArr[d++] = (byte) i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as
|
||||||
|
* fast as {@link #decode(char[])}. The preconditions are:<br>
|
||||||
|
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
|
||||||
|
* + Line separator must be "\r\n", as specified in RFC 2045
|
||||||
|
* + The array must not contain illegal characters within the encoded string<br>
|
||||||
|
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ****************************************************************************************
|
||||||
|
// * String version
|
||||||
|
// ****************************************************************************************
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 s The source string. Length 0 will return an empty array. <code>null</code> will throw an exception.
|
||||||
|
* @return The decoded array of bytes. May be of length 0.
|
||||||
|
*/
|
||||||
|
public final static byte[] decodeFast(String s) {
|
||||||
|
// Check special case
|
||||||
|
int sLen = s.length();
|
||||||
|
if(sLen == 0)
|
||||||
|
return new byte[0];
|
||||||
|
|
||||||
|
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
|
||||||
|
|
||||||
|
// Trim illegal chars from start
|
||||||
|
while(sIx < eIx && IA[s.charAt(sIx) & 0xff] < 0)
|
||||||
|
sIx++;
|
||||||
|
|
||||||
|
// Trim illegal chars from end
|
||||||
|
while(eIx > 0 && IA[s.charAt(eIx) & 0xff] < 0)
|
||||||
|
eIx--;
|
||||||
|
|
||||||
|
// get the padding count (=) (0, 1 or 2)
|
||||||
|
int pad = s.charAt(eIx) == '=' ? (s.charAt(eIx - 1) == '=' ? 2 : 1) : 0; // Count '=' at end.
|
||||||
|
int cCnt = eIx - sIx + 1; // Content count including possible separators
|
||||||
|
int sepCnt = sLen > 76 ? (s.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[s.charAt(sIx++)] << 18 | IA[s.charAt(sIx++)] << 12 | IA[s.charAt(sIx++)] << 6 | IA[s.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[s.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("我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1我搜搜1".getBytes(), false);
|
||||||
|
System.out.println(s);
|
||||||
|
|
||||||
|
byte[] decode = Base64Util.decode(s);
|
||||||
|
System.out.println(new String(decode));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行版本
|
||||||
|
*/
|
||||||
|
private long rowVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用户
|
||||||
|
*/
|
||||||
|
private long createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后更新用户
|
||||||
|
*/
|
||||||
|
private long lastUpdateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后更新时间
|
||||||
|
*/
|
||||||
|
private Date lastUpdateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否删除
|
||||||
|
*/
|
||||||
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
|
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,75 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BaseFindRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class BaseFindRequest extends BaseRequest {
|
||||||
|
private long pageNumber = 1L;
|
||||||
|
private long pageSize = 10L;
|
||||||
|
private long beginIndex = 0;
|
||||||
|
private long endIndex = 10;
|
||||||
|
private String sortKey;
|
||||||
|
private SortType sortType;
|
||||||
|
|
||||||
|
public String getSortKey() {
|
||||||
|
return sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortKey(String sortKey) {
|
||||||
|
this.sortKey = sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortType getSortType() {
|
||||||
|
return sortType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortType(SortType sortType) {
|
||||||
|
this.sortType = sortType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPageNumber() {
|
||||||
|
return pageNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNumber(long pageNumber) {
|
||||||
|
this.pageNumber = pageNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize(long pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getBeginIndex() {
|
||||||
|
beginIndex = pageSize * (pageNumber - 1);
|
||||||
|
return beginIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBeginIndex(long beginIndex) {
|
||||||
|
this.beginIndex = beginIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEndIndex() {
|
||||||
|
endIndex = pageSize * (pageNumber - 1) + pageSize;
|
||||||
|
return endIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndIndex(long endIndex) {
|
||||||
|
this.endIndex = endIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePageNumber(Long totalCount){
|
||||||
|
long maxPage = totalCount / pageSize + (totalCount % pageSize > 0 ? 1 : 0);
|
||||||
|
|
||||||
|
if (pageNumber > maxPage){
|
||||||
|
pageNumber = maxPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.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,12 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BaseRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class BaseRequest {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.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.dbtool.web.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,38 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error - 错误基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class Error {
|
||||||
|
|
||||||
|
/*错误类型*/
|
||||||
|
private ErrorType type;
|
||||||
|
|
||||||
|
/*错误内容*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
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.dbtool.web.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,17 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SortTypeEnum - 排序方式
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public enum SortType {
|
||||||
|
|
||||||
|
//升序
|
||||||
|
ASC,
|
||||||
|
|
||||||
|
//降序
|
||||||
|
DESC
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.base;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collection;
|
||||||
|
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){
|
||||||
|
return resourceSet.contains(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putResource(String resource){
|
||||||
|
resourceSet.add(resource);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.config;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.web.framework.freemarker.FreemarkerViewNameTranslator;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.freemarker.Layout;
|
||||||
|
import xyz.wbsite.dbtool.web.framework.freemarker.Url;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;
|
||||||
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||||
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FreemarkerViewName解析器
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class FreeMarkerConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Layout layout;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Url url;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected FreeMarkerViewResolver resolver;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected FreeMarkerConfigurer freeMarkerConfigurer;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void setSharedVariable() {
|
||||||
|
//设置基本工具类
|
||||||
|
Map<String, Object> attributesMap = resolver.getAttributesMap();
|
||||||
|
attributesMap.put("Layout", layout);
|
||||||
|
attributesMap.put("Url", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析器
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean(name = "viewNameTranslator")
|
||||||
|
public DefaultRequestToViewNameTranslator getViewNameTranslator() {
|
||||||
|
FreemarkerViewNameTranslator nameTranslator = new FreemarkerViewNameTranslator();
|
||||||
|
nameTranslator.setViewResolver(resolver);
|
||||||
|
return nameTranslator;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.config;
|
||||||
|
|
||||||
|
import xyz.wbsite.dbtool.web.framework.interceptor.GlobalInterceptor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.*;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CharacterEncodingFilter characterEncodingFilter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
//增加全局拦截器
|
||||||
|
registry.addInterceptor(new GlobalInterceptor()).addPathPatterns("/*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FilterRegistrationBean characterEncodingFilterRegistration() {
|
||||||
|
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||||
|
//注入过滤器
|
||||||
|
registration.setFilter(characterEncodingFilter);
|
||||||
|
//拦截规则
|
||||||
|
registration.addUrlPatterns("/*");
|
||||||
|
//过滤器名称
|
||||||
|
registration.setName("CharacterEncodingFilter");
|
||||||
|
//过滤器顺序
|
||||||
|
registration.setOrder(1);
|
||||||
|
return registration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CharacterEncodingFilter characterEncodingFilter() {
|
||||||
|
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
|
||||||
|
characterEncodingFilter.setEncoding("UTF-8");
|
||||||
|
characterEncodingFilter.setForceEncoding(true);
|
||||||
|
return characterEncodingFilter;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.freemarker;
|
||||||
|
|
||||||
|
import freemarker.template.TemplateModelException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
import org.springframework.web.servlet.LocaleResolver;
|
||||||
|
import org.springframework.web.servlet.View;
|
||||||
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 布局帮助类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class Layout {
|
||||||
|
|
||||||
|
@Value("${web.welcome.page}")
|
||||||
|
private String homePage;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FreeMarkerViewResolver viewResolver;
|
||||||
|
|
||||||
|
private String screenPrefix = "/screen/";
|
||||||
|
private String controlPrefix = "/control/";
|
||||||
|
private String suffix = ".ftl";
|
||||||
|
|
||||||
|
public String setScreen() throws TemplateModelException {
|
||||||
|
try {
|
||||||
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE);
|
||||||
|
String servletPath = request.getServletPath();
|
||||||
|
if ("/".equals(servletPath)) {
|
||||||
|
servletPath = this.homePage;
|
||||||
|
}
|
||||||
|
servletPath = servletPath.replaceAll("^/", "");
|
||||||
|
Locale locale = localeResolver.resolveLocale(request);
|
||||||
|
String viewName = "screen" + File.separator + servletPath;
|
||||||
|
View view = viewResolver.resolveViewName(viewName, locale);
|
||||||
|
//无法找到对应screen
|
||||||
|
if (view == null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return screenPrefix + servletPath + suffix;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setControl(String control) {
|
||||||
|
return controlPrefix + control + suffix;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Url帮助类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class Url {
|
||||||
|
|
||||||
|
public String setUrl(String url) throws TemplateModelException {
|
||||||
|
if (url == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
String contextPath = request.getContextPath();
|
||||||
|
|
||||||
|
if (url.startsWith("/")) {
|
||||||
|
return contextPath + url;
|
||||||
|
} else {
|
||||||
|
return contextPath + "/" + url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.interceptor;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
public class GlobalInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
|
||||||
|
// todo do something
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.springmvc;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringMVC 对象JSON化自定义转换器
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class GlobalObjectMapper extends ObjectMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置@ResponseBody 返回的JSON格式
|
||||||
|
*/
|
||||||
|
public GlobalObjectMapper() {
|
||||||
|
super();
|
||||||
|
// 将所有的Long变成String以兼容js
|
||||||
|
SimpleModule simpleModule = new SimpleModule("LongModule");
|
||||||
|
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||||
|
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||||
|
registerModule(simpleModule);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.utils;//package com.example.demo.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对json数据排序并签名
|
||||||
|
* @param appSecret
|
||||||
|
* @param currentTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String toSign(TreeNode treeNode, String appSecret, String currentTime) {
|
||||||
|
String typesetting = sortAndJson(treeNode);
|
||||||
|
System.out.println(typesetting);
|
||||||
|
return MD5Util.encode(appSecret + typesetting + currentTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String sortAndJson(TreeNode treeNode) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
Iterator<String> keyIterator = treeNode.fieldNames();
|
||||||
|
while (keyIterator.hasNext()){
|
||||||
|
String next = keyIterator.next();
|
||||||
|
sb.append(next).append(treeNode.get(next));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// private static String sortAndJson(JSONObject jsonObject) {
|
||||||
|
// List<String> data = new ArrayList(jsonObject.keySet());
|
||||||
|
// Collections.sort(data);
|
||||||
|
// StringBuffer sb = new StringBuffer();
|
||||||
|
//
|
||||||
|
// for (String s : data) {
|
||||||
|
// sb.append(s);
|
||||||
|
// Object o = jsonObject.get(s);
|
||||||
|
// if (o == null) {
|
||||||
|
// sb.append("");
|
||||||
|
// } else if (o instanceof JSONArray) {
|
||||||
|
// sb.append(sortAndJson((JSONArray) o));
|
||||||
|
// } else if (o instanceof JSONObject) {
|
||||||
|
// sb.append(sortAndJson((JSONObject) o));
|
||||||
|
// } else {
|
||||||
|
// sb.append(o.toString());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return sb.toString();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试实例
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,117 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.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.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.springframework.cglib.beans.BeanCopier;
|
||||||
|
import org.springframework.cglib.core.Converter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MapUtil - 映射转化工具类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class MapperUtil {
|
||||||
|
private static ObjectMapper om;
|
||||||
|
|
||||||
|
static {
|
||||||
|
//初始化
|
||||||
|
om = new ObjectMapper();
|
||||||
|
//序列化时忽略null属性
|
||||||
|
om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
//序列化时排序
|
||||||
|
om.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(String json, TypeReference valueTypeRef) {
|
||||||
|
try {
|
||||||
|
return om.readValue(json, valueTypeRef);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T map(Object object, Class<T> tClass) {
|
||||||
|
try {
|
||||||
|
T t = tClass.newInstance();
|
||||||
|
map(object, t);
|
||||||
|
return t;
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void map(Object object, Object target) {
|
||||||
|
map(object, target, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void map(Object object, Object target, Converter converter) {
|
||||||
|
BeanCopier copier = BeanCopier.create(object.getClass(), target.getClass(), converter != null);
|
||||||
|
copier.copy(object, target, converter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,225 @@
|
|||||||
|
package xyz.wbsite.dbtool.web.framework.utils;
|
||||||
|
|
||||||
|
import sun.misc.BASE64Decoder;
|
||||||
|
import sun.misc.BASE64Encoder;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import java.security.*;
|
||||||
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
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-->" + new BASE64Encoder().encode(aPublic.getEncoded()));
|
||||||
|
System.err.println("privateKeyBase64-->" + new BASE64Encoder().encode(aPrivate.getEncoded()));
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*
|
||||||
|
* @param data 待加密明文
|
||||||
|
*/
|
||||||
|
public static String encrypt(String data) {
|
||||||
|
try {
|
||||||
|
//生成公钥对象
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(new BASE64Decoder().decodeBuffer(cryptPublicKeyBase64));
|
||||||
|
PublicKey aPublic = keyFactory.generatePublic(x509EncodedKeySpec);
|
||||||
|
|
||||||
|
StringBuffer miwen = new StringBuffer();
|
||||||
|
//分段加密开始
|
||||||
|
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)));
|
||||||
|
miwen.append(new BASE64Encoder().encode(bytes));
|
||||||
|
offset += 117;
|
||||||
|
}
|
||||||
|
return miwen.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param miwen base64密文
|
||||||
|
*/
|
||||||
|
public static String decrypt(String miwen) {
|
||||||
|
try {
|
||||||
|
//生成私钥对象
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(cryptPrivateKeyBase64));
|
||||||
|
PrivateKey aPrivate = keyFactory.generatePrivate(pkcs8EncodedKeySpec);
|
||||||
|
|
||||||
|
Cipher rsa = Cipher.getInstance("RSA");
|
||||||
|
rsa.init(Cipher.DECRYPT_MODE, aPrivate);
|
||||||
|
//获得密文字节
|
||||||
|
byte[] data = new BASE64Decoder().decodeBuffer(miwen.toString());
|
||||||
|
int offset = 0;
|
||||||
|
StringBuffer getMing = new StringBuffer();
|
||||||
|
while (offset < data.length) {
|
||||||
|
byte[] bytes = rsa.doFinal(Arrays.copyOfRange(data, offset, Math.min(offset + 128, data.length)));
|
||||||
|
getMing.append(new String(bytes));
|
||||||
|
offset += 128;
|
||||||
|
}
|
||||||
|
return getMing.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RSA签名
|
||||||
|
*
|
||||||
|
* @param content 待签名数据
|
||||||
|
* @param privateKey 私钥
|
||||||
|
* @param encode 字符集编码
|
||||||
|
* @return 签名值
|
||||||
|
*/
|
||||||
|
public static String sign(String content, String privateKey, String encode) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(privateKey));
|
||||||
|
PrivateKey aPrivate = keyFactory.generatePrivate(priPKCS8);
|
||||||
|
|
||||||
|
Signature signature = Signature.getInstance("SHA1WithRSA");
|
||||||
|
|
||||||
|
signature.initSign(aPrivate);
|
||||||
|
signature.update(content.getBytes(encode));
|
||||||
|
|
||||||
|
byte[] signed = signature.sign();
|
||||||
|
|
||||||
|
return new BASE64Encoder().encode(signed);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RSA验签名检查
|
||||||
|
*
|
||||||
|
* @param content 待签名数据
|
||||||
|
* @param sign 签名值
|
||||||
|
* @param publicKey 公钥
|
||||||
|
* @param encode 字符集编码
|
||||||
|
* @return 布尔值
|
||||||
|
*/
|
||||||
|
public static boolean doCheck(String content, String sign, String publicKey, String encode) {
|
||||||
|
try {
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
byte[] encodedKey = new BASE64Decoder().decodeBuffer(publicKey);
|
||||||
|
PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
|
||||||
|
|
||||||
|
|
||||||
|
Signature signature = Signature.getInstance("SHA1WithRSA");
|
||||||
|
|
||||||
|
signature.initVerify(pubKey);
|
||||||
|
signature.update(content.getBytes(encode));
|
||||||
|
|
||||||
|
boolean bverify = signature.verify(new BASE64Decoder().decodeBuffer(sign));
|
||||||
|
return bverify;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试实例
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
{//创建秘钥对
|
||||||
|
RSAUtil.createKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
{//加解密
|
||||||
|
|
||||||
|
//加密
|
||||||
|
String encrypt = RSAUtil.encrypt("我有一个苹果");
|
||||||
|
System.out.println(encrypt);
|
||||||
|
|
||||||
|
//解密
|
||||||
|
String decrypt = RSAUtil.decrypt(encrypt);
|
||||||
|
System.out.println(decrypt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String sign = sign("我有一个苹果", signPrivateKeyBase64, "utf-8");
|
||||||
|
System.out.println(sign);
|
||||||
|
|
||||||
|
boolean b = doCheck("我有一个苹果", sign, signPublicKeyBase64, "utf-8");
|
||||||
|
System.out.println(b);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
# 开发环境
|
||||||
|
server.port=80
|
||||||
|
server.servlet.context-path=/
|
||||||
|
spring.mvc.static-path-pattern=/static/**
|
||||||
|
spring.resources.static-locations=classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources
|
||||||
|
spring.application.name=SpringBoot
|
||||||
|
# 根路径、欢迎页
|
||||||
|
web.welcome.page = index
|
||||||
|
# 排除的不需要验证的URL
|
||||||
|
web.url.excluded = /static/**,/open/**,/api,/index,/,/login
|
||||||
|
# 默认的登录URL
|
||||||
|
web.url.login = /login
|
||||||
|
# 日志配置
|
||||||
|
logging.config=classpath:logback-config.xml
|
||||||
|
# 热部署生效
|
||||||
|
spring.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
|
@ -0,0 +1,33 @@
|
|||||||
|
${AnsiColor.BRIGHT_YELLOW}
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// _ooOoo_ // //
|
||||||
|
// o8888888o 佛 代 // ┏┓ ┏┓ 神 代 //
|
||||||
|
// 88" . "88 祖 码 // ┏┛┻━━━┛┻┓ 兽 码 //
|
||||||
|
// (| ^_^ |) 保 无 // ┃ ┃ 保 无 //
|
||||||
|
// O\ = /O 佑 BUG // ┃ ━ ┃ 佑 BUG //
|
||||||
|
// ____/`---'\____ // ┃ ┳┛ ┗┳ ┃ //
|
||||||
|
// .' \\| |// `. // ┃ ┃ //
|
||||||
|
// / \\||| : |||// \ // ┃ ┻ ┃ //
|
||||||
|
// / _||||| -:- |||||- \ // ┃ ┃ //
|
||||||
|
// | | \\\ - /// | | // ┗━┓ ┏━┛ //
|
||||||
|
// | \_| ''\---/'' | | // ┃ ┃ //
|
||||||
|
// \ .-\__ `-` ___/-. / // ┃ ┃ //
|
||||||
|
// ___`. .' /--.--\ `. . ___ // ┃ ┗━━━┓ //
|
||||||
|
// ."" '< `.___\_<|>_/___.' >'"". // ┃ ┣┓ //
|
||||||
|
// | | : `- \`.;`\ _ /`;.`/ - ` : | | // ┃ ┏┛ //
|
||||||
|
// \ \ `-. \_ __\ /__ _/ .-` / / // ┗┓┓┏━┳┓┏┛ //
|
||||||
|
// ========`-.____`-.___\_____/___.-`____.-'======== // ┃┫┫ ┃┫┫ //
|
||||||
|
// `=---=' // //
|
||||||
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
_ _ _
|
||||||
|
| | | | (_)
|
||||||
|
| |__ _ _ __ __ __ _ _ __ __ _ | |__ _ _ __ __ _
|
||||||
|
| '_ \ | | | | \ \ /\ / / / _` || '_ \ / _` | | '_ \ | || '_ \ / _` |
|
||||||
|
| |_) || |_| | \ V V / | (_| || | | || (_| | | |_) || || | | || (_| |
|
||||||
|
|_.__/ \__, | \_/\_/ \__,_||_| |_| \__, | |_.__/ |_||_| |_| \__, |
|
||||||
|
__/ | __/ | __/ |
|
||||||
|
|___/ |___/ |___/
|
||||||
|
|
||||||
|
:: Spring Boot :: ${spring-boot.formatted-version} (${spring.profiles.active})
|
||||||
|
|
@ -0,0 +1,103 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<BorderPane fx:controller="xyz.wbsite.dbtool.javafx.ctrl.SdkInfoController"
|
||||||
|
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
|
||||||
|
minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
|
||||||
|
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<top>
|
||||||
|
<GridPane prefHeight="65.0" prefWidth="601.0" BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="295.0" minWidth="10.0" prefWidth="90.0"/>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="496.0" minWidth="10.0" prefWidth="425.0"/>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="496.0" minWidth="10.0" prefWidth="88.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints maxHeight="38.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints maxHeight="33.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label maxHeight="-Infinity" maxWidth="-Infinity" text="模块路径" GridPane.halignment="CENTER"
|
||||||
|
GridPane.valignment="CENTER"/>
|
||||||
|
<Label text="生成路径" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.columnIndex="1" fx:id="modulePath" promptText="...\**\module\"/>
|
||||||
|
<TextField GridPane.columnIndex="1" fx:id="sdkPath" GridPane.rowIndex="1"/>
|
||||||
|
<Button mnemonicParsing="false" fx:id="selectModulePath" text="选择路径" GridPane.columnIndex="2" GridPane.halignment="CENTER"
|
||||||
|
GridPane.valignment="CENTER"/>
|
||||||
|
<Button mnemonicParsing="false" fx:id="selectSdkPath" text="选择路径" GridPane.columnIndex="2" GridPane.halignment="CENTER"
|
||||||
|
GridPane.rowIndex="1" GridPane.valignment="CENTER"/>
|
||||||
|
</children>
|
||||||
|
<opaqueInsets>
|
||||||
|
<Insets/>
|
||||||
|
</opaqueInsets>
|
||||||
|
</GridPane>
|
||||||
|
</top>
|
||||||
|
<opaqueInsets>
|
||||||
|
<Insets/>
|
||||||
|
</opaqueInsets>
|
||||||
|
<center>
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<center>
|
||||||
|
<TableView fx:id="apis" prefHeight="270.0" prefWidth="700.0" BorderPane.alignment="CENTER">
|
||||||
|
<columns>
|
||||||
|
<TableColumn prefWidth="60.0" text="选择"/>
|
||||||
|
<TableColumn prefWidth="140.0" text="错误"/>
|
||||||
|
<TableColumn prefWidth="150.0" text="request"/>
|
||||||
|
<TableColumn prefWidth="150.0" text="response"/>
|
||||||
|
<TableColumn prefWidth="200.0" text="method"/>
|
||||||
|
</columns>
|
||||||
|
|
||||||
|
</TableView>
|
||||||
|
</center>
|
||||||
|
<top>
|
||||||
|
<ToolBar prefHeight="30.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||||
|
<items>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="All" text="All" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="api" text="api" selected="true">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="create" text="create" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="delete" text="delete" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="update" text="update" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="find" text="find" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="search" text="search" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="get" text="get" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="getAll" text="getAll" selected="false">
|
||||||
|
</CheckBox>
|
||||||
|
</items>
|
||||||
|
</ToolBar>
|
||||||
|
</top>
|
||||||
|
<BorderPane.margin>
|
||||||
|
<Insets top="20.0"/>
|
||||||
|
</BorderPane.margin>
|
||||||
|
</BorderPane>
|
||||||
|
|
||||||
|
</center>
|
||||||
|
<bottom>
|
||||||
|
<GridPane prefHeight="45.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Button fx:id="start" mnemonicParsing="false" text="确认" GridPane.halignment="CENTER"
|
||||||
|
GridPane.valignment="CENTER"/>
|
||||||
|
<Button fx:id="cancel" mnemonicParsing="false" text="取消" GridPane.columnIndex="1"
|
||||||
|
GridPane.halignment="CENTER"
|
||||||
|
GridPane.valignment="CENTER"/>
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
|
</bottom>
|
||||||
|
</BorderPane>
|
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<BorderPane fx:controller="xyz.wbsite.dbtool.javafx.ctrl.ConnectInfoController" maxHeight="-Infinity" maxWidth="-Infinity"
|
||||||
|
minHeight="-Infinity" minWidth="-Infinity" prefHeight="214.0" prefWidth="399.0"
|
||||||
|
xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<center>
|
||||||
|
<GridPane BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="195.0" minWidth="10.0" prefWidth="115.0"/>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="284.0" minWidth="10.0" prefWidth="284.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label text="库类型"/>
|
||||||
|
<Label text="Driver" GridPane.rowIndex="1"/>
|
||||||
|
<Label text="Url" GridPane.rowIndex="2"/>
|
||||||
|
<Label text="UserName" GridPane.rowIndex="3"/>
|
||||||
|
<Label text="Password" GridPane.rowIndex="4"/>
|
||||||
|
<ChoiceBox fx:id="databaseType" GridPane.columnIndex="1"/>
|
||||||
|
<TextField fx:id="driver" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
|
||||||
|
<TextField fx:id="url" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||||
|
<TextField fx:id="userName" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
|
||||||
|
<TextField fx:id="password" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
|
||||||
|
</children>
|
||||||
|
<BorderPane.margin>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="20.0" top="10.0"/>
|
||||||
|
</BorderPane.margin>
|
||||||
|
</GridPane>
|
||||||
|
</center>
|
||||||
|
<bottom>
|
||||||
|
<GridPane BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Button fx:id="test" mnemonicParsing="false" text="测试"/>
|
||||||
|
<Button fx:id="load" mnemonicParsing="false" text="加载" GridPane.columnIndex="1"/>
|
||||||
|
<Button fx:id="cancel" mnemonicParsing="false" text="取消" GridPane.columnIndex="2"/>
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
|
</bottom>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0"/>
|
||||||
|
</padding>
|
||||||
|
</BorderPane>
|
@ -0,0 +1,60 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<BorderPane fx:controller="xyz.wbsite.dbtool.javafx.ctrl.GenerateOptionController" prefHeight="199.0" prefWidth="468.0"
|
||||||
|
xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<center>
|
||||||
|
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="173.0"
|
||||||
|
prefWidth="468.0">
|
||||||
|
<children>
|
||||||
|
<Label text="框架">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="3.0" left="10.0" right="10.0" top="3.0"/>
|
||||||
|
</padding>
|
||||||
|
</Label>
|
||||||
|
<HBox prefHeight="40.0" prefWidth="600.0">
|
||||||
|
<children>
|
||||||
|
|
||||||
|
<RadioButton mnemonicParsing="false" selected="true" text="SpringBoot">
|
||||||
|
<toggleGroup>
|
||||||
|
<ToggleGroup fx:id="type"/>
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioButton>
|
||||||
|
<!--<RadioButton mnemonicParsing="false" text="SpringMVC_Mybatis" toggleGroup="$type" selected="false"/>-->
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="3.0" left="20.0" right="10.0" top="3.0"/>
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
<Label text="数据库">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="3.0" left="10.0" right="10.0" top="3.0"/>
|
||||||
|
</padding>
|
||||||
|
</Label>
|
||||||
|
<HBox prefHeight="40.0" prefWidth="600.0">
|
||||||
|
<RadioButton mnemonicParsing="false" text="Oracle">
|
||||||
|
<toggleGroup>
|
||||||
|
<ToggleGroup fx:id="db"/>
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton mnemonicParsing="false" text="MySql" selected="true" toggleGroup="$db"/>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="3.0" left="20.0" right="10.0" top="3.0"/>
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</center>
|
||||||
|
<bottom>
|
||||||
|
<Pane prefHeight="38.0" prefWidth="468.0" BorderPane.alignment="CENTER">
|
||||||
|
<children>
|
||||||
|
<Button layoutX="136.0" layoutY="9.0" mnemonicParsing="false" text="确认" fx:id="ok"/>
|
||||||
|
<Button layoutX="266.0" layoutY="9.0" mnemonicParsing="false" text="取消" fx:id="cancel"/>
|
||||||
|
</children>
|
||||||
|
</Pane>
|
||||||
|
</bottom>
|
||||||
|
</BorderPane>
|
@ -0,0 +1,75 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
|
||||||
|
prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="xyz.wbsite.dbtool.javafx.ctrl.MainController">
|
||||||
|
<top>
|
||||||
|
<MenuBar BorderPane.alignment="CENTER">
|
||||||
|
<menus>
|
||||||
|
<Menu mnemonicParsing="false" text="File">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#save" text="保存"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#saveAs" text="另存"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#clear" text="清除"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#showFileChooser" text="打开"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#showConnectInfo" text="数据库导入"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#generate" text="生成代码"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#generateApi" text="生成api"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
<Menu mnemonicParsing="false" text="Help">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="About"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
</menus>
|
||||||
|
</MenuBar>
|
||||||
|
</top>
|
||||||
|
<center>
|
||||||
|
<SplitPane dividerPositions="0.25" BorderPane.alignment="CENTER">
|
||||||
|
<items>
|
||||||
|
<TreeView fx:id="dbtree" prefHeight="200.0" prefWidth="200.0"/>
|
||||||
|
<SplitPane dividerPositions="0.35" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0">
|
||||||
|
<items>
|
||||||
|
<Pane fx:id="detail" prefHeight="200.0" prefWidth="200.0"/>
|
||||||
|
<BorderPane>
|
||||||
|
<center>
|
||||||
|
<TableView fx:id="feilds" prefHeight="200.0" prefWidth="200.0">
|
||||||
|
<columns>
|
||||||
|
<TableColumn prefWidth="100" text="字段名"/>
|
||||||
|
<TableColumn prefWidth="80" text="类型"/>
|
||||||
|
<TableColumn prefWidth="50" text="长度"/>
|
||||||
|
<TableColumn prefWidth="50" text="默认值"/>
|
||||||
|
<TableColumn prefWidth="40" text="主键"/>
|
||||||
|
<TableColumn prefWidth="40" text="必填"/>
|
||||||
|
<TableColumn prefWidth="40" text="查询"/>
|
||||||
|
<TableColumn prefWidth="40" text="模糊"/>
|
||||||
|
<TableColumn prefWidth="80" text="注释"/>
|
||||||
|
</columns>
|
||||||
|
</TableView>
|
||||||
|
</center>
|
||||||
|
<top>
|
||||||
|
<ToolBar prefHeight="30.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||||
|
<items>
|
||||||
|
<Button mnemonicParsing="false" text=" + " fx:id="add"/>
|
||||||
|
<Button mnemonicParsing="false" text=" - " fx:id="sub"/>
|
||||||
|
<CheckBox mnemonicParsing="false" fx:id="addSysFields" text="添加系统字段" selected="false">
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets left="30.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
</CheckBox>
|
||||||
|
</items>
|
||||||
|
</ToolBar>
|
||||||
|
</top>
|
||||||
|
</BorderPane>
|
||||||
|
|
||||||
|
|
||||||
|
</items>
|
||||||
|
</SplitPane>
|
||||||
|
</items>
|
||||||
|
</SplitPane>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<GridPane fx:controller="xyz.wbsite.dbtool.javafx.ctrl.DbDetailController" maxHeight="-Infinity" maxWidth="-Infinity"
|
||||||
|
minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.65"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="60.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="160.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="60.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="160.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<!-- ROW -->
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="0" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="1" text="模块名称" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.rowIndex="0" GridPane.columnIndex="2" fx:id="moduleName"/>
|
||||||
|
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="3" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="4" text="模块注释" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.rowIndex="0" GridPane.columnIndex="5" fx:id="moduleComment"/>
|
||||||
|
<!-- ROW -->
|
||||||
|
|
||||||
|
<!-- ROW -->
|
||||||
|
<Label GridPane.rowIndex="1" GridPane.columnIndex="0" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="1" GridPane.columnIndex="1" text="前缀" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.rowIndex="1" GridPane.columnIndex="2" fx:id="modulePrefix"/>
|
||||||
|
<!-- ROW -->
|
||||||
|
|
||||||
|
</children>
|
||||||
|
|
||||||
|
</GridPane>
|
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<GridPane fx:controller="xyz.wbsite.dbtool.javafx.ctrl.ProjectDetailController" maxHeight="-Infinity" maxWidth="-Infinity"
|
||||||
|
minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.65"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="60.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="160.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="60.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="160.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<!-- ROW -->
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="0" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="1" text="项目名称" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.rowIndex="0" GridPane.columnIndex="2" fx:id="projectName"/>
|
||||||
|
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="3" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="4" text="作者" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.rowIndex="0" GridPane.columnIndex="5" fx:id="projectAuthor"/>
|
||||||
|
<!-- ROW -->
|
||||||
|
|
||||||
|
<!-- ROW -->
|
||||||
|
<Label GridPane.rowIndex="1" GridPane.columnIndex="0" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="1" GridPane.columnIndex="1" text="域名" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<TextField GridPane.rowIndex="1" GridPane.columnIndex="2" fx:id="projectBasePackage"/>
|
||||||
|
|
||||||
|
<!-- ROW -->
|
||||||
|
</children>
|
||||||
|
|
||||||
|
</GridPane>
|
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<BorderPane fx:controller="xyz.wbsite.dbtool.javafx.ctrl.SdkInfoController" maxHeight="-Infinity" maxWidth="-Infinity"
|
||||||
|
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400" prefWidth="500"
|
||||||
|
xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<center>
|
||||||
|
<GridPane BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="195.0" minWidth="10.0" prefWidth="115.0"/>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="284.0" minWidth="10.0" prefWidth="284.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label text="项目路径" GridPane.rowIndex="0"/>
|
||||||
|
<Label text="生成路径" GridPane.rowIndex="1"/>
|
||||||
|
<TextField fx:id="modulePath" GridPane.columnIndex="1" GridPane.rowIndex="0"
|
||||||
|
promptText="...\**\module\"/>
|
||||||
|
<TextField fx:id="sdkPath" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
|
||||||
|
</children>
|
||||||
|
<BorderPane.margin>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="20.0" top="10.0"/>
|
||||||
|
</BorderPane.margin>
|
||||||
|
</GridPane>
|
||||||
|
</center>
|
||||||
|
<bottom>
|
||||||
|
<GridPane BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Button fx:id="start" mnemonicParsing="false" text="开始"/>
|
||||||
|
<Button fx:id="cancel" mnemonicParsing="false" text="取消" GridPane.columnIndex="1"/>
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
|
</bottom>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0"/>
|
||||||
|
</padding>
|
||||||
|
</BorderPane>
|
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="xyz.wbsite.dbtool.javafx.ctrl.TableDetailController">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="60.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" prefWidth="400.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="0" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="0" GridPane.columnIndex="1" text="对象名称" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
|
<TextField GridPane.rowIndex="0" GridPane.columnIndex="2" fx:id="tablename" />
|
||||||
|
|
||||||
|
<Label GridPane.rowIndex="1" GridPane.columnIndex="0" text="*" alignment="CENTER" textAlignment="CENTER" textFill="RED" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
||||||
|
<Label GridPane.rowIndex="1" GridPane.columnIndex="1" text="对象注释" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
|
<TextField GridPane.rowIndex="1" GridPane.columnIndex="2" fx:id="tablecomment"/>
|
||||||
|
<Label GridPane.rowIndex="2" GridPane.columnIndex="1" text="基本方法" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
|
<HBox GridPane.rowIndex="2" GridPane.columnIndex="2" alignment="CENTER_LEFT" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
|
||||||
|
<children>
|
||||||
|
<CheckBox fx:id="create" mnemonicParsing="false" text="create" />
|
||||||
|
<CheckBox fx:id="delete" mnemonicParsing="false" text="delete" />
|
||||||
|
<CheckBox fx:id="update" mnemonicParsing="false" text="update" />
|
||||||
|
<CheckBox fx:id="find" mnemonicParsing="false" text="find" />
|
||||||
|
<CheckBox fx:id="get" mnemonicParsing="false" text="get" />
|
||||||
|
<CheckBox fx:id="search" mnemonicParsing="false" text="search" />
|
||||||
|
<CheckBox fx:id="getAll" mnemonicParsing="false" text="getAll" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
</children>
|
||||||
|
|
||||||
|
</GridPane>
|
@ -0,0 +1,110 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
|
||||||
|
<!-- 日志根目录(可以随平台修改)-->
|
||||||
|
<property name="root" value="D:/"></property>
|
||||||
|
|
||||||
|
<!-- 迭代日志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>
|
||||||
|
<logger name="org.apache.velocity" level="OFF"></logger>
|
||||||
|
<logger name="org.springframework.ui.freemarker" level="OFF"></logger>
|
||||||
|
|
||||||
|
<!-- 日志总入口 -->
|
||||||
|
<root level="INFO">
|
||||||
|
<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,122 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
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,508 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import ${domain}.${module}.request.ApiExampleRequest;
|
||||||
|
import ${domain}.${module}.response.ApiExampleResponse;
|
||||||
|
import okhttp3.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
|
||||||
|
public class ApiClient {
|
||||||
|
private static ApiClient ourInstance = null;
|
||||||
|
|
||||||
|
public static void init(String serverUrl, String appKey, String appSecret) {
|
||||||
|
init(serverUrl, appKey, appSecret, DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(String serverUrl, String appKey, String appSecret, int connectTimeout, int readTimeout) {
|
||||||
|
ourInstance = new ApiClient(serverUrl, appKey, appSecret, connectTimeout, readTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiClient getInstance() {
|
||||||
|
if (ourInstance == null) {
|
||||||
|
System.err.print("ApiClient need init");
|
||||||
|
}
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
//基本请求参数KEY
|
||||||
|
private static final String P_APP_KEY = "app_key";
|
||||||
|
private static final String P_TYPE = "type";
|
||||||
|
private static final String P_TARGET = "target";
|
||||||
|
private static final String P_FILE_NAME = "file_name";
|
||||||
|
private static final String P_TIMESTAMP = "timestamp";
|
||||||
|
private static final String P_METHOD = "method";
|
||||||
|
private static final String P_SIGN = "sign";
|
||||||
|
private static final String P_TOKEN = "token_id";
|
||||||
|
private static final String P_ENHANCED = "enhanced";
|
||||||
|
//参数类型
|
||||||
|
private static final String TYPE_JSON = "json";
|
||||||
|
private static final String TYPE_FILE = "file";
|
||||||
|
//应用码
|
||||||
|
private String appKey;
|
||||||
|
//应用安全码
|
||||||
|
private String appSecret;
|
||||||
|
//服务器地址
|
||||||
|
private String serverUrl;
|
||||||
|
//公钥
|
||||||
|
private PublicKey publicKey = null;
|
||||||
|
private OkHttpClient httpClient = null;
|
||||||
|
//默认参数
|
||||||
|
private static final int DEFAULT_CONNECT_TIMEOUT = 3;//秒
|
||||||
|
private static final int DEFAULT_READ_TIMEOUT = 30;//秒
|
||||||
|
//请求配置
|
||||||
|
private int connectTimeout;//3秒
|
||||||
|
private int readTimeout;//30秒
|
||||||
|
private boolean needCheckRequest = true; // 是否在客户端校验请求
|
||||||
|
private boolean needEnableParser = true; // 是否对响应结果进行解释
|
||||||
|
|
||||||
|
private Before before = null;
|
||||||
|
private After after = null;
|
||||||
|
private String token = "";
|
||||||
|
private boolean debug = false;
|
||||||
|
|
||||||
|
private ApiClient(String serverUrl, String appKey, String appSecret, int connectTimeout, int readTimeout) {
|
||||||
|
this.connectTimeout = connectTimeout;
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
this.appKey = appKey;
|
||||||
|
this.appSecret = appSecret;
|
||||||
|
this.serverUrl = serverUrl;
|
||||||
|
this.httpClient = new OkHttpClient.Builder()
|
||||||
|
.readTimeout(readTimeout, TimeUnit.SECONDS)
|
||||||
|
.connectTimeout(connectTimeout, TimeUnit.SECONDS)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicKey(PublicKey publicKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Callback<T extends ApiResponse> {
|
||||||
|
void call(T response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Before {
|
||||||
|
void call(ApiRequest request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface After {
|
||||||
|
void call(ApiRequest request, ApiResponse response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAfter(After after) {
|
||||||
|
this.after = after;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBefore(Before before) {
|
||||||
|
this.before = before;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends ApiResponse> T execute(ApiRequest<T> request) {
|
||||||
|
return execute(request, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends ApiResponse> T execute(ApiRequest<T> request, boolean isEnhanced) {
|
||||||
|
if (before != null) {
|
||||||
|
before.call(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查请求参数
|
||||||
|
T t = MapperUtil.toJava("{}", request.responseClass());
|
||||||
|
if (isEnhanced && publicKey == null) {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "publicKey can not be null.");
|
||||||
|
}
|
||||||
|
if (t.hasError()) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//装载请求参数
|
||||||
|
String currentTime = String.valueOf(System.currentTimeMillis());
|
||||||
|
RequestBody requestBody = new FormBody.Builder()
|
||||||
|
.add(P_APP_KEY, appKey)
|
||||||
|
.add(P_METHOD, request.apiMethod())
|
||||||
|
.add(P_TYPE, TYPE_JSON)
|
||||||
|
.add(P_TARGET, MapperUtil.toJson(request))
|
||||||
|
.add(P_TIMESTAMP, currentTime)
|
||||||
|
.add(P_SIGN, sign(request, currentTime))
|
||||||
|
.add(P_ENHANCED, String.valueOf(isEnhanced))
|
||||||
|
.add(P_TOKEN, token)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request build = new Request.Builder()
|
||||||
|
.url(serverUrl)
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = httpClient.newCall(build).execute();
|
||||||
|
String responseJson = decryptResponse(response, isEnhanced);
|
||||||
|
t = MapperUtil.toJava(responseJson, request.responseClass());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
t = MapperUtil.toJava("{}", request.responseClass());
|
||||||
|
t.addError(ErrorType.SYSTEM_ERROR, "请求异常!");
|
||||||
|
} finally {
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends ApiResponse> void execute(ApiRequest<T> request, Callback callback) {
|
||||||
|
execute(request, false, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends ApiResponse> void execute(final ApiRequest<T> request, final boolean isEnhanced, final Callback callback) {
|
||||||
|
if (before != null) {
|
||||||
|
before.call(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查请求参数
|
||||||
|
T t = MapperUtil.toJava("{}", request.responseClass());
|
||||||
|
if (isEnhanced && publicKey == null) {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "publicKey can not be null.");
|
||||||
|
}
|
||||||
|
if (t.hasError()) {
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, t);
|
||||||
|
}
|
||||||
|
if (callback != null) {
|
||||||
|
callback.call(t);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//装载请求参数
|
||||||
|
String currentTime = String.valueOf(System.currentTimeMillis());
|
||||||
|
RequestBody requestBody = new FormBody.Builder()
|
||||||
|
.add(P_APP_KEY, appKey)
|
||||||
|
.add(P_METHOD, request.apiMethod())
|
||||||
|
.add(P_TYPE, TYPE_JSON)
|
||||||
|
.add(P_TARGET, encode(request, isEnhanced))
|
||||||
|
.add(P_TIMESTAMP, currentTime)
|
||||||
|
.add(P_SIGN, sign(request, currentTime))
|
||||||
|
.add(P_ENHANCED, String.valueOf(isEnhanced))
|
||||||
|
.add(P_TOKEN, token)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request build = new Request.Builder()
|
||||||
|
.url(serverUrl)
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
httpClient.newCall(build).enqueue(new okhttp3.Callback() {
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
T t = MapperUtil.toJava("{}", request.responseClass());
|
||||||
|
if (e instanceof ConnectException) {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "网络连接错误!");
|
||||||
|
} else if (e instanceof SocketTimeoutException) {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "连接超时!");
|
||||||
|
} else {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "请求错误!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, t);
|
||||||
|
}
|
||||||
|
if (callback != null) {
|
||||||
|
callback.call(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
T t = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
String responseJson = decryptResponse(response, isEnhanced);
|
||||||
|
t = MapperUtil.toJava(responseJson, request.responseClass());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
t = MapperUtil.toJava("{}", request.responseClass());
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "服务器异常!");
|
||||||
|
}
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, t);
|
||||||
|
}
|
||||||
|
if (callback != null) {
|
||||||
|
callback.call(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
T baseResponse = MapperUtil.toJava("{}", request.responseClass());
|
||||||
|
baseResponse.addError(ErrorType.SYSTEM_ERROR, "请求异常!");
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, baseResponse);
|
||||||
|
}
|
||||||
|
if (callback != null) {
|
||||||
|
callback.call(baseResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fileUpload(FileUploadRequest request, Callback<FileUploadResponse> callback) {
|
||||||
|
fileUpload(request, callback, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fileUpload(final FileUploadRequest request, final Callback<FileUploadResponse> callback, ProgressRequestBody.ProgressListener listener) {
|
||||||
|
if (before != null) {
|
||||||
|
before.call(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//检查文件是否存在
|
||||||
|
if (!request.isExist()) {
|
||||||
|
FileUploadResponse fileUploadResponse = new FileUploadResponse();
|
||||||
|
fileUploadResponse.addError(ErrorType.BUSINESS_ERROR, "文件不存在!");
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, fileUploadResponse);
|
||||||
|
}
|
||||||
|
callback.call(fileUploadResponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//装载请求参数
|
||||||
|
String currentTime = String.valueOf(System.currentTimeMillis());
|
||||||
|
MultipartBody.Builder builder = new MultipartBody.Builder()
|
||||||
|
.addFormDataPart(P_APP_KEY, appKey)
|
||||||
|
.addFormDataPart(P_METHOD, request.apiMethod())
|
||||||
|
.addFormDataPart(P_TYPE, TYPE_FILE)
|
||||||
|
.addFormDataPart(P_TIMESTAMP, currentTime)
|
||||||
|
.addFormDataPart(P_SIGN, sign(request, currentTime))
|
||||||
|
.addFormDataPart(P_TOKEN, token);
|
||||||
|
|
||||||
|
if (request.getFile() != null) {
|
||||||
|
builder.addFormDataPart(P_TARGET, request.getFile().getName(), ProgressRequestBody.createProgressRequestBody(MediaType.parse("image/*"), request.getFile(), listener));
|
||||||
|
builder.addFormDataPart(P_FILE_NAME, request.getFileName());
|
||||||
|
} else {
|
||||||
|
builder.addFormDataPart(P_TARGET, null, ProgressRequestBody.createProgressRequestBody(Base64Util.encodeToString(request.getBytes()), listener));
|
||||||
|
builder.addFormDataPart(P_FILE_NAME, request.getFileName());
|
||||||
|
}
|
||||||
|
MultipartBody multipartBody = builder.build();
|
||||||
|
|
||||||
|
Request build = new Request.Builder()
|
||||||
|
.url(serverUrl)
|
||||||
|
.post(multipartBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
httpClient.newCall(build).enqueue(new okhttp3.Callback() {
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
FileUploadResponse t = MapperUtil.toJava("{}", FileUploadResponse.class);
|
||||||
|
if (e instanceof ConnectException) {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "网络连接错误!");
|
||||||
|
} else if (e instanceof SocketTimeoutException) {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "连接超时!");
|
||||||
|
} else {
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "请求错误!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, t);
|
||||||
|
}
|
||||||
|
if (callback != null) {
|
||||||
|
callback.call(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
|
||||||
|
FileUploadResponse t = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
String responseJson = decryptResponse(response, false);
|
||||||
|
t = MapperUtil.toJava(responseJson, FileUploadResponse.class);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
t = new FileUploadResponse();
|
||||||
|
t.addError(ErrorType.BUSINESS_ERROR, "服务器异常!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (after != null) {
|
||||||
|
after.call(request, t);
|
||||||
|
}
|
||||||
|
if (callback != null) {
|
||||||
|
callback.call(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对请求进行加密编码
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String encode(ApiRequest request, boolean isEnhanced) {
|
||||||
|
String json = MapperUtil.toJson(request);
|
||||||
|
if (isEnhanced) {
|
||||||
|
return RSAUtil.encrypt2Base64(json.getBytes());
|
||||||
|
} else {
|
||||||
|
return AESUtil.encrypt2Base64(json.getBytes(), appSecret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对响应进行解密
|
||||||
|
*
|
||||||
|
* @param response
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String decryptResponse(Response response, boolean isEnhanced) throws IOException {
|
||||||
|
String responseString = response.body().string();
|
||||||
|
String responseJson;
|
||||||
|
if (isEnhanced) {
|
||||||
|
responseJson = RSAUtil.decrypt2String(responseString);
|
||||||
|
} else {
|
||||||
|
responseJson = AESUtil.decrypt2String(responseString, appSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
System.out.println("加密响应结果:" + responseString);
|
||||||
|
System.out.println("响应结果:" + responseJson);
|
||||||
|
}
|
||||||
|
return responseJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对请求进行签名
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String sign(ApiRequest request, String currentTime) {
|
||||||
|
if (request instanceof FileUploadRequest) {//文件签名、对文件字节生成的信息摘要签名
|
||||||
|
FileUploadRequest fileUploadRequest = (FileUploadRequest) request;
|
||||||
|
String encode = MD5Util.encode(fileUploadRequest.getFile() != null ? toByteArray(fileUploadRequest.getFile()) : fileUploadRequest.getBytes());
|
||||||
|
return MD5Util.encode(appSecret + encode + currentTime);
|
||||||
|
} else {//普通参数签名、此处JSON是经过排序生成的JSON字符串,因此验签时也需要排序
|
||||||
|
String json = MapperUtil.toJson(request);
|
||||||
|
return MD5Util.encode(appSecret + json + currentTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] toByteArray(File file) {
|
||||||
|
File f = file;
|
||||||
|
if (!f.exists()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length());
|
||||||
|
BufferedInputStream in = null;
|
||||||
|
try {
|
||||||
|
in = new BufferedInputStream(new FileInputStream(f));
|
||||||
|
int buf_size = 1024;
|
||||||
|
byte[] buffer = new byte[buf_size];
|
||||||
|
int len = 0;
|
||||||
|
while (-1 != (len = in.read(buffer, 0, buf_size))) {
|
||||||
|
bos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
return bos.toByteArray();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenId(String token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDebug() {
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDebug(boolean debug) {
|
||||||
|
this.debug = debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
//实例化API请求客户端
|
||||||
|
ApiClient.init("http://localhost:8080/api", "app_key", "1234567890123456");
|
||||||
|
ApiClient client = ApiClient.getInstance();
|
||||||
|
|
||||||
|
// 以下为对称加密公钥,对重要关键请求加密,可不设
|
||||||
|
String cryptPublicKeyBase64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTrwfsrJjCF+pP4S3A/wrD4U1txg53EuBC1mPt" +
|
||||||
|
"3vGXvSK2U0YNRVR3Q65ooHnPKmk4LwI8v+7+ATTxUg3qkuRiDuzBa5zLkYKM50LOgEWSdOKzbnbx" +
|
||||||
|
"a5FnE7IXawNt1p8+MVN1TTI7J/fZy6g1x0WBy1odE5Osru4WfZNOqQtjHwIDAQAB";
|
||||||
|
client.setPublicKey(RSAUtil.parsePublicKey(cryptPublicKeyBase64));
|
||||||
|
|
||||||
|
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
|
||||||
|
//设置发送网络请求前的统一操作
|
||||||
|
client.setBefore(new Before() {
|
||||||
|
public void call(ApiRequest request) {
|
||||||
|
System.out.println("请求参数" + MapperUtil.toJson(request));
|
||||||
|
System.out.println("请求方法" + request.apiMethod());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//设置网络请求完成后的统一操作
|
||||||
|
client.setAfter(new After() {
|
||||||
|
public void call(ApiRequest request, ApiResponse response) {
|
||||||
|
System.out.println("响应参数" + MapperUtil.toJson(response));
|
||||||
|
Date end = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(end));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//json请求
|
||||||
|
ApiExampleRequest request = new ApiExampleRequest();
|
||||||
|
client.execute(request, true, new ApiClient.Callback<ApiExampleResponse>() {
|
||||||
|
public void call(ApiExampleResponse response) {
|
||||||
|
System.out.println(MapperUtil.toJson(response));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// {//无进度显示
|
||||||
|
// final Date start = new Date();
|
||||||
|
//
|
||||||
|
// //文件上传请求
|
||||||
|
// FileUploadRequest fileUploadRequest = new FileUploadRequest();
|
||||||
|
// fileUploadRequest.setFile(new File("D:\\1.PNG"));
|
||||||
|
// client.fileUpload(fileUploadRequest, new Callback<FileUploadResponse>() {
|
||||||
|
// public void call(FileUploadResponse response) {
|
||||||
|
// Date end = new Date();
|
||||||
|
// System.out.println("无进度显示" + (end.getTime() - start.getTime()));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// {//有进度显示
|
||||||
|
// final Date start = new Date();
|
||||||
|
//
|
||||||
|
// //文件上传请求
|
||||||
|
// FileUploadRequest fileUploadRequest = new FileUploadRequest();
|
||||||
|
// fileUploadRequest.setFile(new File("D:\\1.PNG"));
|
||||||
|
// client.fileUpload(fileUploadRequest, new Callback<FileUploadResponse>() {
|
||||||
|
// public void call(FileUploadResponse response) {
|
||||||
|
// Date end = new Date();
|
||||||
|
// System.out.println("有进度显示" + (end.getTime() - start.getTime()));
|
||||||
|
// }
|
||||||
|
// }, new ProgressRequestBody.ProgressListener() {
|
||||||
|
// public void onProgress(long totalBytes, long remainingBytes, boolean done) {
|
||||||
|
// System.out.println((totalBytes - remainingBytes) * 100 / totalBytes + "%");
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class ApiEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行版号
|
||||||
|
*/
|
||||||
|
private long rowVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用户
|
||||||
|
*/
|
||||||
|
private long createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后更新用户
|
||||||
|
*/
|
||||||
|
private long lastUpdateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后更新时间
|
||||||
|
*/
|
||||||
|
private Date lastUpdateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否删除
|
||||||
|
*/
|
||||||
|
private boolean isDeleted;
|
||||||
|
|
||||||
|
public boolean isDeleted() {
|
||||||
|
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,47 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiFindRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public abstract class ApiFindRequest<T> implements ApiRequest {
|
||||||
|
|
||||||
|
private long pageNumber = 1L;
|
||||||
|
private long pageSize = 10L;
|
||||||
|
private String sortKey;
|
||||||
|
private SortType sortType;
|
||||||
|
|
||||||
|
public String getSortKey() {
|
||||||
|
return sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortKey(String sortKey) {
|
||||||
|
this.sortKey = sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortType getSortType() {
|
||||||
|
return sortType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortType(SortType sortType) {
|
||||||
|
this.sortType = sortType;
|
||||||
|
}
|
||||||
|
public long getPageNumber() {
|
||||||
|
return pageNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNumber(long pageNumber) {
|
||||||
|
this.pageNumber = pageNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize(long pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FindResponse - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class ApiFindResponse<T> extends ApiResponse<T>{
|
||||||
|
|
||||||
|
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,17 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public interface ApiRequest<T extends ApiResponse> {
|
||||||
|
|
||||||
|
void check();
|
||||||
|
|
||||||
|
String apiMethod();
|
||||||
|
|
||||||
|
Class<T> responseClass();
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiResponse - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class ApiResponse<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private List<Error> errors = new ArrayList();
|
||||||
|
|
||||||
|
public void setErrors(List<Error> errors) {
|
||||||
|
this.errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Error> getErrors() {
|
||||||
|
return new ArrayList<Error>(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Error peepError() {
|
||||||
|
if (errors.size() > 0) {
|
||||||
|
return new Error(errors.get(0));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addErrors(List<Error> errors) {
|
||||||
|
this.errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addError(ErrorType type, String message) {
|
||||||
|
Error error = new Error();
|
||||||
|
error.setType(type);
|
||||||
|
error.setMessage(message);
|
||||||
|
this.addError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addError(Error error) {
|
||||||
|
this.errors.add(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasError() {
|
||||||
|
return this.errors != null && this.errors.size() > 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiSearchRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public abstract class ApiSearchRequest<T> extends ApiFindRequest<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键字
|
||||||
|
*/
|
||||||
|
private String keyword;
|
||||||
|
|
||||||
|
public String getKeyword() {
|
||||||
|
return keyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyword(String keyword) {
|
||||||
|
this.keyword = keyword;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,506 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
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,154 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import okhttp3.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class DownloadUtil {
|
||||||
|
public static class Builder {
|
||||||
|
private String savePath;
|
||||||
|
private String saveName;
|
||||||
|
private String fileUrl;
|
||||||
|
private OnDownloadListener onDownloadListener;
|
||||||
|
|
||||||
|
public Builder setFileUrl(String fileUrl) {
|
||||||
|
this.fileUrl = fileUrl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setSavePath(String savePath) {
|
||||||
|
this.savePath = savePath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setSaveName(String saveName) {
|
||||||
|
this.saveName = saveName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setFileName(OnDownloadListener onDownloadListener) {
|
||||||
|
this.onDownloadListener = onDownloadListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
if (savePath == null){
|
||||||
|
System.err.println("savePath can not be null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (saveName == null){
|
||||||
|
saveName = getNameFromUrl(fileUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onDownloadListener == null){
|
||||||
|
onDownloadListener = new OnDownloadListener() {
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate(int progress) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadUtil.download(fileUrl, savePath, saveName, onDownloadListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url 下载连接
|
||||||
|
* @param savePath 储存目录
|
||||||
|
* @param saveName 储存文件名
|
||||||
|
* @param listener 下载监听
|
||||||
|
*/
|
||||||
|
public static void download(final String url, final String savePath, final String saveName, final OnDownloadListener listener) {
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
Request request = new Request.Builder().url(url).build();
|
||||||
|
okHttpClient.newCall(request).enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
// 下载失败
|
||||||
|
listener.onFailed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
InputStream is = null;
|
||||||
|
byte[] buf = new byte[2048];
|
||||||
|
int len = 0;
|
||||||
|
FileOutputStream fos = null;
|
||||||
|
// 储存下载文件的目录
|
||||||
|
File saveP = new File(savePath);
|
||||||
|
if (!saveP.exists()) {
|
||||||
|
saveP.mkdirs();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
is = response.body().byteStream();
|
||||||
|
long total = response.body().contentLength();
|
||||||
|
File saveF = new File(savePath, saveName);
|
||||||
|
fos = new FileOutputStream(saveF);
|
||||||
|
long sum = 0;
|
||||||
|
while ((len = is.read(buf)) != -1) {
|
||||||
|
fos.write(buf, 0, len);
|
||||||
|
sum += len;
|
||||||
|
int progress = (int) (sum * 1.0f / total * 100);
|
||||||
|
// 下载中
|
||||||
|
listener.onUpdate(progress);
|
||||||
|
}
|
||||||
|
fos.flush();
|
||||||
|
// 下载完成
|
||||||
|
listener.onFinish();
|
||||||
|
} catch (Exception e) {
|
||||||
|
listener.onFailed();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (is != null)
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (fos != null)
|
||||||
|
fos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url
|
||||||
|
* @return 从下载连接中解析出文件名
|
||||||
|
*/
|
||||||
|
private static String getNameFromUrl(String url) {
|
||||||
|
return url.substring(url.lastIndexOf("/") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnDownloadListener {
|
||||||
|
/**
|
||||||
|
* 下载成功
|
||||||
|
*/
|
||||||
|
void onFinish();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param progress 下载进度
|
||||||
|
*/
|
||||||
|
void onUpdate(int progress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载失败
|
||||||
|
*/
|
||||||
|
void onFailed();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
public class Error {
|
||||||
|
private ErrorType type;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public Error() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Error(Error error) {
|
||||||
|
this.type = error.getType();
|
||||||
|
this.message = error.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
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,10 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
public enum ErrorType {
|
||||||
|
BUSINESS_ERROR,
|
||||||
|
SYSTEM_ERROR,
|
||||||
|
UNKNOWN_ERROR,
|
||||||
|
UNIQUENESS_ERROR,
|
||||||
|
EXPECTATION_NULL,
|
||||||
|
INVALID_PARAMETER
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileUploadRequest - 文件上传请求
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class FileUploadRequest implements ApiRequest<FileUploadResponse> {
|
||||||
|
private String fileName;
|
||||||
|
private File file;
|
||||||
|
private byte[] bytes;
|
||||||
|
|
||||||
|
public void setFile(File file) {
|
||||||
|
this.file = file;
|
||||||
|
this.fileName = file.getName();
|
||||||
|
this.bytes = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFile(byte[] bytes, String fileName) {
|
||||||
|
this.bytes = bytes;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.file = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExist() {
|
||||||
|
if ((file != null && file.exists()) || bytes != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBytes() {
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void check() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apiMethod() {
|
||||||
|
return "api.file.upload";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<FileUploadResponse> responseClass() {
|
||||||
|
return FileUploadResponse.class;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileUploadResponse - 文件上传响应
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class FileUploadResponse extends ApiResponse {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
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,87 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.wb.sdk.auth.request.LoginRequest;
|
||||||
|
import com.wb.sdk.auth.response.LoginResponse;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws ClassNotFoundException {
|
||||||
|
|
||||||
|
//实例化API请求客户端
|
||||||
|
DefaultApiClient defaultApiClient = new DefaultApiClient("http://localhost:8080/api", "qwe", "asd");
|
||||||
|
//设置发送网络请求前的统一操作
|
||||||
|
defaultApiClient.setBefore(new DefaultApiClient.Before() {
|
||||||
|
public void call(ApiRequest request) {
|
||||||
|
System.out.println("请求参数" + JSON.toJSONString(request));
|
||||||
|
System.out.println("请求方法" + request.apiMethod());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//设置网络请求完成后的统一操作
|
||||||
|
defaultApiClient.setAfter(new DefaultApiClient.After() {
|
||||||
|
public void call(ApiRequest request, ApiResponse response) {
|
||||||
|
System.out.println("响应参数" + JSON.toJSONString(response));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
|
||||||
|
|
||||||
|
{
|
||||||
|
//同步接口请求实例
|
||||||
|
System.out.println("--------------------同步接口请求实例-------------------");
|
||||||
|
Date start = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(start));
|
||||||
|
LoginRequest loginRequest = new LoginRequest();
|
||||||
|
loginRequest.setUserName("admin");
|
||||||
|
loginRequest.setPassword("123456");
|
||||||
|
LoginResponse execute = defaultApiClient.execute(loginRequest);
|
||||||
|
Date end = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(end));
|
||||||
|
System.out.println("共用" + (end.getTime() - start.getTime()) + "毫秒");
|
||||||
|
System.out.println("--------------------同步接口请求实例-------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
//文件上传接口请求实例
|
||||||
|
System.out.println("--------------------文件上传接口请求实例-------------------");
|
||||||
|
Date start = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(start));
|
||||||
|
FileUploadRequest fileUploadRequest = new FileUploadRequest();
|
||||||
|
fileUploadRequest.setFile(new File("E:\\doc\\pic\\QQ截图20160918164514.jpg"));
|
||||||
|
defaultApiClient.fileUpload(fileUploadRequest, new ApiClient.Callback<FileUploadResponse>() {
|
||||||
|
public void call(FileUploadResponse response) {
|
||||||
|
System.out.println("文件上传接口请求实例" + JSON.toJSONString(response));
|
||||||
|
Date end = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(end));
|
||||||
|
System.out.println("共用" + (end.getTime() - start.getTime()) + "毫秒");
|
||||||
|
System.out.println("--------------------文件上传接口请求实例-------------------");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//异步接口请求实例
|
||||||
|
System.out.println("--------------------异步接口请求实例-------------------");
|
||||||
|
final Date start = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(start));
|
||||||
|
LoginRequest loginRequest = new LoginRequest();
|
||||||
|
loginRequest.setUserName("admin");
|
||||||
|
loginRequest.setPassword("123456");
|
||||||
|
defaultApiClient.asyncExecute(loginRequest, 1L, new ApiClient.Callback<LoginResponse>() {
|
||||||
|
public void call(LoginResponse response) {
|
||||||
|
System.out.println("异步接口请求响应" + JSON.toJSONString(response));
|
||||||
|
|
||||||
|
Date end = new Date();
|
||||||
|
System.out.println(simpleDateFormat.format(end));
|
||||||
|
System.out.println("共用" + (end.getTime() - start.getTime()) + "毫秒");
|
||||||
|
System.out.println("--------------------异步接口请求实例-------------------");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
package ${domain};
|
||||||
|
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.MultipartBody;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
import okio.Buffer;
|
||||||
|
import okio.BufferedSink;
|
||||||
|
import okio.Okio;
|
||||||
|
import okio.Source;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public abstract class ProgressRequestBody extends RequestBody {
|
||||||
|
|
||||||
|
public static RequestBody createProgressRequestBody(final MediaType contentType, final File file, final ProgressListener listener) {
|
||||||
|
|
||||||
|
return new RequestBody() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaType contentType() {
|
||||||
|
return contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long contentLength() {
|
||||||
|
return file.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(BufferedSink sink) throws IOException {
|
||||||
|
Source source;
|
||||||
|
source = Okio.source(file);
|
||||||
|
if (listener != null) {
|
||||||
|
try {
|
||||||
|
Buffer buf = new Buffer();
|
||||||
|
Long remaining = contentLength();
|
||||||
|
for (long readCount; (readCount = source.read(buf, 102400)) != -1; ) {
|
||||||
|
sink.write(buf, readCount);
|
||||||
|
listener.onProgress(contentLength(), remaining -= readCount, remaining == 0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sink.writeAll(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RequestBody createProgressRequestBody(final String data, final ProgressListener listener) {
|
||||||
|
|
||||||
|
return new RequestBody() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaType contentType() {
|
||||||
|
return MultipartBody.FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long contentLength() {
|
||||||
|
return data.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(BufferedSink sink) throws IOException {
|
||||||
|
Source source;
|
||||||
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data.getBytes());
|
||||||
|
source = Okio.source(byteArrayInputStream);
|
||||||
|
if (listener != null) {
|
||||||
|
try {
|
||||||
|
Buffer buf = new Buffer();
|
||||||
|
Long remaining = contentLength();
|
||||||
|
for (long readCount; (readCount = source.read(buf, 102400)) != -1; ) {
|
||||||
|
sink.write(buf, readCount);
|
||||||
|
listener.onProgress(contentLength(), remaining -= readCount, remaining == 0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sink.writeAll(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ProgressListener {
|
||||||
|
void onProgress(long totalBytes, long remainingBytes, boolean done);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue