├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .travis.yml
├── mvnw
├── mvnw.cmd
├── pom.xml
├── readme.md
├── res
├── generate.db
├── readme.md
├── screenshot
│ ├── 1.jpg
│ ├── 2.jpg
│ └── 3.jpg
└── templates
│ ├── demo2
│ ├── config.json
│ ├── dao.ftl
│ ├── domain.ftl
│ ├── iservice.ftl
│ ├── mapper.ftl
│ └── service.ftl
│ ├── don
│ ├── config.json
│ ├── dao.ftl
│ ├── domain.ftl
│ ├── iservice.ftl
│ ├── mapper.ftl
│ └── service.ftl
│ └── donJava
│ ├── config.json
│ ├── dao.ftl
│ ├── domain.ftl
│ ├── iservice.ftl
│ ├── mapper.ftl
│ └── service.ftl
└── src
├── main
├── java
│ └── me
│ │ └── beldon
│ │ ├── GenerateApplication.java
│ │ ├── config
│ │ └── CoreConfig.java
│ │ ├── core
│ │ ├── SQLiteDialect.java
│ │ └── util
│ │ │ └── SpringContextUtils.java
│ │ ├── module
│ │ ├── database
│ │ │ ├── bean
│ │ │ │ ├── ColumnData.java
│ │ │ │ ├── GenerateData.java
│ │ │ │ └── Type.java
│ │ │ ├── entity
│ │ │ │ ├── mysql
│ │ │ │ │ ├── Columns.java
│ │ │ │ │ ├── Schemata.java
│ │ │ │ │ └── Tables.java
│ │ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ └── service
│ │ │ │ ├── IDatabaseService.java
│ │ │ │ ├── IMySqlService.java
│ │ │ │ ├── IMySqlTypeService.java
│ │ │ │ └── impl
│ │ │ │ ├── DatabaseService.java
│ │ │ │ ├── MySqlService.java
│ │ │ │ └── MySqlTypeService.java
│ │ ├── demo
│ │ │ └── User.java
│ │ ├── generate
│ │ │ ├── dao
│ │ │ │ └── ConnectDbRepository.java
│ │ │ ├── domain
│ │ │ │ └── ConnectDb.java
│ │ │ ├── package-info.java
│ │ │ ├── service
│ │ │ │ ├── IConnectDbService.java
│ │ │ │ ├── IMySqlGenerateService.java
│ │ │ │ └── impl
│ │ │ │ │ ├── ConnectDbService.java
│ │ │ │ │ └── MySqlGenerateService.java
│ │ │ └── ui
│ │ │ │ ├── GenerateController.java
│ │ │ │ ├── GenerateView.java
│ │ │ │ ├── NewConnectionController.java
│ │ │ │ ├── NewConnectionView.java
│ │ │ │ ├── generate.fxml
│ │ │ │ └── newConnection.fxml
│ │ ├── package-info.java
│ │ ├── template
│ │ │ ├── bean
│ │ │ │ ├── TemplateDetails.java
│ │ │ │ └── TemplateFtl.java
│ │ │ ├── package-info.java
│ │ │ └── service
│ │ │ │ ├── ITemplateService.java
│ │ │ │ ├── impl
│ │ │ │ └── TemplateService.java
│ │ │ │ └── package-info.java
│ │ └── window
│ │ │ ├── service
│ │ │ ├── IWindowService.java
│ │ │ └── impl
│ │ │ │ └── WindowService.java
│ │ │ └── ui
│ │ │ ├── MainController.java
│ │ │ ├── MainView.java
│ │ │ └── main.fxml
│ │ └── util
│ │ ├── SSUtils.java
│ │ └── SpringContextUtil.java
└── resources
│ ├── application.yml
│ ├── icons
│ ├── computer.png
│ ├── config-list.png
│ ├── database.png
│ └── table.png
│ ├── image
│ ├── logo.png
│ └── sysTray.png
│ ├── splash
│ └── javafx.png
│ └── style.css
└── test
└── java
└── me
└── beldon
└── GenerateApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 | before_install:
6 | - chmod +x mvnw
7 |
8 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | me.beldon
7 | code-generator
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | code-generator
12 | A code generate
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.3.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | 8.40.12
26 | 2.3.23
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter
33 |
34 |
35 |
36 | org.freemarker
37 | freemarker
38 | 2.3.26-incubating
39 |
40 |
41 |
42 | org.xerial
43 | sqlite-jdbc
44 | 3.16.1
45 |
46 |
47 |
48 | mysql
49 | mysql-connector-java
50 | 5.1.28
51 |
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-data-jpa
56 |
57 |
58 |
59 | com.alibaba
60 | druid
61 | 1.0.29
62 |
63 |
64 |
65 | de.roskenet
66 | springboot-javafx-support
67 | 1.3.22
68 |
69 |
70 |
71 | org.controlsfx
72 | controlsfx
73 | ${controlsfx.version}
74 |
75 |
76 |
77 | org.freemarker
78 | freemarker
79 | ${freemarker.version}
80 |
81 |
82 |
83 | com.alibaba
84 | fastjson
85 | 1.2.31
86 |
87 |
88 |
89 | org.springframework.boot
90 | spring-boot-starter-test
91 | test
92 |
93 |
94 |
95 |
96 | Generate
97 | src/main/java
98 | src/test/java
99 |
100 |
101 | src/main/resources
102 |
103 |
104 | src/main/java
105 |
106 | **/*.fxml
107 |
108 |
109 |
110 |
111 |
112 | src/test/resources
113 |
114 |
115 |
116 |
117 | org.springframework.boot
118 | spring-boot-maven-plugin
119 |
120 |
121 | com.zenjava
122 | javafx-maven-plugin
123 | 8.8.3
124 |
125 | Generate
126 | me.beldon.GenerateApplication
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 |
2 | [](https://www.travis-ci.org/beldon/code-generator)
3 |
4 | ### 一个基于Freemarker的代码生成器
5 |
6 | #### 目标
7 | * 实现一个通用的代码生成器
8 | * 代码生成器模板管理,用户自定义模板即可生成自己的代码
9 | * 支持多种数据库
10 |
11 | #### 数据库支持
12 | * [ x ] Mysql
13 | * [ ] Oracle
14 | * [ ] ...
15 |
16 |
17 | 
18 | 
19 | 
20 |
--------------------------------------------------------------------------------
/res/generate.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/res/generate.db
--------------------------------------------------------------------------------
/res/readme.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/res/readme.md
--------------------------------------------------------------------------------
/res/screenshot/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/res/screenshot/1.jpg
--------------------------------------------------------------------------------
/res/screenshot/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/res/screenshot/2.jpg
--------------------------------------------------------------------------------
/res/screenshot/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/res/screenshot/3.jpg
--------------------------------------------------------------------------------
/res/templates/demo2/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Demo模板",
3 | "author": "Beldon",
4 | "url":"http://www.baidu.com",
5 | "description": "我的模板文件",
6 | "templates":[
7 | {
8 | "name": "Dao",
9 | "description": "Dao文件",
10 | "fileName":"dao.ftl",
11 | "targetPackage": ".dao",
12 | "targetFileName":"I${domainName!}Dao.java"
13 | },{
14 | "name": "Mapper",
15 | "description": "Mapper文件",
16 | "fileName": "mapper.ftl",
17 | "targetPackage": ".dao",
18 | "targetFileName":"I${domainName!}Dao.xml"
19 | },{
20 | "name": "Domain",
21 | "description": "Domain文件",
22 | "fileName": "domain.ftl",
23 | "targetPackage": ".domain",
24 | "targetFileName":"${domainName!}.java"
25 | }
26 | ]
27 | }
--------------------------------------------------------------------------------
/res/templates/demo2/dao.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | import ${(data.basePackage)!}${(data.domainPackage)!}.${domainName!};
4 | import org.apache.ibatis.annotations.Delete;
5 | import org.apache.ibatis.annotations.ResultMap;
6 | import org.springframework.stereotype.Repository;
7 | import org.apache.ibatis.annotations.Select;
8 | import org.apache.ibatis.annotations.Param;
9 | import eworks.core.bean.Page;
10 | import eworks.core.bean.Query;
11 | import java.util.List;
12 |
13 | /**
14 | * ${(table.tableComment)!}
15 | * Created by ${(data.author)!}.
16 | * Copyright (c) ${.now}, All Rights Reserved.
17 | * ${(data.url)!}
18 | */
19 | @Repository
20 | public interface ${className!} {
21 |
22 | int insert(${domainName!} ${domainName?uncap_first!});
23 |
24 | int insertSelective(${domainName!} ${domainName?uncap_first!});
25 |
26 | @Delete({
27 | "delete from ${(table.tableName)!}",
28 | "where ${(primaryData.column.columnName)!} = ${r"#{"}${(primaryData.name)!},jdbcType=${(primaryData.type.jdbcType)!}${r"}"}"
29 | })
30 | int deleteByPrimaryKey(${(primaryData.type.javaType)!} ${(primaryData.name)!});
31 |
32 | int updateByPrimaryKey(${domainName!} ${domainName?uncap_first!});
33 |
34 | int updateByPrimaryKeySelective(${domainName!} ${domainName?uncap_first!});
35 |
36 | @Select({
37 | "select * ",
38 | "from ${(table.tableName)!}",
39 | "where ${(primaryData.column.columnName)!} = ${r"#{"}${(primaryData.name)!},jdbcType=${(primaryData.type.jdbcType)!}${r"}"}"
40 | })
41 | @ResultMap("BaseResultMap")
42 | ${domainName!} selectByPrimaryKey(${(primaryData.type.javaType)!} ${(primaryData.name)!});
43 |
44 | @ResultMap("BaseResultMap")
45 | List<${domainName!}> query(@Param("query") Query query);
46 |
47 | @ResultMap("BaseResultMap")
48 | List<${domainName!}> query(@Param("${domainName?uncap_first!}") Page<${domainName!}> page, @Param("query") Query query);
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/res/templates/demo2/domain.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | <#list importType as im>
4 | import ${im!};
5 | #list>
6 |
7 | /**
8 | * ${(table.tableComment)!}
9 | * Created by ${(data.author)!}.
10 | * Copyright (c) ${.now}, All Rights Reserved.
11 | * ${url!}
12 | */
13 | public class ${domainName!} {
14 |
15 | <#list columnDatas as columnData>
16 | /**
17 | * ${(columnData.column.columnComment)!}
18 | */
19 | private ${(columnData.type.javaType)!} ${(columnData.name)!};
20 | #list>
21 |
22 | <#list columnDatas as columnData>
23 | public ${(columnData.type.javaType)!} get${(columnData.name)?cap_first!}() {
24 | return ${(columnData.name)!};
25 | }
26 |
27 | public void set${(columnData.name)?cap_first!}(${(columnData.type.javaType)!} ${(columnData.name)!}) {
28 | this.${(columnData.name)!} = ${(columnData.name)!};
29 | }
30 |
31 | #list>
32 | }
33 |
--------------------------------------------------------------------------------
/res/templates/demo2/iservice.ftl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/res/templates/demo2/iservice.ftl
--------------------------------------------------------------------------------
/res/templates/demo2/mapper.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | <#list columnDatas as columnData>
6 | <#if columnData.column.columnKey == "PRI">
7 |
8 | <#else >
9 |
10 | #if>
11 | #list>
12 |
13 |
14 |
15 | <#list columnDatas as columnData>
16 | <#if columnData.column.columnKey != "PRI">
17 | ${(columnData.column.columnName)!}<#if columnData_has_next>,#if>
18 | #if>
19 | #list>
20 |
21 |
22 |
23 |
24 | ${(primaryData.column.columnName)!},
25 |
26 |
27 |
28 | <#list columnDatas as columnData>
29 | <#if columnData.column.columnKey != "PRI">
30 | ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
31 | #if>
32 | #list>
33 |
34 |
35 |
36 | ${r"#{"}${(primaryData.name)!}${r"}"},
37 |
38 |
39 |
40 |
41 |
42 | select replace(uuid(),'-','')
43 |
44 | insert into ${(table.tableName)!} ()
45 | values ()
46 |
47 |
48 |
49 |
50 |
51 | select replace(uuid(),'-','')
52 |
53 | insert into ${(table.tableName)!}
54 |
55 | <#list columnDatas as columnData>
56 |
57 | ${(columnData.column.columnName)!}<#if columnData_has_next>,#if>
58 |
59 | #list>
60 |
61 |
62 | <#list columnDatas as columnData>
63 |
64 | ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
65 |
66 | #list>
67 |
68 |
69 |
70 |
71 |
72 | update ${(table.tableName)!}
73 |
74 | <#list columnDatas as columnData>
75 | <#if columnData.column.columnKey != "PRI">
76 | ${(columnData.column.columnName)!}= ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
77 | #if>
78 | #list>
79 |
80 | where ${(primaryData.name)!} = ${r"#{"}${(primaryData.name)!}${r"}"}
81 |
82 |
83 |
84 | update ${(table.tableName)!}
85 |
86 | <#list columnDatas as columnData>
87 | <#if columnData.column.columnKey != "PRI">
88 |
89 | ${(columnData.column.columnName)!}= ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
90 |
91 | #if>
92 | #list>
93 |
94 | where ${(primaryData.name)!} = ${r"#{"}${(primaryData.name)!}${r"}"}
95 |
96 |
97 |
168 |
169 |
--------------------------------------------------------------------------------
/res/templates/demo2/service.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | import org.apache.ibatis.annotations.Delete;
4 | import org.apache.ibatis.annotations.Insert;
5 | import org.apache.ibatis.annotations.ResultMap;
6 | import org.apache.ibatis.annotations.Select;
7 | import org.apache.ibatis.annotations.SelectKey;
8 | import org.apache.ibatis.annotations.Update;
9 |
10 | /**
11 | * ${(table.tableComment)!}
12 | * Created by ${author!}.
13 | * Copyright (c) ${.now}, All Rights Reserved.
14 | * ${(data.url)!}
15 | */
16 | public interface ${className!} {
17 | int insert();
18 | int update();
19 | int delete(Long id);
20 | }
21 |
--------------------------------------------------------------------------------
/res/templates/don/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Don Kotlin模板",
3 | "author": "Beldon",
4 | "url":"http://blog.beldon.me",
5 | "description": "Don程序的模板",
6 | "templates":[
7 | {
8 | "name":"Domain",
9 | "description": "Domain文件",
10 | "basePath": "/src/main/kotlin",
11 | "fileName":"domain.ftl",
12 | "targetPackage": ".domain",
13 | "targetFileName":"${domainName}.kt"
14 | },{
15 | "name": "Dao",
16 | "description": "Dao文件",
17 | "basePath": "/src/main/kotlin",
18 | "fileName":"dao.ftl",
19 | "targetPackage": ".dao",
20 | "targetFileName":"I${domainName}Dao.kt"
21 | },{
22 | "name": "Mapper",
23 | "description": "Mapper文件",
24 | "basePath": "/src/main/kotlin",
25 | "fileName":"mapper.ftl",
26 | "targetPackage": ".dao",
27 | "targetFileName":"I${domainName}Dao.xml"
28 | },{
29 | "name": "IService",
30 | "description": "IService文件",
31 | "basePath": "/src/main/kotlin",
32 | "fileName":"iservice.ftl",
33 | "targetPackage": ".service",
34 | "targetFileName":"I${domainName}Service.kt"
35 | },{
36 | "name": "Service",
37 | "description": "Service文件",
38 | "basePath": "/src/main/kotlin",
39 | "fileName":"service.ftl",
40 | "targetPackage": ".service.impl",
41 | "targetFileName":"${domainName}Service.kt"
42 | }
43 | ]
44 | }
--------------------------------------------------------------------------------
/res/templates/don/dao.ftl:
--------------------------------------------------------------------------------
1 | package ${package!}
2 |
3 | import ${(data.basePackage)!}.domain.${domainName!}
4 | import org.apache.ibatis.annotations.Delete
5 | import org.apache.ibatis.annotations.ResultMap
6 | import org.springframework.stereotype.Repository
7 | import org.apache.ibatis.annotations.Select
8 | import org.apache.ibatis.annotations.Param
9 | import don.core.bean.Page
10 | import don.core.bean.Query
11 |
12 | /**
13 | * ${(table.tableComment)!}
14 | * Created by ${(data.author)!}.
15 | * Copyright (c) ${.now}, All Rights Reserved.
16 | * ${(data.url)!}
17 | */
18 | @Repository
19 | interface ${className!} {
20 |
21 | fun insert(${domainName?uncap_first!}: ${domainName!}): Int
22 |
23 | fun insertSelective(${domainName?uncap_first!}: ${domainName!}): Int
24 |
25 | @Delete("delete from ${(table.tableName)!} where ${(primaryData.column.columnName)!} = ${r"#{"}${(primaryData.name)!}${r"}"}")
26 | fun deleteByPrimaryKey(${(primaryData.name)!}: ${(primaryData.type.javaType)!}): Int
27 |
28 | fun updateByPrimaryKey(${domainName?uncap_first!}: ${domainName!}): Int
29 |
30 | fun updateByPrimaryKeySelective(${domainName?uncap_first!}: ${domainName!}): Int
31 |
32 | @Select("select * from ${(table.tableName)!} where ${(primaryData.column.columnName)!} = ${r"#{"}${(primaryData.name)!}${r"}"}")
33 | fun selectByPrimaryKey(${(primaryData.name)!}: ${(primaryData.type.javaType)!}): ${domainName!}?
34 |
35 | @ResultMap("BaseResultMap")
36 | fun query(@Param("query") query: Query): List<${domainName!}>
37 |
38 | fun query(@Param("page") page: Page, @Param("query") query: Query): List<${domainName!}>
39 |
40 | }
--------------------------------------------------------------------------------
/res/templates/don/domain.ftl:
--------------------------------------------------------------------------------
1 | package ${package!}
2 |
3 | <#list importType as im>
4 | import ${im!}
5 | #list>
6 |
7 | /**
8 | * ${(table.tableComment)!}
9 | * Created by ${(data.author)!}.
10 | * Copyright (c) ${.now}, All Rights Reserved.
11 | * ${url!}
12 | */
13 | class ${domainName!} {
14 | <#list columnDatas as columnData>
15 | /**
16 | * ${(columnData.column.columnComment)!}
17 | */
18 | var ${(columnData.name)!}: ${(columnData.type.javaType)!}? = null
19 | #list>
20 | }
--------------------------------------------------------------------------------
/res/templates/don/iservice.ftl:
--------------------------------------------------------------------------------
1 | package ${package!}
2 |
3 | import ${(data.basePackage)!}.domain.${domainName!}
4 |
5 | /**
6 | * ${(table.tableComment)!}
7 | * Created by ${(data.author)!}.
8 | * Copyright (c) ${.now}, All Rights Reserved.
9 | * ${(data.url)!}
10 | */
11 | interface ${className!} {
12 | fun findById(${(primaryData.name)!}: ${(primaryData.type.javaType)!}): ${domainName!}?
13 |
14 | fun deleteById(${(primaryData.name)!}: ${(primaryData.type.javaType)!}): Int
15 | }
--------------------------------------------------------------------------------
/res/templates/don/mapper.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | <#list columnDatas as columnData>
6 | <#if columnData.column.columnKey == "PRI">
7 |
8 | <#else >
9 |
10 | #if>
11 | #list>
12 |
13 |
14 |
15 | <#list columnDatas as columnData>
16 | <#if columnData.column.columnKey != "PRI">
17 | ${(columnData.column.columnName)!}<#if columnData_has_next>,#if>
18 | #if>
19 | #list>
20 |
21 |
22 |
23 |
24 | ${(primaryData.column.columnName)!},
25 |
26 |
27 |
28 | <#list columnDatas as columnData>
29 | <#if columnData.column.columnKey != "PRI">
30 | ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
31 | #if>
32 | #list>
33 |
34 |
35 |
36 | ${r"#{"}${(primaryData.name)!}${r"}"},
37 |
38 |
39 |
40 |
41 |
42 | select replace(uuid(),'-','')
43 |
44 | insert into ${(table.tableName)!} ()
45 | values ()
46 |
47 |
48 |
49 |
50 |
51 | select replace(uuid(),'-','')
52 |
53 | insert into ${(table.tableName)!}
54 |
55 | <#list columnDatas as columnData>
56 |
57 | ${(columnData.column.columnName)!}<#if columnData_has_next>,#if>
58 |
59 | #list>
60 |
61 |
62 | <#list columnDatas as columnData>
63 |
64 | ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
65 |
66 | #list>
67 |
68 |
69 |
70 |
71 |
72 | update ${(table.tableName)!}
73 |
74 | <#list columnDatas as columnData>
75 | <#if columnData.column.columnKey != "PRI">
76 | ${(columnData.column.columnName)!}= ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
77 | #if>
78 | #list>
79 |
80 | where ${(primaryData.name)!} = ${r"#{"}${(primaryData.name)!}${r"}"}
81 |
82 |
83 |
84 | update ${(table.tableName)!}
85 |
86 | <#list columnDatas as columnData>
87 | <#if columnData.column.columnKey != "PRI">
88 |
89 | ${(columnData.column.columnName)!}= ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
90 |
91 | #if>
92 | #list>
93 |
94 | where ${(primaryData.name)!} = ${r"#{"}${(primaryData.name)!}${r"}"}
95 |
96 |
97 |
168 |
169 |
--------------------------------------------------------------------------------
/res/templates/don/service.ftl:
--------------------------------------------------------------------------------
1 | package ${package!}
2 |
3 | import don.core.common.service.ServiceBase
4 | import ${(data.basePackage)!}.dao.I${domainName!}Dao
5 | import ${(data.basePackage)!}.service.I${domainName!}Service
6 | import org.springframework.beans.factory.annotation.Autowired
7 | import org.springframework.stereotype.Service
8 |
9 | /**
10 | * ${(table.tableComment)!}
11 | * Created by ${(data.author)!}.
12 | * Copyright (c) ${.now}, All Rights Reserved.
13 | * ${(data.url)!}
14 | */
15 | @Service
16 | class ${className!} : ServiceBase(), I${className!} {
17 |
18 | @Autowired
19 | private lateinit var ${domainName?uncap_first!}Dao: I${domainName!}Dao
20 |
21 | override fun deleteById(${(primaryData.name)!}: ${(primaryData.type.javaType)!}) = ${domainName?uncap_first!}Dao.deleteByPrimaryKey(${(primaryData.name)!})
22 |
23 | override fun findById(${(primaryData.name)!}: ${(primaryData.type.javaType)!}) = ${domainName?uncap_first!}Dao.selectByPrimaryKey(${(primaryData.name)!})
24 |
25 | }
--------------------------------------------------------------------------------
/res/templates/donJava/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "DonJava模板",
3 | "author": "Beldon",
4 | "url":"http://blog.beldon.me",
5 | "description": "Don程序的模板",
6 | "templates":[
7 | {
8 | "name":"Domain",
9 | "description": "Domain文件",
10 | "fileName":"domain.ftl",
11 | "targetPackage": ".domain",
12 | "targetFileName":"${domainName}.java"
13 | },{
14 | "name": "Dao",
15 | "description": "Dao文件",
16 | "fileName":"dao.ftl",
17 | "targetPackage": ".dao",
18 | "targetFileName":"I${domainName}Dao.java"
19 | },{
20 | "name": "Mapper",
21 | "description": "Mapper文件",
22 | "fileName":"mapper.ftl",
23 | "targetPackage": ".dao",
24 | "targetFileName":"I${domainName}Dao.xml"
25 | },{
26 | "name": "IService",
27 | "description": "IService文件",
28 | "fileName":"iservice.ftl",
29 | "targetPackage": ".service",
30 | "targetFileName":"I${domainName}Service.java"
31 | },{
32 | "name": "Service",
33 | "description": "Service文件",
34 | "fileName":"service.ftl",
35 | "targetPackage": ".service.impl",
36 | "targetFileName":"${domainName}Service.java"
37 | }
38 | ]
39 | }
--------------------------------------------------------------------------------
/res/templates/donJava/dao.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | import ${(data.basePackage)!}.domain.${domainName!};
4 | import org.apache.ibatis.annotations.Delete;
5 | import org.apache.ibatis.annotations.ResultMap;
6 | import org.springframework.stereotype.Repository;
7 | import org.apache.ibatis.annotations.Select;
8 | import org.apache.ibatis.annotations.Param;
9 | import don.core.bean.Page;
10 | import don.core.bean.Query;
11 | import java.util.List;
12 |
13 | /**
14 | * ${(table.tableComment)!}
15 | * Created by ${(data.author)!}.
16 | * Copyright (c) ${.now}, All Rights Reserved.
17 | * ${(data.url)!}
18 | */
19 | @Repository
20 | public interface ${className!} {
21 |
22 | int insert(${domainName!} ${domainName?uncap_first!});
23 |
24 | int insertSelective(${domainName!} ${domainName?uncap_first!});
25 |
26 | @Delete("delete from ${(table.tableName)!} where ${(primaryData.column.columnName)!} = ${r"#{"}${(primaryData.name)!}${r"}"}")
27 | int deleteByPrimaryKey(${(primaryData.type.javaType)!} ${(primaryData.name)!});
28 |
29 | int updateByPrimaryKey(${domainName!} ${domainName?uncap_first!});
30 |
31 | int updateByPrimaryKeySelective(${domainName!} ${domainName?uncap_first!});
32 |
33 | @Select("select * from ${(table.tableName)!} where ${(primaryData.column.columnName)!} = ${r"#{"}${(primaryData.name)!}${r"}"}")
34 | @ResultMap("BaseResultMap")
35 | ${domainName!} selectByPrimaryKey(${(primaryData.type.javaType)!} ${(primaryData.name)!});
36 |
37 | @ResultMap("BaseResultMap")
38 | List<${domainName!}> query(@Param("query") Query query);
39 |
40 | @ResultMap("BaseResultMap")
41 | List<${domainName!}> query(@Param("${domainName?uncap_first!}") Page<${domainName!}> page, @Param("query") Query query);
42 |
43 | }
--------------------------------------------------------------------------------
/res/templates/donJava/domain.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | <#list importType as im>
4 | import ${im!};
5 | #list>
6 |
7 | /**
8 | * ${(table.tableComment)!}
9 | * Created by ${(data.author)!}.
10 | * Copyright (c) ${.now}, All Rights Reserved.
11 | * ${url!}
12 | */
13 | public class ${domainName!} {
14 | <#list columnDatas as columnData>
15 | /**
16 | * ${(columnData.column.columnComment)!}
17 | */
18 | private ${(columnData.type.javaType)!} ${(columnData.name)!};
19 | #list>
20 |
21 | <#list columnDatas as columnData>
22 | public ${(columnData.type.javaType)!} get${(columnData.name)?cap_first!}() {
23 | return ${(columnData.name)!};
24 | }
25 |
26 | public void set${(columnData.name)?cap_first!}(${(columnData.type.javaType)!} ${(columnData.name)!}) {
27 | this.${(columnData.name)!} = ${(columnData.name)!};
28 | }
29 |
30 | #list>
31 | }
32 |
--------------------------------------------------------------------------------
/res/templates/donJava/iservice.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | import ${(data.basePackage)!}.domain.${domainName!};
4 | import java.util.Optional;
5 |
6 | /**
7 | * ${(table.tableComment)!}
8 | * Created by ${(data.author)!}.
9 | * Copyright (c) ${.now}, All Rights Reserved.
10 | * ${(data.url)!}
11 | */
12 | public interface ${className!} {
13 |
14 | Optional<${domainName!}> findById(${(primaryData.type.javaType)!} ${(primaryData.name)!});
15 |
16 | void deleteById(${(primaryData.type.javaType)!} ${(primaryData.name)!});
17 | }
--------------------------------------------------------------------------------
/res/templates/donJava/mapper.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | <#list columnDatas as columnData>
6 | <#if columnData.column.columnKey == "PRI">
7 |
8 | <#else >
9 |
10 | #if>
11 | #list>
12 |
13 |
14 |
15 | <#list columnDatas as columnData>
16 | <#if columnData.column.columnKey != "PRI">
17 | `${(columnData.column.columnName)!}`<#if columnData_has_next>,#if>
18 | #if>
19 | #list>
20 |
21 |
22 |
23 |
24 | `${(primaryData.column.columnName)!}`,
25 |
26 |
27 |
28 | <#list columnDatas as columnData>
29 | <#if columnData.column.columnKey != "PRI">
30 | ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
31 | #if>
32 | #list>
33 |
34 |
35 |
36 | ${r"#{"}${(primaryData.name)!}${r"}"},
37 |
38 |
39 |
40 |
41 |
42 | select replace(uuid(),'-','')
43 |
44 | insert into ${(table.tableName)!} ()
45 | values ()
46 |
47 |
48 |
49 |
50 |
51 | select replace(uuid(),'-','')
52 |
53 | insert into ${(table.tableName)!}
54 |
55 | <#list columnDatas as columnData>
56 |
57 | `${(columnData.column.columnName)!}`<#if columnData_has_next>,#if>
58 |
59 | #list>
60 |
61 |
62 | <#list columnDatas as columnData>
63 |
64 | ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
65 |
66 | #list>
67 |
68 |
69 |
70 |
71 |
72 | update ${(table.tableName)!}
73 |
74 | <#list columnDatas as columnData>
75 | <#if columnData.column.columnKey != "PRI">
76 | `${(columnData.column.columnName)!}`= ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
77 | #if>
78 | #list>
79 |
80 | where `${(primaryData.column.columnName)!}` = ${r"#{"}${(primaryData.name)!}${r"}"}
81 |
82 |
83 |
84 | update ${(table.tableName)!}
85 |
86 | <#list columnDatas as columnData>
87 | <#if columnData.column.columnKey != "PRI">
88 |
89 | `${(columnData.column.columnName)!}`= ${r"#{"}${(columnData.name)!}${r"}"}<#if columnData_has_next>,#if>
90 |
91 | #if>
92 | #list>
93 |
94 | where `${(primaryData.column.columnName)!}` = ${r"#{"}${(primaryData.name)!}${r"}"}
95 |
96 |
97 |
168 |
169 |
--------------------------------------------------------------------------------
/res/templates/donJava/service.ftl:
--------------------------------------------------------------------------------
1 | package ${package!};
2 |
3 | import don.core.common.service.ServiceBase;
4 | import ${(data.basePackage)!}.dao.I${domainName!}Dao;
5 | import ${(data.basePackage)!}.service.I${domainName!}Service;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 | import ${(data.basePackage)!}.domain.${domainName!};
9 | import java.util.Optional;
10 | import org.springframework.util.Assert;
11 |
12 | /**
13 | * ${(table.tableComment)!}
14 | * Created by ${(data.author)!}.
15 | * Copyright (c) ${.now}, All Rights Reserved.
16 | * ${(data.url)!}
17 | */
18 | @Service
19 | public class ${className!} extends ServiceBase implements I${className!} {
20 |
21 | @Autowired
22 | private I${domainName!}Dao ${domainName?uncap_first!}Dao;
23 |
24 | @Override
25 | public Optional<${domainName!}> findById(${(primaryData.type.javaType)!} ${(primaryData.name)!}) {
26 | Assert.notNull(${(primaryData.name)!},"${(primaryData.name)!} is required");
27 | ${domainName} ${domainName?uncap_first!} = ${domainName?uncap_first!}Dao.selectByPrimaryKey(${(primaryData.name)!});
28 | return Optional.ofNullable(${domainName?uncap_first!});
29 | }
30 |
31 | @Override
32 | public void deleteById(${(primaryData.type.javaType)!} ${(primaryData.name)!}) {
33 | Assert.notNull(${(primaryData.name)!},"${(primaryData.name)!} is required");
34 | ${domainName?uncap_first!}Dao.deleteByPrimaryKey(${(primaryData.name)!});
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/me/beldon/GenerateApplication.java:
--------------------------------------------------------------------------------
1 | package me.beldon;
2 |
3 | import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
4 | import javafx.application.Platform;
5 | import javafx.geometry.Pos;
6 | import javafx.stage.Stage;
7 | import javafx.util.Duration;
8 | import me.beldon.module.generate.ui.GenerateView;
9 | import me.beldon.module.window.service.impl.WindowService;
10 | import me.beldon.module.window.ui.MainView;
11 | import me.beldon.util.SpringContextUtil;
12 | import org.controlsfx.control.Notifications;
13 | import org.springframework.boot.autoconfigure.SpringBootApplication;
14 | import org.springframework.context.annotation.Lazy;
15 |
16 | import java.awt.*;
17 |
18 | @SpringBootApplication
19 | public class GenerateApplication extends AbstractJavaFxApplicationSupport {
20 |
21 | public static void main(String[] args) {
22 | // launchApp(GenerateApplication.class, MainView.class, args);
23 | launchApp(GenerateApplication.class, GenerateView.class, args);
24 | }
25 |
26 | @Override
27 | public void start(Stage stage) throws Exception {
28 | SystemTray.isSupported();//支持系統托盤
29 | super.start(stage);
30 | getStage().setOnCloseRequest(event -> {
31 | Platform.setImplicitExit(false); //禁止退出
32 | Platform.runLater(getStage()::hide); //最小化到托盘
33 | WindowService windowService = SpringContextUtil.getApplicationContext().getBean(WindowService.class);
34 | windowService.enableTray();
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/config/CoreConfig.java:
--------------------------------------------------------------------------------
1 | package me.beldon.config;
2 |
3 | import freemarker.template.Version;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | import java.io.File;
8 | import java.io.IOException;
9 |
10 | /**
11 | * Created by Beldon.
12 | * Copyright (c) 2017/5/21, All Rights Reserved.
13 | * http://beldon.me
14 | */
15 | @Configuration
16 | public class CoreConfig {
17 |
18 | @Bean
19 | public freemarker.template.Configuration configuration() {
20 | freemarker.template.Configuration configuration = new freemarker.template.Configuration(new Version("2.3.0"));
21 | try {
22 | configuration.setDirectoryForTemplateLoading(new File("./res/"));
23 | configuration.setDefaultEncoding("utf-8");
24 | } catch (IOException e) {
25 | e.printStackTrace();
26 | }
27 |
28 | return configuration;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/core/SQLiteDialect.java:
--------------------------------------------------------------------------------
1 | package me.beldon.core;
2 |
3 | import org.hibernate.dialect.Dialect;
4 | import org.hibernate.dialect.function.SQLFunctionTemplate;
5 | import org.hibernate.dialect.function.StandardSQLFunction;
6 | import org.hibernate.dialect.function.VarArgsSQLFunction;
7 | import org.hibernate.type.StringType;
8 |
9 | import java.sql.Types;
10 |
11 | /**
12 | * Created by Beldon.
13 | * Copyright (c) 2017/5/21, All Rights Reserved.
14 | * http://beldon.me
15 | */
16 | public class SQLiteDialect extends Dialect {
17 | public SQLiteDialect() {
18 | registerColumnType(Types.BIT, "integer");
19 | registerColumnType(Types.TINYINT, "tinyint");
20 | registerColumnType(Types.SMALLINT, "smallint");
21 | registerColumnType(Types.INTEGER, "integer");
22 | registerColumnType(Types.BIGINT, "bigint");
23 | registerColumnType(Types.FLOAT, "float");
24 | registerColumnType(Types.REAL, "real");
25 | registerColumnType(Types.DOUBLE, "double");
26 | registerColumnType(Types.NUMERIC, "numeric");
27 | registerColumnType(Types.DECIMAL, "decimal");
28 | registerColumnType(Types.CHAR, "char");
29 | registerColumnType(Types.VARCHAR, "varchar");
30 | registerColumnType(Types.LONGVARCHAR, "longvarchar");
31 | registerColumnType(Types.DATE, "date");
32 | registerColumnType(Types.TIME, "time");
33 | registerColumnType(Types.TIMESTAMP, "timestamp");
34 | registerColumnType(Types.BINARY, "blob");
35 | registerColumnType(Types.VARBINARY, "blob");
36 | registerColumnType(Types.LONGVARBINARY, "blob");
37 | // registerColumnType(Types.NULL, "null");
38 | registerColumnType(Types.BLOB, "blob");
39 | registerColumnType(Types.CLOB, "clob");
40 | registerColumnType(Types.BOOLEAN, "integer");
41 |
42 | registerFunction( "concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", "") );
43 | registerFunction( "mod", new SQLFunctionTemplate( StringType.INSTANCE, "?1 % ?2" ) );
44 | registerFunction( "substr", new StandardSQLFunction("substr", StringType.INSTANCE) );
45 | registerFunction( "substring", new StandardSQLFunction( "substr", StringType.INSTANCE) );
46 | }
47 |
48 | public boolean supportsIdentityColumns() {
49 | return true;
50 | }
51 |
52 | /*
53 | public boolean supportsInsertSelectIdentity() {
54 | return true; // As specify in NHibernate dialect
55 | }
56 | */
57 |
58 | public boolean hasDataTypeInIdentityColumn() {
59 | return false; // As specify in NHibernate dialect
60 | }
61 |
62 | /*
63 | public String appendIdentitySelectToInsert(String insertString) {
64 | return new StringBuffer(insertString.length()+30). // As specify in NHibernate dialect
65 | append(insertString).
66 | append("; ").append(getIdentitySelectString()).
67 | toString();
68 | }
69 | */
70 |
71 | public String getIdentityColumnString() {
72 | // return "integer primary key autoincrement";
73 | return "integer";
74 | }
75 |
76 | public String getIdentitySelectString() {
77 | return "select last_insert_rowid()";
78 | }
79 |
80 | public boolean supportsLimit() {
81 | return true;
82 | }
83 |
84 | protected String getLimitString(String query, boolean hasOffset) {
85 | return new StringBuffer(query.length()+20).
86 | append(query).
87 | append(hasOffset ? " limit ? offset ?" : " limit ?").
88 | toString();
89 | }
90 |
91 | public boolean supportsTemporaryTables() {
92 | return true;
93 | }
94 |
95 | public String getCreateTemporaryTableString() {
96 | return "create temporary table if not exists";
97 | }
98 |
99 | public boolean dropTemporaryTableAfterUse() {
100 | return false;
101 | }
102 |
103 | public boolean supportsCurrentTimestampSelection() {
104 | return true;
105 | }
106 |
107 | public boolean isCurrentTimestampSelectStringCallable() {
108 | return false;
109 | }
110 |
111 | public String getCurrentTimestampSelectString() {
112 | return "select current_timestamp";
113 | }
114 |
115 | public boolean supportsUnionAll() {
116 | return true;
117 | }
118 |
119 | public boolean hasAlterTable() {
120 | return false; // As specify in NHibernate dialect
121 | }
122 |
123 | public boolean dropConstraints() {
124 | return false;
125 | }
126 |
127 | public String getAddColumnString() {
128 | return "add column";
129 | }
130 |
131 | public String getForUpdateString() {
132 | return "";
133 | }
134 |
135 | public boolean supportsOuterJoinForUpdate() {
136 | return false;
137 | }
138 |
139 | public String getDropForeignKeyString() {
140 | throw new UnsupportedOperationException("No drop foreign key syntax supported by SQLiteDialect");
141 | }
142 |
143 | public String getAddForeignKeyConstraintString(String constraintName,
144 | String[] foreignKey, String referencedTable, String[] primaryKey,
145 | boolean referencesPrimaryKey) {
146 | throw new UnsupportedOperationException("No add foreign key syntax supported by SQLiteDialect");
147 | }
148 |
149 | public String getAddPrimaryKeyConstraintString(String constraintName) {
150 | throw new UnsupportedOperationException("No add primary key syntax supported by SQLiteDialect");
151 | }
152 |
153 | public boolean supportsIfExistsBeforeTableName() {
154 | return true;
155 | }
156 |
157 | public boolean supportsCascadeDelete() {
158 | return false;
159 | }
160 | }
--------------------------------------------------------------------------------
/src/main/java/me/beldon/core/util/SpringContextUtils.java:
--------------------------------------------------------------------------------
1 | package me.beldon.core.util;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * Created by Beldon.
10 | * Copyright (c) 2017/5/21, All Rights Reserved.
11 | * http://beldon.me
12 | */
13 | @Component
14 | public class SpringContextUtils implements ApplicationContextAware {
15 | private static ApplicationContext applicationContext;
16 | @Override
17 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
18 | SpringContextUtils.applicationContext = applicationContext;
19 | }
20 |
21 | public static ApplicationContext getApplicationContext() {
22 | return applicationContext;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/bean/ColumnData.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.bean;
2 |
3 |
4 | import me.beldon.module.database.entity.mysql.Columns;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2016/10/18, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | public class ColumnData {
12 | private String name;
13 | private Type type;
14 | private Columns column;
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public void setName(String name) {
21 | this.name = name;
22 | }
23 |
24 | public Type getType() {
25 | return type;
26 | }
27 |
28 | public void setType(Type type) {
29 | this.type = type;
30 | }
31 |
32 | public Columns getColumn() {
33 | return column;
34 | }
35 |
36 | public void setColumn(Columns column) {
37 | this.column = column;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/bean/GenerateData.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.bean;
2 |
3 | import me.beldon.module.database.entity.mysql.Columns;
4 | import me.beldon.module.database.entity.mysql.Tables;
5 | import me.beldon.module.template.bean.TemplateDetails;
6 | import me.beldon.module.template.bean.TemplateFtl;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * 代码生成的基本信息
12 | * Created by Beldon.
13 | * Copyright (c) 2016/10/14, All Rights Reserved.
14 | * http://beldon.me
15 | */
16 | public class GenerateData {
17 | /**
18 | * 作者
19 | */
20 | private String author = "";
21 |
22 | private String url = "";
23 |
24 | /**
25 | * 代码生成的根路径
26 | */
27 | private String basePath;
28 |
29 | /**
30 | * 基本的包
31 | */
32 | private String basePackage;
33 |
34 | /**
35 | * 模板详情
36 | */
37 | private TemplateDetails templateDetails;
38 |
39 | /**
40 | * 模板
41 | */
42 | private TemplateFtl template;
43 |
44 | /**
45 | * 实体类名称
46 | */
47 | private String domainName;
48 |
49 | /**
50 | * 模板路径
51 | */
52 | private String templatePath;
53 |
54 | /**
55 | * 表
56 | */
57 | private Tables table;
58 |
59 | public String getAuthor() {
60 | return author;
61 | }
62 |
63 | public void setAuthor(String author) {
64 | this.author = author;
65 | }
66 |
67 | public String getUrl() {
68 | return url;
69 | }
70 |
71 | public void setUrl(String url) {
72 | this.url = url;
73 | }
74 |
75 | public String getBasePath() {
76 | return basePath;
77 | }
78 |
79 | public void setBasePath(String basePath) {
80 | this.basePath = basePath;
81 | }
82 |
83 | public String getBasePackage() {
84 | return basePackage;
85 | }
86 |
87 | public void setBasePackage(String basePackage) {
88 | this.basePackage = basePackage;
89 | }
90 |
91 | public TemplateDetails getTemplateDetails() {
92 | return templateDetails;
93 | }
94 |
95 | public void setTemplateDetails(TemplateDetails templateDetails) {
96 | this.templateDetails = templateDetails;
97 | }
98 |
99 | public TemplateFtl getTemplate() {
100 | return template;
101 | }
102 |
103 | public void setTemplate(TemplateFtl template) {
104 | this.template = template;
105 | }
106 |
107 | public String getTemplatePath() {
108 | return templatePath;
109 | }
110 |
111 | public void setTemplatePath(String templatePath) {
112 | this.templatePath = templatePath;
113 | }
114 |
115 | public Tables getTable() {
116 | return table;
117 | }
118 |
119 | public void setTable(Tables table) {
120 | this.table = table;
121 | }
122 |
123 | public String getDomainName() {
124 | return domainName;
125 | }
126 |
127 | public void setDomainName(String domainName) {
128 | this.domainName = domainName;
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/bean/Type.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.bean;
2 |
3 | /**
4 | * Created by Beldon.
5 | * Copyright (c) 2016/10/18, All Rights Reserved.
6 | * http://beldon.me
7 | */
8 | public class Type {
9 | private String mysqlType;
10 | private String jdbcType;
11 | private String javaType;
12 | private String javaFullType;
13 |
14 | public Type() {
15 | }
16 |
17 | public Type(String mysqlType, String jdbcType, String javaType, String javaFullType) {
18 | this.mysqlType = mysqlType;
19 | this.jdbcType = jdbcType;
20 | this.javaType = javaType;
21 | this.javaFullType = javaFullType;
22 | }
23 |
24 | public String getMysqlType() {
25 | return mysqlType;
26 | }
27 |
28 | public void setMysqlType(String mysqlType) {
29 | this.mysqlType = mysqlType;
30 | }
31 |
32 | public String getJdbcType() {
33 | return jdbcType;
34 | }
35 |
36 | public void setJdbcType(String jdbcType) {
37 | this.jdbcType = jdbcType;
38 | }
39 |
40 | public String getJavaType() {
41 | return javaType;
42 | }
43 |
44 | public void setJavaType(String javaType) {
45 | this.javaType = javaType;
46 | }
47 |
48 | public String getJavaFullType() {
49 | return javaFullType;
50 | }
51 |
52 | public void setJavaFullType(String javaFullType) {
53 | this.javaFullType = javaFullType;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/entity/mysql/Columns.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.entity.mysql;
2 |
3 | /**
4 | * 字段表
5 | * Created by Beldon.
6 | * Copyright (c) 2016/10/14, All Rights Reserved.
7 | * http://beldon.me
8 | */
9 | public class Columns {
10 | private String tableCatalog;
11 | private String tableSchema;
12 | private String tableName;
13 | private String columnName;
14 | private Long ordinalPosition;
15 | private String columnDefault;
16 | private String isNullable;
17 | private String dataType;
18 | private Long characterMaximumLength;
19 | private Long characterOctetLength;
20 | private Long numberPrecision;
21 | private Long numberScale;
22 | private String characterSetName;
23 | private String collationName;
24 | private String columnType;
25 | private String columnKey;//PRI:主键
26 | private String extra;
27 | /**
28 | * 权限
29 | */
30 | private String privileges;
31 | /**
32 | * 字段注释
33 | */
34 | private String columnComment;
35 |
36 | public String getTableCatalog() {
37 | return tableCatalog;
38 | }
39 |
40 | public void setTableCatalog(String tableCatalog) {
41 | this.tableCatalog = tableCatalog;
42 | }
43 |
44 | public String getTableSchema() {
45 | return tableSchema;
46 | }
47 |
48 | public void setTableSchema(String tableSchema) {
49 | this.tableSchema = tableSchema;
50 | }
51 |
52 | public String getTableName() {
53 | return tableName;
54 | }
55 |
56 | public void setTableName(String tableName) {
57 | this.tableName = tableName;
58 | }
59 |
60 | public String getColumnName() {
61 | return columnName;
62 | }
63 |
64 | public void setColumnName(String columnName) {
65 | this.columnName = columnName;
66 | }
67 |
68 | public Long getOrdinalPosition() {
69 | return ordinalPosition;
70 | }
71 |
72 | public void setOrdinalPosition(Long ordinalPosition) {
73 | this.ordinalPosition = ordinalPosition;
74 | }
75 |
76 | public String getColumnDefault() {
77 | return columnDefault;
78 | }
79 |
80 | public void setColumnDefault(String columnDefault) {
81 | this.columnDefault = columnDefault;
82 | }
83 |
84 | public String getIsNullable() {
85 | return isNullable;
86 | }
87 |
88 | public void setIsNullable(String isNullable) {
89 | this.isNullable = isNullable;
90 | }
91 |
92 | public String getDataType() {
93 | return dataType;
94 | }
95 |
96 | public void setDataType(String dataType) {
97 | this.dataType = dataType;
98 | }
99 |
100 | public Long getCharacterMaximumLength() {
101 | return characterMaximumLength;
102 | }
103 |
104 | public void setCharacterMaximumLength(Long characterMaximumLength) {
105 | this.characterMaximumLength = characterMaximumLength;
106 | }
107 |
108 | public Long getCharacterOctetLength() {
109 | return characterOctetLength;
110 | }
111 |
112 | public void setCharacterOctetLength(Long characterOctetLength) {
113 | this.characterOctetLength = characterOctetLength;
114 | }
115 |
116 | public Long getNumberPrecision() {
117 | return numberPrecision;
118 | }
119 |
120 | public void setNumberPrecision(Long numberPrecision) {
121 | this.numberPrecision = numberPrecision;
122 | }
123 |
124 | public Long getNumberScale() {
125 | return numberScale;
126 | }
127 |
128 | public void setNumberScale(Long numberScale) {
129 | this.numberScale = numberScale;
130 | }
131 |
132 | public String getCharacterSetName() {
133 | return characterSetName;
134 | }
135 |
136 | public void setCharacterSetName(String characterSetName) {
137 | this.characterSetName = characterSetName;
138 | }
139 |
140 | public String getCollationName() {
141 | return collationName;
142 | }
143 |
144 | public void setCollationName(String collationName) {
145 | this.collationName = collationName;
146 | }
147 |
148 | public String getColumnType() {
149 | return columnType;
150 | }
151 |
152 | public void setColumnType(String columnType) {
153 | this.columnType = columnType;
154 | }
155 |
156 | public String getColumnKey() {
157 | return columnKey;
158 | }
159 |
160 | public void setColumnKey(String columnKey) {
161 | this.columnKey = columnKey;
162 | }
163 |
164 | public String getExtra() {
165 | return extra;
166 | }
167 |
168 | public void setExtra(String extra) {
169 | this.extra = extra;
170 | }
171 |
172 | public String getPrivileges() {
173 | return privileges;
174 | }
175 |
176 | public void setPrivileges(String privileges) {
177 | this.privileges = privileges;
178 | }
179 |
180 | public String getColumnComment() {
181 | return columnComment;
182 | }
183 |
184 | public void setColumnComment(String columnComment) {
185 | this.columnComment = columnComment;
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/entity/mysql/Schemata.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.entity.mysql;
2 |
3 |
4 |
5 | /**
6 | * Created by Beldon.
7 | * Copyright (c) 2016/10/13, All Rights Reserved.
8 | * http://beldon.me
9 | */
10 | public class Schemata {
11 | private String catalogName;
12 | private String schemaName;
13 | private String defaultCharacterSetName;
14 | private String defaultCollationName;
15 | private String sqlPath;
16 |
17 | public String getCatalogName() {
18 | return catalogName;
19 | }
20 |
21 | public void setCatalogName(String catalogName) {
22 | this.catalogName = catalogName;
23 | }
24 |
25 | public String getSchemaName() {
26 | return schemaName;
27 | }
28 |
29 | public void setSchemaName(String schemaName) {
30 | this.schemaName = schemaName;
31 | }
32 |
33 | public String getDefaultCharacterSetName() {
34 | return defaultCharacterSetName;
35 | }
36 |
37 | public void setDefaultCharacterSetName(String defaultCharacterSetName) {
38 | this.defaultCharacterSetName = defaultCharacterSetName;
39 | }
40 |
41 | public String getDefaultCollationName() {
42 | return defaultCollationName;
43 | }
44 |
45 | public void setDefaultCollationName(String defaultCollationName) {
46 | this.defaultCollationName = defaultCollationName;
47 | }
48 |
49 | public String getSqlPath() {
50 | return sqlPath;
51 | }
52 |
53 | public void setSqlPath(String sqlPath) {
54 | this.sqlPath = sqlPath;
55 | }
56 |
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/entity/mysql/Tables.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.entity.mysql;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Created by Beldon.
7 | * Copyright (c) 2016/10/14, All Rights Reserved.
8 | * http://beldon.me
9 | */
10 | public class Tables {
11 | private String tableCatalog;
12 | private String tableSchema;
13 | /**
14 | * 表名称
15 | */
16 | private String tableName;
17 | private String tableType;
18 | private String engine;
19 | private Long version;
20 | private String rowFormat;
21 | private Long tableRows;
22 | private Long avgRowLength;
23 | private Long dataLength;
24 | private Long maxDataLength;
25 | private Long indexLength;
26 | private Long dataFree;
27 | private Long autoIncrement;
28 | private Date createTime;
29 | private Date updateTime;
30 | private Date checkTime;
31 | private String tableCollation;
32 | private Long checksum;
33 | private String createOptions;
34 | /**
35 | * 表注释
36 | */
37 | private String tableComment;
38 |
39 | public String getTableCatalog() {
40 | return tableCatalog;
41 | }
42 |
43 | public void setTableCatalog(String tableCatalog) {
44 | this.tableCatalog = tableCatalog;
45 | }
46 |
47 | public String getTableSchema() {
48 | return tableSchema;
49 | }
50 |
51 | public void setTableSchema(String tableSchema) {
52 | this.tableSchema = tableSchema;
53 | }
54 |
55 | public String getTableName() {
56 | return tableName;
57 | }
58 |
59 | public void setTableName(String tableName) {
60 | this.tableName = tableName;
61 | }
62 |
63 | public String getTableType() {
64 | return tableType;
65 | }
66 |
67 | public void setTableType(String tableType) {
68 | this.tableType = tableType;
69 | }
70 |
71 | public String getEngine() {
72 | return engine;
73 | }
74 |
75 | public void setEngine(String engine) {
76 | this.engine = engine;
77 | }
78 |
79 | public Long getVersion() {
80 | return version;
81 | }
82 |
83 | public void setVersion(Long version) {
84 | this.version = version;
85 | }
86 |
87 | public String getRowFormat() {
88 | return rowFormat;
89 | }
90 |
91 | public void setRowFormat(String rowFormat) {
92 | this.rowFormat = rowFormat;
93 | }
94 |
95 | public Long getTableRows() {
96 | return tableRows;
97 | }
98 |
99 | public void setTableRows(Long tableRows) {
100 | this.tableRows = tableRows;
101 | }
102 |
103 | public Long getAvgRowLength() {
104 | return avgRowLength;
105 | }
106 |
107 | public void setAvgRowLength(Long avgRowLength) {
108 | this.avgRowLength = avgRowLength;
109 | }
110 |
111 | public Long getDataLength() {
112 | return dataLength;
113 | }
114 |
115 | public void setDataLength(Long dataLength) {
116 | this.dataLength = dataLength;
117 | }
118 |
119 | public Long getMaxDataLength() {
120 | return maxDataLength;
121 | }
122 |
123 | public void setMaxDataLength(Long maxDataLength) {
124 | this.maxDataLength = maxDataLength;
125 | }
126 |
127 | public Long getIndexLength() {
128 | return indexLength;
129 | }
130 |
131 | public void setIndexLength(Long indexLength) {
132 | this.indexLength = indexLength;
133 | }
134 |
135 | public Long getDataFree() {
136 | return dataFree;
137 | }
138 |
139 | public void setDataFree(Long dataFree) {
140 | this.dataFree = dataFree;
141 | }
142 |
143 | public Long getAutoIncrement() {
144 | return autoIncrement;
145 | }
146 |
147 | public void setAutoIncrement(Long autoIncrement) {
148 | this.autoIncrement = autoIncrement;
149 | }
150 |
151 | public Date getCreateTime() {
152 | return createTime;
153 | }
154 |
155 | public void setCreateTime(Date createTime) {
156 | this.createTime = createTime;
157 | }
158 |
159 | public Date getUpdateTime() {
160 | return updateTime;
161 | }
162 |
163 | public void setUpdateTime(Date updateTime) {
164 | this.updateTime = updateTime;
165 | }
166 |
167 | public Date getCheckTime() {
168 | return checkTime;
169 | }
170 |
171 | public void setCheckTime(Date checkTime) {
172 | this.checkTime = checkTime;
173 | }
174 |
175 | public String getTableCollation() {
176 | return tableCollation;
177 | }
178 |
179 | public void setTableCollation(String tableCollation) {
180 | this.tableCollation = tableCollation;
181 | }
182 |
183 | public Long getChecksum() {
184 | return checksum;
185 | }
186 |
187 | public void setChecksum(Long checksum) {
188 | this.checksum = checksum;
189 | }
190 |
191 | public String getCreateOptions() {
192 | return createOptions;
193 | }
194 |
195 | public void setCreateOptions(String createOptions) {
196 | this.createOptions = createOptions;
197 | }
198 |
199 | public String getTableComment() {
200 | return tableComment;
201 | }
202 |
203 | public void setTableComment(String tableComment) {
204 | this.tableComment = tableComment;
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/entity/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Beldon.
3 | * Copyright (c) 2017/5/26, All Rights Reserved.
4 | * http://beldon.me
5 | */
6 | package me.beldon.module.database.entity;
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Beldon.
3 | * Copyright (c) 2017/5/26, All Rights Reserved.
4 | * http://beldon.me
5 | */
6 | package me.beldon.module.database;
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/service/IDatabaseService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.service;
2 |
3 | import me.beldon.module.generate.domain.ConnectDb;
4 | import org.springframework.jdbc.core.JdbcTemplate;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2017/5/26, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | public interface IDatabaseService {
12 |
13 | void switchConnect(ConnectDb connectDb);
14 |
15 | JdbcTemplate currentJdbcTemplate();
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/service/IMySqlService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.service;
2 |
3 |
4 | import me.beldon.module.database.entity.mysql.Columns;
5 | import me.beldon.module.database.entity.mysql.Schemata;
6 | import me.beldon.module.database.entity.mysql.Tables;
7 | import org.springframework.jdbc.core.JdbcTemplate;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * 数据库辅助类
13 | * Created by Beldon.
14 | * Copyright (c) 2016/10/14, All Rights Reserved.
15 | * http://beldon.me
16 | */
17 | public interface IMySqlService {
18 | /**
19 | * 获取所有Schemata
20 | *
21 | * @return
22 | */
23 | List getAllSchemata();
24 |
25 | /**
26 | * 获取指定schemata所有Table
27 | *
28 | * @param schemata 指定schemata
29 | * @return
30 | */
31 | List getAllSchemataTables(String schemata);
32 |
33 | /**
34 | * 获取指定schemata 所有 columns
35 | *
36 | * @param schemata 指定schemata
37 | * @return
38 | */
39 | List getAllSchemataColumns(String schemata);
40 |
41 | /**
42 | * 获取指定schemata下指定指定table 所有 columns
43 | *
44 | * @param schemata 指定schemata
45 | * @param table 指定table
46 | * @return
47 | */
48 | List getAllSchemataTableColumns(String schemata, String table);
49 |
50 | /**
51 | * 获取指定table下指定指定table 所有 columns
52 | *
53 | * @param table 指定table
54 | * @return
55 | */
56 | List getAllSchemataTableColumns(Tables table);
57 |
58 | void switchJdbcTemplate(JdbcTemplate jdbcTemplate);
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/service/IMySqlTypeService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.service;
2 |
3 |
4 | import me.beldon.module.database.bean.Type;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2016/10/18, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | public interface IMySqlTypeService {
12 | Type getType(String mysqlType);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/service/impl/DatabaseService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.service.impl;
2 |
3 | import me.beldon.module.database.service.IDatabaseService;
4 | import me.beldon.module.database.service.IMySqlService;
5 | import me.beldon.module.generate.domain.ConnectDb;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.jdbc.core.JdbcTemplate;
8 | import org.springframework.jdbc.datasource.DriverManagerDataSource;
9 | import org.springframework.stereotype.Service;
10 |
11 | /**
12 | * Created by Beldon.
13 | * Copyright (c) 2017/5/26, All Rights Reserved.
14 | * http://beldon.me
15 | */
16 | @Service
17 | public class DatabaseService implements IDatabaseService {
18 |
19 | private JdbcTemplate jdbcTemplate;
20 |
21 | @Autowired
22 | private IMySqlService mySqlService;
23 |
24 | @Override
25 | public void switchConnect(ConnectDb connectDb) {
26 | String url = "jdbc:mysql://" + connectDb.getHost() + ":" + connectDb.getPort() + "/information_schema";
27 | DriverManagerDataSource dataSource = new DriverManagerDataSource();
28 | dataSource.setDriverClassName("com.mysql.jdbc.Driver");
29 | dataSource.setUrl(url);
30 | dataSource.setUsername(connectDb.getUser());
31 | dataSource.setPassword(connectDb.getPass());
32 | jdbcTemplate = new JdbcTemplate(dataSource);
33 | mySqlService.switchJdbcTemplate(jdbcTemplate);
34 | }
35 |
36 | @Override
37 | public JdbcTemplate currentJdbcTemplate() {
38 | return jdbcTemplate;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/service/impl/MySqlService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.service.impl;
2 |
3 | import me.beldon.module.database.entity.mysql.Columns;
4 | import me.beldon.module.database.entity.mysql.Schemata;
5 | import me.beldon.module.database.entity.mysql.Tables;
6 | import me.beldon.module.database.service.IMySqlService;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.jdbc.core.BeanPropertyRowMapper;
9 | import org.springframework.jdbc.core.JdbcTemplate;
10 | import org.springframework.stereotype.Service;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * 数据库辅助类
16 | * Created by Beldon.
17 | * Copyright (c) 2016/10/14, All Rights Reserved.
18 | * http://beldon.me
19 | */
20 | @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
21 | @Service
22 | public class MySqlService implements IMySqlService {
23 |
24 | private JdbcTemplate jdbcTemplate;
25 |
26 | public List getAllSchemata() {
27 | return jdbcTemplate.query("select * from SCHEMATA;", BeanPropertyRowMapper.newInstance(Schemata.class));
28 | }
29 |
30 | public List getAllSchemataTables(String schemata) {
31 | return jdbcTemplate.query("select * from TABLES WHERE TABLE_SCHEMA = ?;", new Object[]{schemata}, BeanPropertyRowMapper.newInstance(Tables.class));
32 | }
33 |
34 | public List getAllSchemataColumns(String schemata) {
35 | return jdbcTemplate.query("select * from `COLUMNS` WHERE TABLE_SCHEMA = ?;", new Object[]{schemata}, BeanPropertyRowMapper.newInstance(Columns.class));
36 | }
37 |
38 | public List getAllSchemataTableColumns(String schemata, String table) {
39 | return jdbcTemplate.query("select * from `COLUMNS` WHERE TABLE_SCHEMA = ? AND `TABLE_NAME` = ?;", new Object[]{schemata, table}, BeanPropertyRowMapper.newInstance(Columns.class));
40 | }
41 |
42 | public List getAllSchemataTableColumns(Tables table) {
43 | return getAllSchemataTableColumns(table.getTableSchema(),table.getTableName());
44 | }
45 |
46 | @Override
47 | public void switchJdbcTemplate(JdbcTemplate jdbcTemplate) {
48 | this.jdbcTemplate = jdbcTemplate;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/database/service/impl/MySqlTypeService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.database.service.impl;
2 |
3 | import me.beldon.module.database.bean.Type;
4 | import me.beldon.module.database.service.IMySqlTypeService;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.util.StringUtils;
7 |
8 | import javax.annotation.PostConstruct;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * Created by Beldon.
14 | * Copyright (c) 2016/10/18, All Rights Reserved.
15 | * http://beldon.me
16 | */
17 | @Service
18 | public class MySqlTypeService implements IMySqlTypeService {
19 | private Map types = new HashMap();
20 |
21 | @PostConstruct
22 | public void init() {
23 | add(new Type("smallint", "INTEGER", "Integer", "java.lang.Integer"));
24 | add(new Type("mediumint", "INTEGER", "Integer", "java.lang.Integer"));
25 | add(new Type("int", "BIGINT", "Long", "java.lang.Long"));
26 | add(new Type("integer", "INTEGER", "Integer", "java.lang.Integer"));
27 | add(new Type("bigint", "BIGINT", "Long", "java.lang.Long"));
28 | add(new Type("varchar", "VARCHAR", "String", "java.lang.String"));
29 | add(new Type("text", "VARCHAR", "String", "java.lang.String"));
30 | add(new Type("datetime", "TIMESTAMP", "Date", "java.util.Date"));
31 | add(new Type("date", "TIMESTAMP", "Date", "java.util.Date"));
32 | add(new Type("tinyint", "INTEGER", "Integer", "java.lang.Integer"));
33 | add(new Type("bit", "BIT", "Boolean", "java.lang.Boolean"));
34 | add(new Type("longtext", "VARCHAR", "String", "java.lang.String"));
35 | }
36 |
37 | private void add(Type type) {
38 | types.put(type.getMysqlType(), type);
39 | }
40 |
41 | public Type getType(String mysqlType) {
42 | if (StringUtils.hasText(mysqlType) && types.containsKey(mysqlType)) {
43 | return types.get(mysqlType);
44 | }
45 | return new Type();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/demo/User.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.demo;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | /**
9 | * Created by Beldon.
10 | * Copyright (c) 2017/5/21, All Rights Reserved.
11 | * http://beldon.me
12 | */
13 | @Entity
14 | public class User {
15 |
16 | @Id
17 | @GeneratedValue
18 | private Long id;
19 |
20 | @Column(nullable = false)
21 | private String name;
22 |
23 | @Column(nullable = false)
24 | private Integer age;
25 |
26 | public Long getId() {
27 | return id;
28 | }
29 |
30 | public void setId(Long id) {
31 | this.id = id;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public Integer getAge() {
43 | return age;
44 | }
45 |
46 | public void setAge(Integer age) {
47 | this.age = age;
48 | }
49 | }
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/dao/ConnectDbRepository.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.dao;
2 |
3 | import me.beldon.module.generate.domain.ConnectDb;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | /**
8 | * Created by Beldon.
9 | * Copyright (c) 2017/5/21, All Rights Reserved.
10 | * http://beldon.me
11 | */
12 | @Repository
13 | public interface ConnectDbRepository extends JpaRepository {
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/domain/ConnectDb.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.domain;
2 |
3 | import org.hibernate.annotations.GenericGenerator;
4 |
5 | import javax.persistence.*;
6 |
7 | /**
8 | * Created by Beldon.
9 | * Copyright (c) 2017/5/21, All Rights Reserved.
10 | * http://beldon.me
11 | */
12 | @Entity
13 | @Table(name = "connect_db")
14 | public class ConnectDb {
15 | @GenericGenerator(name = "uuidGenerator", strategy = "uuid")
16 | @Id
17 | @GeneratedValue(generator = "uuidGenerator")
18 | private String id;
19 |
20 | /**
21 | * 保存名称
22 | */
23 | private String name;
24 |
25 | /**
26 | * 数据库类型
27 | */
28 | private String type;
29 |
30 | /**
31 | * 主机
32 | */
33 | private String host;
34 |
35 | /**
36 | * 数据库端口
37 | */
38 | private String port;
39 |
40 | /**
41 | * 数据库用户
42 | */
43 | private String user;
44 |
45 | /**
46 | * 数据密码
47 | */
48 | private String pass;
49 |
50 | /**
51 | * 数据库schema
52 | */
53 | private String schema;
54 |
55 | /**
56 | * 连接编码
57 | */
58 | private String encoding;
59 |
60 | public String getId() {
61 | return id;
62 | }
63 |
64 | public void setId(String id) {
65 | this.id = id;
66 | }
67 |
68 | public String getName() {
69 | return name;
70 | }
71 |
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | public String getType() {
77 | return type;
78 | }
79 |
80 | public void setType(String type) {
81 | this.type = type;
82 | }
83 |
84 | public String getHost() {
85 | return host;
86 | }
87 |
88 | public void setHost(String host) {
89 | this.host = host;
90 | }
91 |
92 | public String getPort() {
93 | return port;
94 | }
95 |
96 | public void setPort(String port) {
97 | this.port = port;
98 | }
99 |
100 | public String getUser() {
101 | return user;
102 | }
103 |
104 | public void setUser(String user) {
105 | this.user = user;
106 | }
107 |
108 | public String getPass() {
109 | return pass;
110 | }
111 |
112 | public void setPass(String pass) {
113 | this.pass = pass;
114 | }
115 |
116 | public String getSchema() {
117 | return schema;
118 | }
119 |
120 | public void setSchema(String schema) {
121 | this.schema = schema;
122 | }
123 |
124 | public String getEncoding() {
125 | return encoding;
126 | }
127 |
128 | public void setEncoding(String encoding) {
129 | this.encoding = encoding;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Beldon.
3 | * Copyright (c) 2017/5/21, All Rights Reserved.
4 | * http://beldon.me
5 | */
6 | package me.beldon.module.generate;
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/service/IConnectDbService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.service;
2 |
3 | import me.beldon.module.generate.domain.ConnectDb;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by Beldon.
9 | * Copyright (c) 2017/5/21, All Rights Reserved.
10 | * http://beldon.me
11 | */
12 | public interface IConnectDbService {
13 |
14 | void save(ConnectDb connectDb);
15 |
16 |
17 | List findAll();
18 |
19 | void deleteById(String id);
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/service/IMySqlGenerateService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.service;
2 |
3 |
4 | import me.beldon.module.database.bean.GenerateData;
5 |
6 | /**
7 | * 代码生成Service
8 | * Created by Beldon.
9 | * Copyright (c) 2016/10/14, All Rights Reserved.
10 | * http://beldon.me
11 | */
12 | public interface IMySqlGenerateService {
13 |
14 | /**
15 | * 生成代码
16 | *
17 | * @param generateData 生成的数据信息
18 | * @throws Exception
19 | */
20 | void generate(GenerateData generateData) throws Exception;
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/service/impl/ConnectDbService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.service.impl;
2 |
3 | import me.beldon.module.generate.dao.ConnectDbRepository;
4 | import me.beldon.module.generate.domain.ConnectDb;
5 | import me.beldon.module.generate.service.IConnectDbService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by Beldon.
13 | * Copyright (c) 2017/5/21, All Rights Reserved.
14 | * http://beldon.me
15 | */
16 | @Service
17 | public class ConnectDbService implements IConnectDbService {
18 |
19 | @Autowired
20 | private ConnectDbRepository connectDbRepository;
21 |
22 | @Override
23 | public void save(ConnectDb connectDb) {
24 | connectDbRepository.save(connectDb);
25 | }
26 |
27 | @Override
28 | public List findAll() {
29 | return connectDbRepository.findAll();
30 | }
31 |
32 | @Override
33 | public void deleteById(String id) {
34 | connectDbRepository.delete(id);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/service/impl/MySqlGenerateService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.service.impl;
2 |
3 |
4 | import freemarker.cache.StringTemplateLoader;
5 | import freemarker.template.Configuration;
6 | import freemarker.template.Template;
7 | import freemarker.template.TemplateException;
8 | import me.beldon.module.database.bean.ColumnData;
9 | import me.beldon.module.database.bean.GenerateData;
10 | import me.beldon.module.database.bean.Type;
11 | import me.beldon.module.database.entity.mysql.Columns;
12 | import me.beldon.module.database.service.IMySqlService;
13 | import me.beldon.module.database.service.IMySqlTypeService;
14 | import me.beldon.module.generate.service.IMySqlGenerateService;
15 | import me.beldon.module.template.bean.TemplateDetails;
16 | import me.beldon.module.template.bean.TemplateFtl;
17 | import me.beldon.util.SSUtils;
18 | import org.springframework.beans.factory.annotation.Autowired;
19 | import org.springframework.stereotype.Service;
20 | import org.springframework.util.StringUtils;
21 |
22 | import java.io.File;
23 | import java.io.FileWriter;
24 | import java.io.IOException;
25 | import java.io.StringWriter;
26 | import java.util.*;
27 |
28 |
29 | /**
30 | * 代码生成Service
31 | * Created by Beldon.
32 | * Copyright (c) 2016/10/14, All Rights Reserved.
33 | * http://beldon.me
34 | */
35 | @SuppressWarnings("Duplicates")
36 | @Service
37 | public class MySqlGenerateService implements IMySqlGenerateService {
38 |
39 | @Autowired
40 | private freemarker.template.Configuration configuration;
41 | @Autowired
42 | private IMySqlService mySqlService;
43 | @Autowired
44 | private IMySqlTypeService mySqlTypeService;
45 |
46 |
47 | @Override
48 | public void generate(GenerateData generateData) throws Exception {
49 | List columns = mySqlService.getAllSchemataTableColumns(generateData.getTable());
50 | String basePath = generateData.getBasePath(); //基本路径
51 | TemplateFtl templateFtl = generateData.getTemplate();
52 |
53 | TemplateDetails templateDetails = generateData.getTemplateDetails();
54 |
55 | String templatePath = "/templates/" + templateDetails.getPath() + File.separator + templateFtl.getFileName();
56 | String dirPath; //生成的文件目录
57 | String basePackage = generateData.getBasePackage();
58 | String pk = "";
59 | if ("java".equals(generateData.getTemplate().getType())) {
60 | pk = basePackage + templateFtl.getTargetPackage();
61 | dirPath = basePath + templateFtl.getBasePath() + File.separator + pk.replaceAll("\\.", "\\\\") + "\\";
62 | } else {
63 | dirPath = basePath + templateFtl.getTargetPath();
64 | }
65 |
66 | File dir = new File(dirPath);
67 | if (!dir.exists()) {
68 | dir.mkdirs();
69 | }
70 |
71 | String domainName = generateData.getDomainName();
72 | List columnDatas = new ArrayList<>();
73 |
74 | ColumnData primaryData = new ColumnData();
75 | Set importType = new LinkedHashSet<>();
76 | for (Columns column : columns) {
77 | ColumnData columnData = new ColumnData();
78 | columnData.setName(SSUtils.underlineToCamel2(column.getColumnName()));
79 | columnData.setColumn(column);
80 | Type type = mySqlTypeService.getType(column.getDataType());
81 | columnData.setType(type);
82 | columnDatas.add(columnData);
83 | if (type != null && StringUtils.hasText(type.getJavaFullType())) {
84 | String javaFullType = type.getJavaFullType();
85 | if (StringUtils.hasText(javaFullType) && !javaFullType.contains("java.lang")) {
86 | importType.add(javaFullType);
87 | }
88 | }
89 |
90 | if ("PRI".equals(column.getColumnKey())) {
91 | primaryData = columnData;
92 | }
93 |
94 | }
95 | //组织数据
96 | Map data = new HashMap<>();
97 | data.put("package", pk);
98 | data.put("table", generateData.getTable());
99 | data.put("domainName", domainName); //实体类名称
100 | data.put("data", generateData); //生成的数据信息
101 | data.put("url", generateData.getUrl()); //生成的数据信息
102 | data.put("columnDatas", columnDatas); //所有字段信息
103 | data.put("importType", importType); //所需要导入的包
104 | data.put("primaryData", primaryData); //主键
105 | data.put("templateFtl", templateFtl); //模板信息
106 |
107 | templateFtl.setTargetFileName(replace(templateFtl.getTargetFileName(), data));
108 | data.put("className", templateFtl.getTargetFileName().replaceAll("[.][^.]+$", "")); //生成的类的名称
109 |
110 | String filePath = dirPath + "" + templateFtl.getTargetFileName();
111 | FileWriter fileWriter = new FileWriter(new File(filePath));
112 | Template template = configuration.getTemplate(templatePath);
113 | template.process(data, fileWriter);
114 | fileWriter.flush();
115 | fileWriter.close();
116 | }
117 |
118 | /**
119 | * freemarker内容转换
120 | *
121 | * @param templateContent 文本内容
122 | * @param data data内容
123 | * @return
124 | */
125 | private String replace(String templateContent, Map data) {
126 | if (StringUtils.isEmpty(templateContent)) {
127 | return "";
128 | }
129 | Configuration cfg = new Configuration();
130 | StringTemplateLoader stringLoader = new StringTemplateLoader();
131 | stringLoader.putTemplate("templateContent", templateContent);
132 | cfg.setTemplateLoader(stringLoader);
133 | try {
134 | Template template = cfg.getTemplate("templateContent", "utf-8");
135 |
136 | StringWriter writer = new StringWriter();
137 | try {
138 | template.process(data, writer);
139 | return writer.toString();
140 | } catch (TemplateException e) {
141 | e.printStackTrace();
142 | }
143 | } catch (IOException e) {
144 | e.printStackTrace();
145 | }
146 | return templateContent;
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/ui/GenerateController.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.ui;
2 |
3 | import de.felixroske.jfxsupport.FXMLController;
4 | import javafx.collections.FXCollections;
5 | import javafx.collections.ObservableList;
6 | import javafx.event.ActionEvent;
7 | import javafx.fxml.FXML;
8 | import javafx.fxml.Initializable;
9 | import javafx.geometry.Pos;
10 | import javafx.scene.control.*;
11 | import javafx.scene.control.cell.TextFieldTreeCell;
12 | import javafx.scene.image.ImageView;
13 | import javafx.scene.input.MouseEvent;
14 | import javafx.stage.DirectoryChooser;
15 | import javafx.stage.Stage;
16 | import javafx.util.Callback;
17 | import me.beldon.GenerateApplication;
18 | import me.beldon.module.database.bean.GenerateData;
19 | import me.beldon.module.database.entity.mysql.Columns;
20 | import me.beldon.module.database.entity.mysql.Tables;
21 | import me.beldon.module.database.service.IDatabaseService;
22 | import me.beldon.module.database.service.IMySqlService;
23 | import me.beldon.module.generate.domain.ConnectDb;
24 | import me.beldon.module.generate.service.IConnectDbService;
25 | import me.beldon.module.generate.service.IMySqlGenerateService;
26 | import me.beldon.module.template.bean.TemplateDetails;
27 | import me.beldon.module.template.bean.TemplateFtl;
28 | import me.beldon.module.template.service.ITemplateService;
29 | import me.beldon.module.window.service.IWindowService;
30 | import me.beldon.util.SSUtils;
31 | import org.controlsfx.control.Notifications;
32 | import org.springframework.beans.BeanUtils;
33 | import org.springframework.beans.factory.annotation.Autowired;
34 | import org.springframework.util.StringUtils;
35 |
36 | import java.io.File;
37 | import java.net.URL;
38 | import java.util.List;
39 | import java.util.ResourceBundle;
40 |
41 | /**
42 | * Created by Beldon.
43 | * Copyright (c) 2017/5/21, All Rights Reserved.
44 | * http://beldon.me
45 | */
46 | @FXMLController
47 | public class GenerateController implements Initializable {
48 | public TreeView leftDBTree;
49 | public TextField tableNameField;
50 | public TextField domainObjectNameField;
51 | public TextField projectFolderField;
52 | public TextField authorTextFile;
53 | public TextField targetPackage;
54 | public TextField modelTargetPackage;
55 | public TextField daoTargetPackage;
56 | public TextField daoPrefix;
57 | public TextField daoSuffix;
58 | public TextField serviceTargetPackage;
59 | public TextField servicePrefix;
60 | public TextField serviceSuffix;
61 | public TextField urlTextFile;
62 | public CheckBox generatePage;
63 | public CheckBox generatePojo;
64 | public CheckBox generateDao;
65 | public CheckBox generateService;
66 | public ChoiceBox templateChoiceBox;
67 | @FXML
68 | private Label connectionLabel;
69 | @FXML
70 | private Label configsLabel;
71 |
72 | private Tables currentTables; //当前Tables
73 |
74 | @Autowired
75 | private IWindowService windowService;
76 |
77 | @Autowired
78 | private IConnectDbService connectDbService;
79 |
80 | @Autowired
81 | private IMySqlService mySqlService;
82 | @Autowired
83 | private IDatabaseService databaseService;
84 |
85 | @Autowired
86 | private IMySqlGenerateService mySqlGenerateService;
87 |
88 | @Autowired
89 | private ITemplateService templateService;
90 |
91 | @Override
92 | public void initialize(URL location, ResourceBundle resources) {
93 | ImageView dbImage = new ImageView("/icons/computer.png");
94 | dbImage.setFitHeight(40);
95 | dbImage.setFitWidth(40);
96 | connectionLabel.setGraphic(dbImage);
97 | // ImageView configImage = new ImageView("/icons/config-list.png");
98 | // configImage.setFitHeight(40);
99 | // configImage.setFitWidth(40);
100 | // configsLabel.setGraphic(configImage);
101 |
102 | Stage stage = GenerateApplication.getStage();
103 | stage.setMaximized(true);
104 |
105 | //
106 | initDBTree();
107 |
108 | loadTemplate();
109 | }
110 |
111 | private void initDBTree() {
112 | leftDBTree.setShowRoot(false);
113 | leftDBTree.setRoot(new TreeItem<>());
114 | Callback, TreeCell> defaultCellFactory = TextFieldTreeCell.forTreeView();
115 | leftDBTree.setCellFactory((TreeView tv) -> {
116 | TreeCell cell = defaultCellFactory.call(tv);
117 | cell.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
118 | int level = leftDBTree.getTreeItemLevel(cell.getTreeItem());
119 | TreeCell treeCell = (TreeCell) event.getSource();
120 | TreeItem treeItem = treeCell.getTreeItem();
121 | if (level == 1) {
122 | final ContextMenu contextMenu = new ContextMenu();
123 | MenuItem item1 = new MenuItem("关闭连接");
124 | item1.setOnAction(event1 -> treeItem.getChildren().clear()); //关闭链接
125 | MenuItem item2 = new MenuItem("删除连接");
126 | item2.setOnAction(event1 -> {
127 | System.out.println("删除连接");
128 | ConnectDb connectDb = (ConnectDb) treeItem.getGraphic().getUserData();
129 | if (connectDb != null && StringUtils.hasText(connectDb.getId())) {
130 | connectDbService.deleteById(connectDb.getId());
131 | loadLeftDBTree();
132 | }
133 | });
134 | contextMenu.getItems().addAll(item1, item2);
135 | cell.setContextMenu(contextMenu);
136 | }
137 | if (event.getClickCount() == 2) { //双击
138 | if (treeItem == null) return;
139 | treeItem.setExpanded(true);
140 | if (level == 1) {
141 | ConnectDb connectDb = (ConnectDb) treeItem.getGraphic().getUserData(); //load表数据
142 | databaseService.switchConnect(connectDb); //切換
143 | List tables = mySqlService.getAllSchemataTables(connectDb.getSchema());
144 | ObservableList> children = cell.getTreeItem().getChildren();
145 | children.clear();
146 | for (Tables table : tables) {
147 | TreeItem newTreeItem = new TreeItem<>();
148 | ImageView imageView = new ImageView("icons/table.png");
149 | imageView.setFitHeight(16);
150 | imageView.setFitWidth(16);
151 | newTreeItem.setGraphic(imageView);
152 | newTreeItem.setValue(table.getTableName());
153 | newTreeItem.getGraphic().setUserData(table);
154 | children.add(newTreeItem);
155 | }
156 | } else if (level == 2) { // left DB tree level3
157 | String tableName = treeCell.getTreeItem().getValue();
158 | tableNameField.setText(tableName);
159 | domainObjectNameField.setText(SSUtils.underlineToCamel(tableName)); //实体类名称
160 | ConnectDb connectDb = (ConnectDb) treeItem.getParent().getGraphic().getUserData();
161 | databaseService.switchConnect(connectDb); //切換
162 | currentTables = (Tables) treeItem.getGraphic().getUserData();
163 | // List columns = mySqlService.getAllSchemataTableColumns(connectDb.getSchema(), tableName);
164 | }
165 | }
166 | });
167 | return cell;
168 | });
169 |
170 | loadLeftDBTree();
171 | }
172 |
173 | /**
174 | * Connect点击事件
175 | *
176 | * @param mouseEvent
177 | */
178 | public void connection(MouseEvent mouseEvent) {
179 | windowService.showDialog(NewConnectionView.class, "新建连接", 400, 500);
180 | }
181 |
182 | /**
183 | * 加载数据
184 | */
185 | public void loadLeftDBTree() {
186 | TreeItem rootTreeItem = leftDBTree.getRoot();
187 | rootTreeItem.getChildren().clear();
188 | List list = connectDbService.findAll();
189 | if (list != null) {
190 | for (ConnectDb connectDb : list) {
191 | TreeItem treeItem = new TreeItem<>();
192 | treeItem.setValue(connectDb.getName());
193 | ImageView dbImage = new ImageView("icons/computer.png");
194 | dbImage.setFitHeight(16);
195 | dbImage.setFitWidth(16);
196 | dbImage.setUserData(connectDb);
197 | treeItem.setGraphic(dbImage);
198 | rootTreeItem.getChildren().add(treeItem);
199 | }
200 | }
201 | }
202 |
203 | public void chooseProjectFolder(ActionEvent actionEvent) {
204 | DirectoryChooser directoryChooser = new DirectoryChooser();
205 | File selectedFolder = directoryChooser.showDialog(GenerateApplication.getStage());
206 | if (selectedFolder != null) {
207 | projectFolderField.setText(selectedFolder.getAbsolutePath());
208 | }
209 | }
210 |
211 | /**
212 | * 代码生成
213 | * @param actionEvent
214 | */
215 | public void generateCode(ActionEvent actionEvent) {
216 | if (currentTables == null) {
217 | Notifications.create().title("生成提示").text("请选择要生成的数据表").position(Pos.BASELINE_CENTER).showWarning();
218 | return;
219 | }
220 |
221 | String basePath = projectFolderField.getText();
222 | if (StringUtils.isEmpty(basePath)) {
223 | Notifications.create().title("生成提示").text("请选择项目路径").position(Pos.BASELINE_CENTER).showWarning();
224 | return;
225 | }
226 |
227 | GenerateData generateData = new GenerateData();
228 | generateData.setAuthor(authorTextFile.getText());
229 | generateData.setUrl(urlTextFile.getText());
230 |
231 | generateData.setBasePath(basePath);
232 | generateData.setBasePackage(targetPackage.getText());
233 | generateData.setDomainName(domainObjectNameField.getText());
234 |
235 | try {
236 | TemplateDetails templateDetails = (TemplateDetails) templateChoiceBox.getValue();
237 | if (templateDetails == null) {
238 | return;
239 | }
240 |
241 | generateData.setTemplateDetails(templateDetails);
242 | generateData.setTable(currentTables);
243 |
244 | List templateFtls = templateDetails.getTemplates();
245 | for (TemplateFtl templateFtl : templateFtls) {
246 | TemplateFtl temp = new TemplateFtl();
247 | BeanUtils.copyProperties(templateFtl,temp);
248 | generateData.setTemplate(temp);
249 | mySqlGenerateService.generate(generateData);
250 | }
251 |
252 | Notifications.create().title("生成提示").text("生成成功!").position(Pos.BASELINE_CENTER).showInformation();
253 | } catch (Exception e) {
254 | e.printStackTrace();
255 | }
256 | }
257 |
258 | /**
259 | * 刷新模板
260 | * @param actionEvent
261 | */
262 | public void refreshTemplate(ActionEvent actionEvent) {
263 | loadTemplate();
264 | }
265 |
266 | /**
267 | * 重新加载模板
268 | */
269 | private void loadTemplate() {
270 | List templateDetails = templateService.getAllTemplates();
271 | ObservableList items = FXCollections.observableArrayList(templateDetails);
272 | templateChoiceBox.setItems(items);
273 | if (items.size() > 0) {
274 | templateChoiceBox.setValue(items.get(0));
275 | }
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/ui/GenerateView.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.ui;
2 |
3 | import de.felixroske.jfxsupport.AbstractFxmlView;
4 | import de.felixroske.jfxsupport.FXMLView;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2017/5/21, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | @FXMLView
12 | public class GenerateView extends AbstractFxmlView {
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/ui/NewConnectionController.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.ui;
2 |
3 | import de.felixroske.jfxsupport.FXMLController;
4 | import javafx.event.ActionEvent;
5 | import javafx.fxml.Initializable;
6 | import javafx.geometry.Pos;
7 | import javafx.scene.control.ChoiceBox;
8 | import javafx.scene.control.PasswordField;
9 | import javafx.scene.control.TextField;
10 | import javafx.stage.Stage;
11 | import me.beldon.module.generate.domain.ConnectDb;
12 | import me.beldon.module.generate.service.IConnectDbService;
13 | import me.beldon.module.window.service.IWindowService;
14 | import org.controlsfx.control.Notifications;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.util.StringUtils;
17 |
18 | import java.net.URL;
19 | import java.sql.DriverManager;
20 | import java.util.ResourceBundle;
21 |
22 | /**
23 | * Created by Beldon.
24 | * Copyright (c) 2017/5/21, All Rights Reserved.
25 | * http://beldon.me
26 | */
27 | @FXMLController
28 | public class NewConnectionController implements Initializable {
29 | public static String DRIVER_MYSQL = "com.mysql.jdbc.Driver";
30 |
31 | public ChoiceBox dbTypeChoice;
32 | public ChoiceBox encodingChoice;
33 | public TextField hostField;
34 | public TextField portField;
35 | public TextField userNameField;
36 | public TextField schemaField;
37 | public PasswordField passwordField;
38 | public TextField nameField;
39 |
40 | @Autowired
41 | private GenerateController generateController;
42 |
43 |
44 |
45 | @Autowired
46 | private IConnectDbService connectDbService;
47 |
48 | @Autowired
49 | private IWindowService windowService;
50 |
51 | @Override
52 | public void initialize(URL location, ResourceBundle resources) {
53 | dbTypeChoice.setValue("MySQL");
54 | encodingChoice.setValue("utf8");
55 | portField.setText("3306");
56 | hostField.setText("localhost");
57 | userNameField.setText("root");
58 | }
59 |
60 | public void testConnection(ActionEvent actionEvent) {
61 | if (checkConnect()) {
62 | Notifications.create().title("测试连接").text("连接成功!").position(Pos.BASELINE_CENTER).showInformation();
63 | }
64 | }
65 |
66 |
67 | public void saveConnection(ActionEvent actionEvent) {
68 | if (checkConnect()) {
69 | ConnectDb connectDb = new ConnectDb();
70 | String name = nameField.getText();
71 | if (StringUtils.isEmpty(name)) {
72 | name = schemaField.getText();
73 | }
74 | connectDb.setName(name);
75 | connectDb.setType(dbTypeChoice.getValue());
76 | connectDb.setHost(hostField.getText());
77 | connectDb.setPort(portField.getText());
78 | connectDb.setUser(userNameField.getText());
79 | connectDb.setPass(passwordField.getText());
80 | connectDb.setSchema(schemaField.getText());
81 | connectDb.setEncoding(encodingChoice.getValue());
82 | connectDbService.save(connectDb);
83 | Notifications.create().title("测试连接").text("保存成功").position(Pos.BASELINE_CENTER).showInformation();
84 | generateController.loadLeftDBTree();
85 | windowService.closeDialog(NewConnectionView.class);
86 | }
87 | }
88 |
89 | public boolean checkConnect() {
90 | String host = hostField.getText();
91 | if (StringUtils.isEmpty(host)) {
92 | Notifications.create().title("测试连接").text("主机名或IP地址不能为空").position(Pos.BASELINE_CENTER).showWarning();
93 | return false;
94 | }
95 |
96 | String portText = portField.getText();
97 | if (StringUtils.isEmpty(portText)) {
98 | Notifications.create().title("测试连接").text("端口不能为空").position(Pos.BASELINE_CENTER).showWarning();
99 | return false;
100 | }
101 | try {
102 | Integer.parseInt(portText.trim());
103 | } catch (Exception e) {
104 | Notifications.create().title("测试连接").text("端口只能为纯数字").position(Pos.BASELINE_CENTER).showWarning();
105 | return false;
106 | }
107 |
108 | String username = userNameField.getText();
109 | if (StringUtils.isEmpty(username)) {
110 | Notifications.create().title("测试连接").text("密码不能为空").position(Pos.BASELINE_CENTER).showWarning();
111 | return false;
112 | }
113 |
114 | String schema = schemaField.getText();
115 | if (StringUtils.isEmpty(schema)) {
116 | Notifications.create().title("测试连接").text("Schema/数据库不能为空").position(Pos.BASELINE_CENTER).showWarning();
117 | return false;
118 | }
119 |
120 | String password = passwordField.getText();
121 | try {
122 | Class.forName(DRIVER_MYSQL);
123 | String url = "jdbc:mysql://" + host + ":" + portText + "/" + schema + "?serverTimezone=UTC&characterEncoding=" + encodingChoice.getValue();
124 | DriverManager.getConnection(url, username, password);
125 | return true;
126 | } catch (Exception e) {
127 | Notifications.create().title("测试连接").text("连接失败!").position(Pos.BASELINE_CENTER).showWarning();
128 | }
129 |
130 | return false;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/ui/NewConnectionView.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.generate.ui;
2 |
3 | import de.felixroske.jfxsupport.AbstractFxmlView;
4 | import de.felixroske.jfxsupport.FXMLView;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2017/5/21, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | @FXMLView
12 | public class NewConnectionView extends AbstractFxmlView {
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/ui/generate.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
41 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
164 |
165 |
166 |
171 |
172 |
173 |
174 |
175 |
176 |
181 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/generate/ui/newConnection.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
71 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Beldon.
3 | * Copyright (c) 2017/5/15, All Rights Reserved.
4 | * http://beldon.me
5 | */
6 | package me.beldon.module;
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/template/bean/TemplateDetails.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.template.bean;
2 |
3 | import org.springframework.util.StringUtils;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 模板基本信息类
9 | * Created by Beldon.
10 | * Copyright (c) 2017/5/27, All Rights Reserved.
11 | * http://beldon.me
12 | */
13 | public class TemplateDetails {
14 | /**
15 | * 模板名字
16 | */
17 | private String name;
18 |
19 | /**
20 | * 作者名称
21 | */
22 | private String author;
23 |
24 | /**
25 | * 作者链接
26 | */
27 | private String url;
28 |
29 | /**
30 | * 模板描述
31 | */
32 | private String description;
33 |
34 | private String path;
35 |
36 | /**
37 | * 模板文件
38 | */
39 | private List templates;
40 |
41 | public String getName() {
42 | return name;
43 | }
44 |
45 | public void setName(String name) {
46 | this.name = name;
47 | }
48 |
49 | public String getAuthor() {
50 | return author;
51 | }
52 |
53 | public void setAuthor(String author) {
54 | this.author = author;
55 | }
56 |
57 | public String getUrl() {
58 | return url;
59 | }
60 |
61 | public void setUrl(String url) {
62 | this.url = url;
63 | }
64 |
65 | public String getDescription() {
66 | return description;
67 | }
68 |
69 | public void setDescription(String description) {
70 | this.description = description;
71 | }
72 |
73 | public List getTemplates() {
74 | return templates;
75 | }
76 |
77 | public void setTemplates(List templates) {
78 | this.templates = templates;
79 | }
80 |
81 | public String getPath() {
82 | return path;
83 | }
84 |
85 | public void setPath(String path) {
86 | this.path = path;
87 | }
88 |
89 | @Override
90 | public String toString() {
91 | return StringUtils.hasText(name) ? name : path;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/template/bean/TemplateFtl.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.template.bean;
2 |
3 | import org.springframework.util.StringUtils;
4 |
5 | /**
6 | * Ftl模板文件
7 | * Created by Beldon.
8 | * Copyright (c) 2017/5/27, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | public class TemplateFtl {
12 |
13 | /**
14 | * 名字
15 | */
16 | private String name;
17 | /**
18 | * 描述
19 | */
20 | private String description;
21 |
22 | /**
23 | * 模板文件名
24 | */
25 | private String fileName;
26 |
27 | /**
28 | * 生成的目标包名
29 | */
30 | private String targetPackage;
31 |
32 | /**
33 | * 模板生成的路径
34 | */
35 | private String targetPath;
36 |
37 | /**
38 | * 生成的目标文件名
39 | */
40 | private String targetFileName;
41 |
42 | /**
43 | * 类型,java代表java文件,其他则表是非java文件
44 | */
45 | private String type = "java";
46 |
47 | /**
48 | * 模板根目录
49 | */
50 | private String basePath = "/src/main/java";
51 |
52 | public String getName() {
53 | return name;
54 | }
55 |
56 | public void setName(String name) {
57 | this.name = name;
58 | }
59 |
60 | public String getDescription() {
61 | return description;
62 | }
63 |
64 | public void setDescription(String description) {
65 | this.description = description;
66 | }
67 |
68 | public String getFileName() {
69 | return fileName;
70 | }
71 |
72 | public void setFileName(String fileName) {
73 | this.fileName = fileName;
74 | }
75 |
76 | public String getTargetPackage() {
77 | return targetPackage;
78 | }
79 |
80 | public void setTargetPackage(String targetPackage) {
81 | this.targetPackage = targetPackage;
82 | }
83 |
84 | public String getTargetFileName() {
85 | return targetFileName;
86 | }
87 |
88 | public void setTargetFileName(String targetFileName) {
89 | this.targetFileName = targetFileName;
90 | }
91 |
92 | public String getTargetPath() {
93 | return targetPath;
94 | }
95 |
96 | public void setTargetPath(String targetPath) {
97 | this.targetPath = targetPath;
98 | }
99 |
100 | public String getType() {
101 | return type;
102 | }
103 |
104 | public void setType(String type) {
105 | this.type = type;
106 | }
107 |
108 | public String getBasePath() {
109 | return basePath;
110 | }
111 |
112 | public void setBasePath(String basePath) {
113 | if (StringUtils.hasText(basePath)) {
114 | this.basePath = basePath;
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/template/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Beldon.
3 | * Copyright (c) 2017/5/27, All Rights Reserved.
4 | * http://beldon.me
5 | */
6 | package me.beldon.module.template;
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/template/service/ITemplateService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.template.service;
2 |
3 | import me.beldon.module.template.bean.TemplateDetails;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by Beldon.
9 | * Copyright (c) 2017/5/27, All Rights Reserved.
10 | * http://beldon.me
11 | */
12 | public interface ITemplateService {
13 |
14 | /**
15 | * 模板目录
16 | */
17 | String TEMPLATE_PATH = "res/templates";
18 |
19 | List getAllTemplates();
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/template/service/impl/TemplateService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.template.service.impl;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import me.beldon.module.template.bean.TemplateDetails;
5 | import me.beldon.module.template.service.ITemplateService;
6 | import org.springframework.stereotype.Service;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.File;
10 | import java.io.FileReader;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by Beldon.
16 | * Copyright (c) 2017/5/27, All Rights Reserved.
17 | * http://beldon.me
18 | */
19 | @Service
20 | public class TemplateService implements ITemplateService {
21 | @Override
22 | public List getAllTemplates() {
23 | File file = new File(TEMPLATE_PATH);
24 | if (!file.exists()) {
25 | file.mkdirs();
26 | }
27 |
28 | List templateDetails = new ArrayList<>();
29 | try {
30 | File[] templateDirs = file.listFiles(File::isDirectory); //模板目录
31 | for (File templateDir : templateDirs) {
32 |
33 | String templateDirName = templateDir.getName();
34 | File configFile = new File(templateDir, "config.json");
35 |
36 | BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile));
37 | String s;
38 | StringBuffer stringBuffer = new StringBuffer();
39 | while((s = bufferedReader.readLine())!=null){//使用readLine方法,一次读一行
40 | stringBuffer.append(System.lineSeparator()+s);
41 | }
42 | bufferedReader.close();
43 |
44 | TemplateDetails details = JSON.parseObject(stringBuffer.toString(), TemplateDetails.class);
45 | details.setPath(templateDirName);
46 | templateDetails.add(details);
47 | }
48 | } catch (Exception e) {
49 | e.printStackTrace();
50 | }
51 |
52 | return templateDetails;
53 | }
54 |
55 | public static void main(String[] args) {
56 | TemplateService templateService = new TemplateService();
57 | List details = templateService.getAllTemplates();
58 | System.out.println("a");
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/template/service/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Beldon.
3 | * Copyright (c) 2017/5/27, All Rights Reserved.
4 | * http://beldon.me
5 | */
6 | package me.beldon.module.template.service;
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/window/service/IWindowService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.window.service;
2 |
3 | import de.felixroske.jfxsupport.AbstractFxmlView;
4 | import javafx.stage.Stage;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2017/5/15, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | public interface IWindowService {
12 | /**
13 | * 托盘
14 | */
15 | void enableTray();
16 |
17 | /**
18 | * 显示dialog
19 | *
20 | * @param dialogView
21 | * @param title
22 | * @param width
23 | * @param height
24 | */
25 | void showDialog(final Class extends AbstractFxmlView> dialogView, String title, double width, double height);
26 |
27 | /**
28 | * 获取dialog
29 | *
30 | * @param viewClass
31 | * @return
32 | */
33 | Stage getDialogStage(Class viewClass);
34 |
35 | void closeDialog(Class viewClass);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/window/service/impl/WindowService.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.window.service.impl;
2 |
3 | import de.felixroske.jfxsupport.AbstractFxmlView;
4 | import de.felixroske.jfxsupport.GUIState;
5 | import javafx.application.Platform;
6 | import javafx.geometry.Pos;
7 | import javafx.scene.Scene;
8 | import javafx.stage.Modality;
9 | import javafx.stage.Stage;
10 | import javafx.util.Duration;
11 | import me.beldon.GenerateApplication;
12 | import me.beldon.module.generate.ui.NewConnectionView;
13 | import me.beldon.module.window.service.IWindowService;
14 | import me.beldon.util.SpringContextUtil;
15 | import org.controlsfx.control.Notifications;
16 | import org.springframework.stereotype.Service;
17 |
18 | import javax.imageio.ImageIO;
19 | import java.awt.*;
20 | import java.awt.event.ActionListener;
21 | import java.awt.event.MouseEvent;
22 | import java.awt.event.MouseListener;
23 | import java.awt.image.BufferedImage;
24 | import java.util.HashMap;
25 | import java.util.Map;
26 |
27 | /**
28 | * Created by Beldon.
29 | * Copyright (c) 2017/5/15, All Rights Reserved.
30 | * http://beldon.me
31 | */
32 | @Service
33 | public class WindowService implements IWindowService {
34 | private TrayIcon trayIcon;
35 | private boolean first = true;
36 |
37 | private Map dialogs = new HashMap<>();
38 |
39 | @Override
40 | public void enableTray() {
41 | if (SystemTray.isSupported()) {
42 | try {
43 | if (first) {
44 | trayInit();
45 | SystemTray.getSystemTray().add(trayIcon);
46 | trayIcon.displayMessage("退出提示", "已最小化到托盘.", TrayIcon.MessageType.NONE);
47 | first = false;
48 | }
49 |
50 | } catch (Exception e) {
51 | e.printStackTrace();
52 | }
53 | } else {
54 | Notifications.create().title("系统错误").text("系统不支持托盘").position(Pos.BOTTOM_RIGHT).hideAfter(Duration.seconds(5)).showError();
55 | }
56 | }
57 |
58 | @Override
59 | public void showDialog(Class extends AbstractFxmlView> dialogView, String title, double width, double height) {
60 | Stage dialogStage;
61 | if (dialogs.containsKey(dialogView)) {
62 | dialogStage = dialogs.get(dialogView);
63 | }else{
64 | final AbstractFxmlView view = SpringContextUtil.getApplicationContext().getBean(dialogView);
65 | Scene scene = new Scene(view.getView());
66 | dialogStage = new Stage();
67 | dialogStage.setScene(scene);
68 | dialogStage.initModality(Modality.APPLICATION_MODAL);
69 | dialogStage.initOwner(GUIState.getStage());
70 | dialogStage.setMaximized(false);
71 | dialogStage.setResizable(false);
72 | dialogs.put(dialogView, dialogStage);
73 | }
74 | dialogStage.setTitle(title);
75 | dialogStage.setHeight(height);
76 | dialogStage.setWidth(width);
77 | dialogStage.show();
78 | }
79 |
80 | @Override
81 | public Stage getDialogStage(Class viewClass) {
82 | return dialogs.get(viewClass);
83 | }
84 |
85 | @Override
86 | public void closeDialog(Class viewClass) {
87 | Stage stage = getDialogStage(viewClass);
88 | if (stage != null) {
89 | stage.close();
90 | }
91 | }
92 |
93 | private void trayInit() {
94 | Stage stage = GenerateApplication.getStage();
95 | PopupMenu popupMenu = new PopupMenu();
96 | MenuItem openItem = new MenuItem("Show");
97 | MenuItem hideItem = new MenuItem("Small最小化");
98 | MenuItem quitItem = new MenuItem("Exit");
99 |
100 | ActionListener acl = e -> {
101 | MenuItem item = (MenuItem) e.getSource();
102 | Platform.setImplicitExit(false); //多次使用显示和隐藏设置false
103 | if (item.getLabel().equals("Exit")) {
104 | SystemTray.getSystemTray().remove(trayIcon);
105 | Platform.exit();
106 | return;
107 | }
108 | if (item.getLabel().equals("Show")) {
109 | stage.centerOnScreen();
110 | Platform.runLater(() -> stage.show());
111 | }
112 | if (item.getLabel().equals("Small")) {
113 | Platform.runLater(() -> stage.hide());
114 | }
115 |
116 | };
117 |
118 | //双击事件方法
119 | MouseListener mouseListener = new MouseListener() {
120 | public void mouseReleased(MouseEvent e) {
121 | }
122 |
123 | public void mousePressed(MouseEvent e) {
124 | }
125 |
126 | public void mouseExited(MouseEvent e) {
127 | }
128 |
129 | public void mouseEntered(MouseEvent e) {
130 | }
131 |
132 | public void mouseClicked(MouseEvent e) {
133 | Platform.setImplicitExit(false); //多次使用显示和隐藏设置false
134 | if (e.getClickCount() == 2) {
135 | if (stage.isShowing()) {
136 | Platform.runLater(() -> stage.hide());
137 | } else {
138 | Platform.runLater(() -> stage.show());
139 | }
140 | }
141 | }
142 | };
143 |
144 | openItem.addActionListener(acl);
145 | quitItem.addActionListener(acl);
146 | hideItem.addActionListener(acl);
147 |
148 | popupMenu.add(openItem);
149 | popupMenu.add(hideItem);
150 | popupMenu.add(quitItem);
151 |
152 | try {
153 | BufferedImage image = ImageIO.read(this.getClass().getResourceAsStream("/image/sysTray.png"));
154 | trayIcon = new TrayIcon(image, "tools", popupMenu);
155 | trayIcon.addMouseListener(mouseListener);
156 | } catch (Exception e) {
157 | e.printStackTrace();
158 | }
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/window/ui/MainController.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.window.ui;
2 |
3 | import de.felixroske.jfxsupport.FXMLController;
4 | import javafx.event.ActionEvent;
5 | import me.beldon.GenerateApplication;
6 | import me.beldon.module.generate.ui.GenerateView;
7 |
8 | /**
9 | * Created by Beldon.
10 | * Copyright (c) 2017/5/15, All Rights Reserved.
11 | * http://beldon.me
12 | */
13 | @FXMLController
14 | public class MainController {
15 |
16 | public void showGenerate(ActionEvent actionEvent) {
17 | GenerateApplication.showView(GenerateView.class);
18 | }
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/window/ui/MainView.java:
--------------------------------------------------------------------------------
1 | package me.beldon.module.window.ui;
2 |
3 | import de.felixroske.jfxsupport.AbstractFxmlView;
4 | import de.felixroske.jfxsupport.FXMLView;
5 |
6 | /**
7 | * Created by Beldon.
8 | * Copyright (c) 2017/5/15, All Rights Reserved.
9 | * http://beldon.me
10 | */
11 | @FXMLView
12 | public class MainView extends AbstractFxmlView {
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/module/window/ui/main.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/util/SSUtils.java:
--------------------------------------------------------------------------------
1 | package me.beldon.util;
2 |
3 | /**
4 | * Created by Beldon.
5 | * Copyright (c) 2016/10/14, All Rights Reserved.
6 | * http://beldon.me
7 | */
8 | public class SSUtils {
9 | public static final char UNDERLINE = '_';
10 |
11 | public static String camelToUnderline(String param) {
12 | if (param == null || "".equals(param.trim())) {
13 | return "";
14 | }
15 | int len = param.length();
16 | StringBuilder sb = new StringBuilder(len);
17 | for (int i = 0; i < len; i++) {
18 | char c = param.charAt(i);
19 | if (Character.isUpperCase(c)) {
20 | if (i != 0) {
21 | sb.append(UNDERLINE);
22 | }
23 | sb.append(Character.toLowerCase(c));
24 | } else {
25 | sb.append(c);
26 | }
27 | }
28 | return sb.toString();
29 | }
30 |
31 | public static String underlineToCamel(String param) {
32 | if (param == null || "".equals(param.trim())) {
33 | return "";
34 | }
35 | int len = param.length();
36 | StringBuilder sb = new StringBuilder(len);
37 | for (int i = 0; i < len; i++) {
38 | char c = param.charAt(i);
39 | if (c == UNDERLINE) {
40 | if (++i < len) {
41 | sb.append(Character.toUpperCase(param.charAt(i)));
42 | }
43 | } else {
44 | if (i == 0) {
45 | sb.append(Character.toUpperCase(param.charAt(i)));
46 | }else{
47 | sb.append(c);
48 | }
49 | }
50 | }
51 | return sb.toString();
52 | }
53 |
54 | public static String underlineToCamel2(String param) {
55 | if (param == null || "".equals(param.trim())) {
56 | return "";
57 | }
58 | int len = param.length();
59 | StringBuilder sb = new StringBuilder(len);
60 | for (int i = 0; i < len; i++) {
61 | char c = param.charAt(i);
62 | if (c == UNDERLINE) {
63 | if (++i < len) {
64 | sb.append(Character.toUpperCase(param.charAt(i)));
65 | }
66 | } else {
67 | sb.append(c);
68 | }
69 | }
70 | return sb.toString();
71 | }
72 |
73 | public static void main(String[] args) {
74 | System.out.println(camelToUnderline("BeldonHelper"));
75 | System.out.println(underlineToCamel("beldon_helper"));
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/me/beldon/util/SpringContextUtil.java:
--------------------------------------------------------------------------------
1 | package me.beldon.util;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * Created by Beldon.
10 | * Copyright (c) 2017/5/15, All Rights Reserved.
11 | * http://beldon.me
12 | */
13 | @Component
14 | public class SpringContextUtil implements ApplicationContextAware {
15 | private static ApplicationContext applicationContext;
16 | @Override
17 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
18 | SpringContextUtil.applicationContext = applicationContext;
19 | }
20 |
21 | public static ApplicationContext getApplicationContext() {
22 | return applicationContext;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | jpa:
3 | database-platform: me.beldon.core.SQLiteDialect
4 | # hibernate:
5 | # ddl-auto: create
6 | datasource:
7 | url: jdbc:sqlite:res\\generate.db
8 | username: root
9 | password: root
10 | driver-class-name: org.sqlite.JDBC
11 | type: com.alibaba.druid.pool.DruidDataSource
12 | filters: stat
13 | maxActive: 20
14 | initialSize: 1
15 | maxWait: 60000
16 | minIdle: 1
17 | timeBetweenEvictionRunsMillis: 60000
18 | minEvictableIdleTimeMillis: 300000
19 | validationQuery: select 'x'
20 | testWhileIdle: true
21 | testOnBorrow: false
22 | testOnReturn: false
23 | poolPreparedStatements: true
24 | maxOpenPreparedStatements: 20
25 |
26 | javafx:
27 | title: Beldon Tools
28 | appicons:
29 | - /image/logo.png
30 | stage:
31 | # width: 800 # defaults to the size of the scene
32 | # height: 600
33 | # resizable: false # defaults to true
34 | # style: utility # defaults to DECORATED see: javafx.stage.StageStyle
35 |
36 | banner:
37 | location: banner.txt
38 | charset: utf-8
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/resources/icons/computer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/icons/computer.png
--------------------------------------------------------------------------------
/src/main/resources/icons/config-list.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/icons/config-list.png
--------------------------------------------------------------------------------
/src/main/resources/icons/database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/icons/database.png
--------------------------------------------------------------------------------
/src/main/resources/icons/table.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/icons/table.png
--------------------------------------------------------------------------------
/src/main/resources/image/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/image/logo.png
--------------------------------------------------------------------------------
/src/main/resources/image/sysTray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/image/sysTray.png
--------------------------------------------------------------------------------
/src/main/resources/splash/javafx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beldon/code-generator/37120ab2889c849025d28315c97416e3bd20d9f0/src/main/resources/splash/javafx.png
--------------------------------------------------------------------------------
/src/main/resources/style.css:
--------------------------------------------------------------------------------
1 | * {
2 | -fx-font-size: 12px;
3 | }
4 |
5 | .button {
6 | -fx-font-size: 14px;
7 | }
8 |
9 | .tool-bar .button {
10 | -fx-border-width: 0px;
11 | }
12 |
13 | .btn {
14 | -fx-border-width: 1px;
15 | -fx-border-color: transparent;
16 | -fx-border-radius: 4px;
17 | }
18 |
19 | .btn-primary {
20 | -fx-background-color: #378bfa;
21 | -fx-text-fill: white;
22 | }
23 |
24 | .btn-primary:hover {
25 | -fx-background-color: #579efa;
26 | }
27 |
28 | .btn-default {
29 | -fx-text-fill: #333;
30 | -fx-background-color: #fff;
31 | -fx-border-color: #ccc;
32 | }
33 |
34 | .btn-default:hover {
35 | -fx-background-color: #e6e6e6;
36 | -fx-border-color: #adadad;
37 | }
38 |
39 | .btn-success:hover {
40 | -fx-text-fill: #fff;
41 | -fx-background-color: #449d44;
42 | -fx-border-color: #398439;
43 | }
44 |
45 | .btn-success {
46 | -fx-text-fill: #fff;
47 | -fx-background-color: #5cb85c;
48 | -fx-border-color: #4cae4c;
49 | }
50 |
51 | .consoleTextArea {
52 | -fx-stroke: white;
53 | -fx-fill: black;
54 | -fx-background-color: black;
55 | }
56 |
57 | .consoleTextArea:focused {
58 | }
--------------------------------------------------------------------------------
/src/test/java/me/beldon/GenerateApplicationTests.java:
--------------------------------------------------------------------------------
1 | package me.beldon;
2 |
3 | import me.beldon.module.demo.User;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | @RunWith(SpringRunner.class)
10 | @SpringBootTest
11 | public class GenerateApplicationTests {
12 |
13 | @Test
14 | public void contextLoads() {
15 |
16 | User user = new User() {
17 | public void setAge(Integer age) {
18 | super.setAge(age);
19 | }
20 | };
21 | Runnable runnable = new Runnable() {
22 | @Override
23 | public void run() {
24 |
25 | }
26 | };
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------