Commit 993ce8e530f6eeff04d8ff3d739f3cc4d0974c77
0 parents
鲁班h5编辑器SpringBoot后台改造,初始化
Showing
30 changed files
with
1925 additions
and
0 deletions
.gitignore
0 → 100644
| 1 | +++ a/.gitignore | ||
| 1 | +HELP.md | ||
| 2 | +target/ | ||
| 3 | +!.mvn/wrapper/maven-wrapper.jar | ||
| 4 | +!**/src/main/**/target/ | ||
| 5 | +!**/src/test/**/target/ | ||
| 6 | + | ||
| 7 | +### STS ### | ||
| 8 | +.apt_generated | ||
| 9 | +.classpath | ||
| 10 | +.factorypath | ||
| 11 | +.project | ||
| 12 | +.settings | ||
| 13 | +.springBeans | ||
| 14 | +.sts4-cache | ||
| 15 | + | ||
| 16 | +### IntelliJ IDEA ### | ||
| 17 | +.idea | ||
| 18 | +*.iws | ||
| 19 | +*.iml | ||
| 20 | +*.ipr | ||
| 21 | + | ||
| 22 | +### NetBeans ### | ||
| 23 | +/nbproject/private/ | ||
| 24 | +/nbbuild/ | ||
| 25 | +/dist/ | ||
| 26 | +/nbdist/ | ||
| 27 | +/.nb-gradle/ | ||
| 28 | +build/ | ||
| 29 | +!**/src/main/**/build/ | ||
| 30 | +!**/src/test/**/build/ | ||
| 31 | + | ||
| 32 | +### VS Code ### | ||
| 33 | +.vscode/ |
.mvn/wrapper/MavenWrapperDownloader.java
0 → 100644
| 1 | +++ a/.mvn/wrapper/MavenWrapperDownloader.java | ||
| 1 | +/* | ||
| 2 | + * Copyright 2007-present the original author or authors. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +import java.net.*; | ||
| 17 | +import java.io.*; | ||
| 18 | +import java.nio.channels.*; | ||
| 19 | +import java.util.Properties; | ||
| 20 | + | ||
| 21 | +public class MavenWrapperDownloader { | ||
| 22 | + | ||
| 23 | + private static final String WRAPPER_VERSION = "0.5.6"; | ||
| 24 | + /** | ||
| 25 | + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | ||
| 26 | + */ | ||
| 27 | + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" | ||
| 28 | + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | ||
| 32 | + * use instead of the default one. | ||
| 33 | + */ | ||
| 34 | + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | ||
| 35 | + ".mvn/wrapper/maven-wrapper.properties"; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * Path where the maven-wrapper.jar will be saved to. | ||
| 39 | + */ | ||
| 40 | + private static final String MAVEN_WRAPPER_JAR_PATH = | ||
| 41 | + ".mvn/wrapper/maven-wrapper.jar"; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Name of the property which should be used to override the default download url for the wrapper. | ||
| 45 | + */ | ||
| 46 | + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | ||
| 47 | + | ||
| 48 | + public static void main(String args[]) { | ||
| 49 | + System.out.println("- Downloader started"); | ||
| 50 | + File baseDirectory = new File(args[0]); | ||
| 51 | + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | ||
| 52 | + | ||
| 53 | + // If the maven-wrapper.properties exists, read it and check if it contains a custom | ||
| 54 | + // wrapperUrl parameter. | ||
| 55 | + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | ||
| 56 | + String url = DEFAULT_DOWNLOAD_URL; | ||
| 57 | + if(mavenWrapperPropertyFile.exists()) { | ||
| 58 | + FileInputStream mavenWrapperPropertyFileInputStream = null; | ||
| 59 | + try { | ||
| 60 | + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | ||
| 61 | + Properties mavenWrapperProperties = new Properties(); | ||
| 62 | + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | ||
| 63 | + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | ||
| 64 | + } catch (IOException e) { | ||
| 65 | + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | ||
| 66 | + } finally { | ||
| 67 | + try { | ||
| 68 | + if(mavenWrapperPropertyFileInputStream != null) { | ||
| 69 | + mavenWrapperPropertyFileInputStream.close(); | ||
| 70 | + } | ||
| 71 | + } catch (IOException e) { | ||
| 72 | + // Ignore ... | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + System.out.println("- Downloading from: " + url); | ||
| 77 | + | ||
| 78 | + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | ||
| 79 | + if(!outputFile.getParentFile().exists()) { | ||
| 80 | + if(!outputFile.getParentFile().mkdirs()) { | ||
| 81 | + System.out.println( | ||
| 82 | + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | ||
| 86 | + try { | ||
| 87 | + downloadFileFromURL(url, outputFile); | ||
| 88 | + System.out.println("Done"); | ||
| 89 | + System.exit(0); | ||
| 90 | + } catch (Throwable e) { | ||
| 91 | + System.out.println("- Error downloading"); | ||
| 92 | + e.printStackTrace(); | ||
| 93 | + System.exit(1); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + private static void downloadFileFromURL(String urlString, File destination) throws Exception { | ||
| 98 | + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { | ||
| 99 | + String username = System.getenv("MVNW_USERNAME"); | ||
| 100 | + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); | ||
| 101 | + Authenticator.setDefault(new Authenticator() { | ||
| 102 | + @Override | ||
| 103 | + protected PasswordAuthentication getPasswordAuthentication() { | ||
| 104 | + return new PasswordAuthentication(username, password); | ||
| 105 | + } | ||
| 106 | + }); | ||
| 107 | + } | ||
| 108 | + URL website = new URL(urlString); | ||
| 109 | + ReadableByteChannel rbc; | ||
| 110 | + rbc = Channels.newChannel(website.openStream()); | ||
| 111 | + FileOutputStream fos = new FileOutputStream(destination); | ||
| 112 | + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | ||
| 113 | + fos.close(); | ||
| 114 | + rbc.close(); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | +} |
.mvn/wrapper/maven-wrapper.jar
0 → 100644
No preview for this file type
.mvn/wrapper/maven-wrapper.properties
0 → 100644
mvnw
0 → 100755
| 1 | +++ a/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 | +# https://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 | +# Maven 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 Mingw, 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 | +fi | ||
| 118 | + | ||
| 119 | +if [ -z "$JAVA_HOME" ]; then | ||
| 120 | + javaExecutable="`which javac`" | ||
| 121 | + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then | ||
| 122 | + # readlink(1) is not available as standard on Solaris 10. | ||
| 123 | + readLink=`which readlink` | ||
| 124 | + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then | ||
| 125 | + if $darwin ; then | ||
| 126 | + javaHome="`dirname \"$javaExecutable\"`" | ||
| 127 | + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" | ||
| 128 | + else | ||
| 129 | + javaExecutable="`readlink -f \"$javaExecutable\"`" | ||
| 130 | + fi | ||
| 131 | + javaHome="`dirname \"$javaExecutable\"`" | ||
| 132 | + javaHome=`expr "$javaHome" : '\(.*\)/bin'` | ||
| 133 | + JAVA_HOME="$javaHome" | ||
| 134 | + export JAVA_HOME | ||
| 135 | + fi | ||
| 136 | + fi | ||
| 137 | +fi | ||
| 138 | + | ||
| 139 | +if [ -z "$JAVACMD" ] ; then | ||
| 140 | + if [ -n "$JAVA_HOME" ] ; then | ||
| 141 | + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | ||
| 142 | + # IBM's JDK on AIX uses strange locations for the executables | ||
| 143 | + JAVACMD="$JAVA_HOME/jre/sh/java" | ||
| 144 | + else | ||
| 145 | + JAVACMD="$JAVA_HOME/bin/java" | ||
| 146 | + fi | ||
| 147 | + else | ||
| 148 | + JAVACMD="`which java`" | ||
| 149 | + fi | ||
| 150 | +fi | ||
| 151 | + | ||
| 152 | +if [ ! -x "$JAVACMD" ] ; then | ||
| 153 | + echo "Error: JAVA_HOME is not defined correctly." >&2 | ||
| 154 | + echo " We cannot execute $JAVACMD" >&2 | ||
| 155 | + exit 1 | ||
| 156 | +fi | ||
| 157 | + | ||
| 158 | +if [ -z "$JAVA_HOME" ] ; then | ||
| 159 | + echo "Warning: JAVA_HOME environment variable is not set." | ||
| 160 | +fi | ||
| 161 | + | ||
| 162 | +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher | ||
| 163 | + | ||
| 164 | +# traverses directory structure from process work directory to filesystem root | ||
| 165 | +# first directory with .mvn subdirectory is considered project base directory | ||
| 166 | +find_maven_basedir() { | ||
| 167 | + | ||
| 168 | + if [ -z "$1" ] | ||
| 169 | + then | ||
| 170 | + echo "Path not specified to find_maven_basedir" | ||
| 171 | + return 1 | ||
| 172 | + fi | ||
| 173 | + | ||
| 174 | + basedir="$1" | ||
| 175 | + wdir="$1" | ||
| 176 | + while [ "$wdir" != '/' ] ; do | ||
| 177 | + if [ -d "$wdir"/.mvn ] ; then | ||
| 178 | + basedir=$wdir | ||
| 179 | + break | ||
| 180 | + fi | ||
| 181 | + # workaround for JBEAP-8937 (on Solaris 10/Sparc) | ||
| 182 | + if [ -d "${wdir}" ]; then | ||
| 183 | + wdir=`cd "$wdir/.."; pwd` | ||
| 184 | + fi | ||
| 185 | + # end of workaround | ||
| 186 | + done | ||
| 187 | + echo "${basedir}" | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +# concatenates all lines of a file | ||
| 191 | +concat_lines() { | ||
| 192 | + if [ -f "$1" ]; then | ||
| 193 | + echo "$(tr -s '\n' ' ' < "$1")" | ||
| 194 | + fi | ||
| 195 | +} | ||
| 196 | + | ||
| 197 | +BASE_DIR=`find_maven_basedir "$(pwd)"` | ||
| 198 | +if [ -z "$BASE_DIR" ]; then | ||
| 199 | + exit 1; | ||
| 200 | +fi | ||
| 201 | + | ||
| 202 | +########################################################################################## | ||
| 203 | +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | ||
| 204 | +# This allows using the maven wrapper in projects that prohibit checking in binary data. | ||
| 205 | +########################################################################################## | ||
| 206 | +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then | ||
| 207 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 208 | + echo "Found .mvn/wrapper/maven-wrapper.jar" | ||
| 209 | + fi | ||
| 210 | +else | ||
| 211 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 212 | + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." | ||
| 213 | + fi | ||
| 214 | + if [ -n "$MVNW_REPOURL" ]; then | ||
| 215 | + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | ||
| 216 | + else | ||
| 217 | + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | ||
| 218 | + fi | ||
| 219 | + while IFS="=" read key value; do | ||
| 220 | + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; | ||
| 221 | + esac | ||
| 222 | + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" | ||
| 223 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 224 | + echo "Downloading from: $jarUrl" | ||
| 225 | + fi | ||
| 226 | + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" | ||
| 227 | + if $cygwin; then | ||
| 228 | + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` | ||
| 229 | + fi | ||
| 230 | + | ||
| 231 | + if command -v wget > /dev/null; then | ||
| 232 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 233 | + echo "Found wget ... using wget" | ||
| 234 | + fi | ||
| 235 | + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | ||
| 236 | + wget "$jarUrl" -O "$wrapperJarPath" | ||
| 237 | + else | ||
| 238 | + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" | ||
| 239 | + fi | ||
| 240 | + elif command -v curl > /dev/null; then | ||
| 241 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 242 | + echo "Found curl ... using curl" | ||
| 243 | + fi | ||
| 244 | + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | ||
| 245 | + curl -o "$wrapperJarPath" "$jarUrl" -f | ||
| 246 | + else | ||
| 247 | + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f | ||
| 248 | + fi | ||
| 249 | + | ||
| 250 | + else | ||
| 251 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 252 | + echo "Falling back to using Java to download" | ||
| 253 | + fi | ||
| 254 | + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" | ||
| 255 | + # For Cygwin, switch paths to Windows format before running javac | ||
| 256 | + if $cygwin; then | ||
| 257 | + javaClass=`cygpath --path --windows "$javaClass"` | ||
| 258 | + fi | ||
| 259 | + if [ -e "$javaClass" ]; then | ||
| 260 | + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | ||
| 261 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 262 | + echo " - Compiling MavenWrapperDownloader.java ..." | ||
| 263 | + fi | ||
| 264 | + # Compiling the Java class | ||
| 265 | + ("$JAVA_HOME/bin/javac" "$javaClass") | ||
| 266 | + fi | ||
| 267 | + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | ||
| 268 | + # Running the downloader | ||
| 269 | + if [ "$MVNW_VERBOSE" = true ]; then | ||
| 270 | + echo " - Running MavenWrapperDownloader.java ..." | ||
| 271 | + fi | ||
| 272 | + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") | ||
| 273 | + fi | ||
| 274 | + fi | ||
| 275 | + fi | ||
| 276 | +fi | ||
| 277 | +########################################################################################## | ||
| 278 | +# End of extension | ||
| 279 | +########################################################################################## | ||
| 280 | + | ||
| 281 | +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} | ||
| 282 | +if [ "$MVNW_VERBOSE" = true ]; then | ||
| 283 | + echo $MAVEN_PROJECTBASEDIR | ||
| 284 | +fi | ||
| 285 | +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" | ||
| 286 | + | ||
| 287 | +# For Cygwin, switch paths to Windows format before running java | ||
| 288 | +if $cygwin; then | ||
| 289 | + [ -n "$M2_HOME" ] && | ||
| 290 | + M2_HOME=`cygpath --path --windows "$M2_HOME"` | ||
| 291 | + [ -n "$JAVA_HOME" ] && | ||
| 292 | + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` | ||
| 293 | + [ -n "$CLASSPATH" ] && | ||
| 294 | + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` | ||
| 295 | + [ -n "$MAVEN_PROJECTBASEDIR" ] && | ||
| 296 | + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` | ||
| 297 | +fi | ||
| 298 | + | ||
| 299 | +# Provide a "standardized" way to retrieve the CLI args that will | ||
| 300 | +# work with both Windows and non-Windows executions. | ||
| 301 | +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" | ||
| 302 | +export MAVEN_CMD_LINE_ARGS | ||
| 303 | + | ||
| 304 | +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | ||
| 305 | + | ||
| 306 | +exec "$JAVACMD" \ | ||
| 307 | + $MAVEN_OPTS \ | ||
| 308 | + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ | ||
| 309 | + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ | ||
| 310 | + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" |
mvnw.cmd
0 → 100644
| 1 | +++ a/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 https://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 Maven 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 keystroke 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 set title of command window | ||
| 39 | +title %0 | ||
| 40 | +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' | ||
| 41 | +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% | ||
| 42 | + | ||
| 43 | +@REM set %HOME% to equivalent of $HOME | ||
| 44 | +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") | ||
| 45 | + | ||
| 46 | +@REM Execute a user defined script before this one | ||
| 47 | +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre | ||
| 48 | +@REM check for pre script, once with legacy .bat ending and once with .cmd ending | ||
| 49 | +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" | ||
| 50 | +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" | ||
| 51 | +:skipRcPre | ||
| 52 | + | ||
| 53 | +@setlocal | ||
| 54 | + | ||
| 55 | +set ERROR_CODE=0 | ||
| 56 | + | ||
| 57 | +@REM To isolate internal variables from possible post scripts, we use another setlocal | ||
| 58 | +@setlocal | ||
| 59 | + | ||
| 60 | +@REM ==== START VALIDATION ==== | ||
| 61 | +if not "%JAVA_HOME%" == "" goto OkJHome | ||
| 62 | + | ||
| 63 | +echo. | ||
| 64 | +echo Error: JAVA_HOME not found in your environment. >&2 | ||
| 65 | +echo Please set the JAVA_HOME variable in your environment to match the >&2 | ||
| 66 | +echo location of your Java installation. >&2 | ||
| 67 | +echo. | ||
| 68 | +goto error | ||
| 69 | + | ||
| 70 | +:OkJHome | ||
| 71 | +if exist "%JAVA_HOME%\bin\java.exe" goto init | ||
| 72 | + | ||
| 73 | +echo. | ||
| 74 | +echo Error: JAVA_HOME is set to an invalid directory. >&2 | ||
| 75 | +echo JAVA_HOME = "%JAVA_HOME%" >&2 | ||
| 76 | +echo Please set the JAVA_HOME variable in your environment to match the >&2 | ||
| 77 | +echo location of your Java installation. >&2 | ||
| 78 | +echo. | ||
| 79 | +goto error | ||
| 80 | + | ||
| 81 | +@REM ==== END VALIDATION ==== | ||
| 82 | + | ||
| 83 | +:init | ||
| 84 | + | ||
| 85 | +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". | ||
| 86 | +@REM Fallback to current working directory if not found. | ||
| 87 | + | ||
| 88 | +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% | ||
| 89 | +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir | ||
| 90 | + | ||
| 91 | +set EXEC_DIR=%CD% | ||
| 92 | +set WDIR=%EXEC_DIR% | ||
| 93 | +:findBaseDir | ||
| 94 | +IF EXIST "%WDIR%"\.mvn goto baseDirFound | ||
| 95 | +cd .. | ||
| 96 | +IF "%WDIR%"=="%CD%" goto baseDirNotFound | ||
| 97 | +set WDIR=%CD% | ||
| 98 | +goto findBaseDir | ||
| 99 | + | ||
| 100 | +:baseDirFound | ||
| 101 | +set MAVEN_PROJECTBASEDIR=%WDIR% | ||
| 102 | +cd "%EXEC_DIR%" | ||
| 103 | +goto endDetectBaseDir | ||
| 104 | + | ||
| 105 | +:baseDirNotFound | ||
| 106 | +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% | ||
| 107 | +cd "%EXEC_DIR%" | ||
| 108 | + | ||
| 109 | +:endDetectBaseDir | ||
| 110 | + | ||
| 111 | +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig | ||
| 112 | + | ||
| 113 | +@setlocal EnableExtensions EnableDelayedExpansion | ||
| 114 | +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a | ||
| 115 | +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% | ||
| 116 | + | ||
| 117 | +:endReadAdditionalConfig | ||
| 118 | + | ||
| 119 | +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" | ||
| 120 | +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" | ||
| 121 | +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | ||
| 122 | + | ||
| 123 | +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | ||
| 124 | + | ||
| 125 | +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( | ||
| 126 | + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B | ||
| 127 | +) | ||
| 128 | + | ||
| 129 | +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | ||
| 130 | +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. | ||
| 131 | +if exist %WRAPPER_JAR% ( | ||
| 132 | + if "%MVNW_VERBOSE%" == "true" ( | ||
| 133 | + echo Found %WRAPPER_JAR% | ||
| 134 | + ) | ||
| 135 | +) else ( | ||
| 136 | + if not "%MVNW_REPOURL%" == "" ( | ||
| 137 | + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | ||
| 138 | + ) | ||
| 139 | + if "%MVNW_VERBOSE%" == "true" ( | ||
| 140 | + echo Couldn't find %WRAPPER_JAR%, downloading it ... | ||
| 141 | + echo Downloading from: %DOWNLOAD_URL% | ||
| 142 | + ) | ||
| 143 | + | ||
| 144 | + powershell -Command "&{"^ | ||
| 145 | + "$webclient = new-object System.Net.WebClient;"^ | ||
| 146 | + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ | ||
| 147 | + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ | ||
| 148 | + "}"^ | ||
| 149 | + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ | ||
| 150 | + "}" | ||
| 151 | + if "%MVNW_VERBOSE%" == "true" ( | ||
| 152 | + echo Finished downloading %WRAPPER_JAR% | ||
| 153 | + ) | ||
| 154 | +) | ||
| 155 | +@REM End of extension | ||
| 156 | + | ||
| 157 | +@REM Provide a "standardized" way to retrieve the CLI args that will | ||
| 158 | +@REM work with both Windows and non-Windows executions. | ||
| 159 | +set MAVEN_CMD_LINE_ARGS=%* | ||
| 160 | + | ||
| 161 | +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* | ||
| 162 | +if ERRORLEVEL 1 goto error | ||
| 163 | +goto end | ||
| 164 | + | ||
| 165 | +:error | ||
| 166 | +set ERROR_CODE=1 | ||
| 167 | + | ||
| 168 | +:end | ||
| 169 | +@endlocal & set ERROR_CODE=%ERROR_CODE% | ||
| 170 | + | ||
| 171 | +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost | ||
| 172 | +@REM check for post script, once with legacy .bat ending and once with .cmd ending | ||
| 173 | +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" | ||
| 174 | +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" | ||
| 175 | +:skipRcPost | ||
| 176 | + | ||
| 177 | +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' | ||
| 178 | +if "%MAVEN_BATCH_PAUSE%" == "on" pause | ||
| 179 | + | ||
| 180 | +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% | ||
| 181 | + | ||
| 182 | +exit /B %ERROR_CODE% |
pom.xml
0 → 100644
| 1 | +++ a/pom.xml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 4 | + <modelVersion>4.0.0</modelVersion> | ||
| 5 | + <parent> | ||
| 6 | + <groupId>org.springframework.boot</groupId> | ||
| 7 | + <artifactId>spring-boot-starter-parent</artifactId> | ||
| 8 | + <version>2.4.0</version> | ||
| 9 | + <relativePath/> <!-- lookup parent from repository --> | ||
| 10 | + </parent> | ||
| 11 | + <groupId>com.bsth</groupId> | ||
| 12 | + <artifactId>luban_springboot2</artifactId> | ||
| 13 | + <version>0.0.1-SNAPSHOT</version> | ||
| 14 | + <packaging>war</packaging> | ||
| 15 | + <name>luban_springboot2</name> | ||
| 16 | + <description> | ||
| 17 | + 鲁班h5编辑器后台修正成springboot2的项目, | ||
| 18 | + 参考https://github.com/luban-h5/springboot2-jpa-api-for-luban | ||
| 19 | + </description> | ||
| 20 | + | ||
| 21 | + <properties> | ||
| 22 | + <java.version>1.8</java.version> | ||
| 23 | + </properties> | ||
| 24 | + | ||
| 25 | + <dependencies> | ||
| 26 | + <dependency> | ||
| 27 | + <groupId>org.springframework.boot</groupId> | ||
| 28 | + <artifactId>spring-boot-starter-data-jdbc</artifactId> | ||
| 29 | + </dependency> | ||
| 30 | + <dependency> | ||
| 31 | + <groupId>org.springframework.boot</groupId> | ||
| 32 | + <artifactId>spring-boot-starter-data-jpa</artifactId> | ||
| 33 | + </dependency> | ||
| 34 | + <dependency> | ||
| 35 | + <groupId>org.springframework.boot</groupId> | ||
| 36 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 37 | + </dependency> | ||
| 38 | + | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>mysql</groupId> | ||
| 41 | + <artifactId>mysql-connector-java</artifactId> | ||
| 42 | + <scope>runtime</scope> | ||
| 43 | + </dependency> | ||
| 44 | + <dependency> | ||
| 45 | + <groupId>org.springframework.boot</groupId> | ||
| 46 | + <artifactId>spring-boot-starter-tomcat</artifactId> | ||
| 47 | + <scope>provided</scope> | ||
| 48 | + </dependency> | ||
| 49 | + <dependency> | ||
| 50 | + <groupId>org.springframework.boot</groupId> | ||
| 51 | + <artifactId>spring-boot-starter-test</artifactId> | ||
| 52 | + <scope>test</scope> | ||
| 53 | + </dependency> | ||
| 54 | + <dependency> | ||
| 55 | + <groupId>com.h2database</groupId> | ||
| 56 | + <artifactId>h2</artifactId> | ||
| 57 | + <scope>test</scope> | ||
| 58 | + </dependency> | ||
| 59 | + <dependency> | ||
| 60 | + <groupId>org.dbunit</groupId> | ||
| 61 | + <artifactId>dbunit</artifactId> | ||
| 62 | + <version>2.4.9</version> | ||
| 63 | + <scope>test</scope> | ||
| 64 | + <exclusions> | ||
| 65 | + <exclusion> | ||
| 66 | + <groupId>junit</groupId> | ||
| 67 | + <artifactId>junit</artifactId> | ||
| 68 | + </exclusion> | ||
| 69 | + </exclusions> | ||
| 70 | + </dependency> | ||
| 71 | + | ||
| 72 | + <dependency> | ||
| 73 | + <groupId>org.projectlombok</groupId> | ||
| 74 | + <artifactId>lombok</artifactId> | ||
| 75 | + <scope>provided</scope> | ||
| 76 | + </dependency> | ||
| 77 | + | ||
| 78 | + <dependency> | ||
| 79 | + <groupId>org.hibernate.validator</groupId> | ||
| 80 | + <artifactId>hibernate-validator</artifactId> | ||
| 81 | + </dependency> | ||
| 82 | + | ||
| 83 | + </dependencies> | ||
| 84 | + | ||
| 85 | + <build> | ||
| 86 | + <plugins> | ||
| 87 | + <plugin> | ||
| 88 | + <groupId>org.springframework.boot</groupId> | ||
| 89 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 90 | + </plugin> | ||
| 91 | + </plugins> | ||
| 92 | + </build> | ||
| 93 | + | ||
| 94 | +</project> |
src/main/java/com/bsth/luban_springboot2/LubanSpringboot2Application.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/LubanSpringboot2Application.java | ||
| 1 | +package com.bsth.luban_springboot2; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.SpringApplication; | ||
| 4 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 5 | + | ||
| 6 | +@SpringBootApplication | ||
| 7 | +public class LubanSpringboot2Application { | ||
| 8 | + | ||
| 9 | + public static void main(String[] args) { | ||
| 10 | + SpringApplication.run(LubanSpringboot2Application.class, args); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | +} |
src/main/java/com/bsth/luban_springboot2/ServletInitializer.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/ServletInitializer.java | ||
| 1 | +package com.bsth.luban_springboot2; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.builder.SpringApplicationBuilder; | ||
| 4 | +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
| 5 | + | ||
| 6 | +public class ServletInitializer extends SpringBootServletInitializer { | ||
| 7 | + | ||
| 8 | + @Override | ||
| 9 | + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
| 10 | + return application.sources(LubanSpringboot2Application.class); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | +} |
src/main/java/com/bsth/luban_springboot2/controller/WorkController.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/controller/WorkController.java | ||
| 1 | +package com.bsth.luban_springboot2.controller; | ||
| 2 | + | ||
| 3 | +import com.bsth.luban_springboot2.dto.WorkDto; | ||
| 4 | +import com.bsth.luban_springboot2.dto.request.WorkCreateRequest; | ||
| 5 | +import com.bsth.luban_springboot2.dto.request.WorkQueryRequest; | ||
| 6 | +import com.bsth.luban_springboot2.dto.request.WorkUpdateRequest; | ||
| 7 | +import com.bsth.luban_springboot2.service.WorkService; | ||
| 8 | +import org.springframework.beans.BeanUtils; | ||
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | +import org.springframework.data.domain.Page; | ||
| 11 | +import org.springframework.data.domain.Pageable; | ||
| 12 | +import org.springframework.data.domain.Sort; | ||
| 13 | +import org.springframework.data.web.PageableDefault; | ||
| 14 | +import org.springframework.http.HttpStatus; | ||
| 15 | +import org.springframework.web.bind.annotation.*; | ||
| 16 | + | ||
| 17 | +import javax.validation.Valid; | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 作品控制器(和鲁班h5后台strapi.js保持一致)。 | ||
| 22 | + * TODO:swagger标注后面再加 | ||
| 23 | + */ | ||
| 24 | +@RestController | ||
| 25 | +@RequestMapping(value = "/works") | ||
| 26 | +public class WorkController { | ||
| 27 | + @Autowired | ||
| 28 | + private WorkService workService; | ||
| 29 | + | ||
| 30 | + // 根据workId查询 | ||
| 31 | + @RequestMapping(value = "/{id}", method = RequestMethod.GET) | ||
| 32 | + public WorkDto findWorkById(@PathVariable Long id) { | ||
| 33 | + return this.workService.findWorkById(id); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + // 查询所有work | ||
| 37 | + @RequestMapping(method = RequestMethod.GET) | ||
| 38 | + public List<WorkDto> listAllWorks(@Valid @ModelAttribute WorkQueryRequest request) { | ||
| 39 | + WorkDto workDto = new WorkDto(); | ||
| 40 | + workDto.setTemplate(Boolean.valueOf(request.getIs_template())); | ||
| 41 | + BeanUtils.copyProperties(request, workDto); | ||
| 42 | + return this.workService.listAllWorks(workDto); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + // 分页查询work | ||
| 46 | + @RequestMapping(value = "/pageable", method = RequestMethod.GET) | ||
| 47 | + public Page<WorkDto> listWorks( | ||
| 48 | + @Valid @ModelAttribute WorkQueryRequest request, | ||
| 49 | + @PageableDefault(sort = {"createTime"}, direction = Sort.Direction.DESC) Pageable pageable) { | ||
| 50 | + WorkDto workDto = new WorkDto(); | ||
| 51 | + workDto.setTemplate(Boolean.valueOf(request.getIs_template())); | ||
| 52 | + BeanUtils.copyProperties(request, workDto); | ||
| 53 | + return this.workService.listWorks(workDto, pageable); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + // 创建work | ||
| 57 | + @RequestMapping(method = RequestMethod.POST) | ||
| 58 | + @ResponseStatus(HttpStatus.OK) | ||
| 59 | + public WorkDto createWork(@RequestBody @Valid WorkCreateRequest request) { | ||
| 60 | + WorkDto workDto = new WorkDto(); | ||
| 61 | + BeanUtils.copyProperties(request, workDto); | ||
| 62 | + return workService.createWork(workDto); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + // 更新work | ||
| 66 | + @RequestMapping(value = "/{id}", method = RequestMethod.PUT) | ||
| 67 | + @ResponseStatus(HttpStatus.OK) | ||
| 68 | + public WorkDto updateWork(@PathVariable Long id, @RequestBody @Valid WorkUpdateRequest request) { | ||
| 69 | + WorkDto workDto = new WorkDto(); | ||
| 70 | + workDto.setId(id); | ||
| 71 | + BeanUtils.copyProperties(request, workDto); | ||
| 72 | + return workService.updateWork(workDto); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + // 删除work | ||
| 76 | + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) | ||
| 77 | + public void deleteWorkById(@PathVariable Long id) { | ||
| 78 | + this.workService.deleteWorkById(id); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + // 设置为模版 | ||
| 82 | + @RequestMapping(value = "/set-as-template/{id}", method = RequestMethod.POST) | ||
| 83 | + public WorkDto markWorkAsTemplate(@PathVariable Long id) { | ||
| 84 | + return this.workService.markWorkAsTemplate(id); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + // 作品数量 | ||
| 88 | + @RequestMapping(value = "/count", method = RequestMethod.GET) | ||
| 89 | + public Long countWork() { | ||
| 90 | + return this.workService.countWork(); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + // 使用模版创建作品 | ||
| 94 | + @RequestMapping(value = "/use-template/{id}", method = RequestMethod.POST) | ||
| 95 | + public WorkDto useTemplate(@PathVariable Long id) { | ||
| 96 | + return this.workService.useTemplate(id); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | +} |
src/main/java/com/bsth/luban_springboot2/dto/WorkDto.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/dto/WorkDto.java | ||
| 1 | +package com.bsth.luban_springboot2.dto; | ||
| 2 | + | ||
| 3 | +import com.bsth.luban_springboot2.entity.Work; | ||
| 4 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 5 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 7 | +import org.springframework.beans.BeanUtils; | ||
| 8 | +import org.springframework.beans.BeanWrapper; | ||
| 9 | +import org.springframework.beans.BeanWrapperImpl; | ||
| 10 | +import org.springframework.util.CollectionUtils; | ||
| 11 | +import org.springframework.util.StringUtils; | ||
| 12 | + | ||
| 13 | +import java.io.Serializable; | ||
| 14 | +import java.util.Date; | ||
| 15 | +import java.util.HashSet; | ||
| 16 | +import java.util.List; | ||
| 17 | +import java.util.Set; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * 作品Dto。 | ||
| 21 | + */ | ||
| 22 | +public class WorkDto implements Serializable { | ||
| 23 | + private static final long serialVersionUID = -8340849614408314674L; | ||
| 24 | + | ||
| 25 | + /** 作品Id */ | ||
| 26 | + private Long id; | ||
| 27 | + /** 作品标题 */ | ||
| 28 | + private String title; | ||
| 29 | + /** 作品描述 */ | ||
| 30 | + private String description; | ||
| 31 | + /** 封面图片url */ | ||
| 32 | + private String coverImageUrl; | ||
| 33 | + /** 放置作品的json array */ | ||
| 34 | + private List<Object> pages; | ||
| 35 | + /** 创建时间 */ | ||
| 36 | + private Date createTime; | ||
| 37 | + /** 更新时间 */ | ||
| 38 | + private Date updateTime; | ||
| 39 | + /** 是否已经发布 */ | ||
| 40 | + private Boolean publish; | ||
| 41 | + /** 是否是模版 */ | ||
| 42 | + private Boolean template; | ||
| 43 | + | ||
| 44 | + public Long getId() { | ||
| 45 | + return id; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setId(Long id) { | ||
| 49 | + this.id = id; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public String getTitle() { | ||
| 53 | + return title; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setTitle(String title) { | ||
| 57 | + this.title = title; | ||
| 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 getCoverImageUrl() { | ||
| 69 | + return coverImageUrl; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setCoverImageUrl(String coverImageUrl) { | ||
| 73 | + this.coverImageUrl = coverImageUrl; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public List<Object> getPages() { | ||
| 77 | + return pages; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setPages(List<Object> pages) { | ||
| 81 | + this.pages = pages; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public Date getCreateTime() { | ||
| 85 | + return createTime; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public void setCreateTime(Date createTime) { | ||
| 89 | + this.createTime = createTime; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public Date getUpdateTime() { | ||
| 93 | + return updateTime; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setUpdateTime(Date updateTime) { | ||
| 97 | + this.updateTime = updateTime; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public Boolean getPublish() { | ||
| 101 | + return publish; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setPublish(Boolean publish) { | ||
| 105 | + this.publish = publish; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public Boolean getTemplate() { | ||
| 109 | + return template; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public void setTemplate(Boolean template) { | ||
| 113 | + this.template = template; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public WorkDto() {} | ||
| 117 | + public WorkDto(Builder builder) { | ||
| 118 | + this.id = builder.id; | ||
| 119 | + this.title = builder.title; | ||
| 120 | + this.description = builder.description; | ||
| 121 | + this.coverImageUrl = builder.coverImageUrl; | ||
| 122 | + this.pages = builder.pages; | ||
| 123 | + this.createTime = builder.createTime; | ||
| 124 | + this.updateTime = builder.updateTime; | ||
| 125 | + this.publish = builder.publish; | ||
| 126 | + this.template = builder.template; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * 转换成Work对象。 | ||
| 131 | + * @param workDto | ||
| 132 | + * @return | ||
| 133 | + */ | ||
| 134 | + public static Work toWork(WorkDto workDto) { | ||
| 135 | + Work work = new Work(); | ||
| 136 | + BeanUtils.copyProperties(workDto, work); | ||
| 137 | + if (!CollectionUtils.isEmpty(workDto.getPages())) { | ||
| 138 | + ObjectMapper objectMapper = new ObjectMapper(); | ||
| 139 | + try { | ||
| 140 | + work.setPages(objectMapper.writeValueAsString(workDto.getPages())); | ||
| 141 | + } catch (JsonProcessingException exp) { | ||
| 142 | + exp.printStackTrace(); | ||
| 143 | + | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + } | ||
| 147 | + return work; | ||
| 148 | + } | ||
| 149 | + public static Builder getBuilder() { | ||
| 150 | + return new Builder(); | ||
| 151 | + } | ||
| 152 | + public static class Builder { | ||
| 153 | + /** 作品Id */ | ||
| 154 | + private Long id; | ||
| 155 | + /** 作品标题 */ | ||
| 156 | + private String title; | ||
| 157 | + /** 作品描述 */ | ||
| 158 | + private String description; | ||
| 159 | + /** 封面图片url */ | ||
| 160 | + private String coverImageUrl; | ||
| 161 | + /** 放置作品的json array */ | ||
| 162 | + private List<Object> pages; | ||
| 163 | + /** 创建时间 */ | ||
| 164 | + private Date createTime; | ||
| 165 | + /** 更新时间 */ | ||
| 166 | + private Date updateTime; | ||
| 167 | + /** 是否已经发布 */ | ||
| 168 | + private Boolean publish; | ||
| 169 | + /** 是否是模版 */ | ||
| 170 | + private Boolean template; | ||
| 171 | + | ||
| 172 | + public Builder setId(Long id) { | ||
| 173 | + this.id = id; | ||
| 174 | + return this; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + public Builder setTitle(String title) { | ||
| 178 | + this.title = title; | ||
| 179 | + return this; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + public Builder setDescription(String description) { | ||
| 183 | + this.description = description; | ||
| 184 | + return this; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + public Builder setCoverImageUrl(String coverImageUrl) { | ||
| 188 | + this.coverImageUrl = coverImageUrl; | ||
| 189 | + return this; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public Builder setPages(List<Object> pages) { | ||
| 193 | + this.pages = pages; | ||
| 194 | + return this; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + public Builder setCreateTime(Date createTime) { | ||
| 198 | + this.createTime = createTime; | ||
| 199 | + return this; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + public Builder setUpdateTime(Date updateTime) { | ||
| 203 | + this.updateTime = updateTime; | ||
| 204 | + return this; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + public Builder setPublish(Boolean publish) { | ||
| 208 | + this.publish = publish; | ||
| 209 | + return this; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + public Builder setTemplate(Boolean template) { | ||
| 213 | + this.template = template; | ||
| 214 | + return this; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * 使用work对象直接复制属性。 | ||
| 219 | + * @param work | ||
| 220 | + * @return | ||
| 221 | + */ | ||
| 222 | + public Builder setPropertyFromWork(Work work) { | ||
| 223 | + setPropertyFromWork(work, false); | ||
| 224 | + return this; | ||
| 225 | + } | ||
| 226 | + /** | ||
| 227 | + * 使用work对象直接复制属性(忽略空值属性)。 | ||
| 228 | + * @param work | ||
| 229 | + * @return | ||
| 230 | + */ | ||
| 231 | + public Builder setPropertyFromWorkIgnoreNullProperties(Work work) { | ||
| 232 | + setPropertyFromWork(work, true); | ||
| 233 | + return this; | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + private void setPropertyFromWork(Work work, boolean ignoreNullProperties) { | ||
| 237 | + if (ignoreNullProperties) { | ||
| 238 | + // 查找空值属性名数组 | ||
| 239 | + final BeanWrapper src = new BeanWrapperImpl(work); | ||
| 240 | + java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); | ||
| 241 | + Set emptyNames = new HashSet(); | ||
| 242 | + for(java.beans.PropertyDescriptor pd : pds) { | ||
| 243 | + //check if value of this property is null then add it to the collection | ||
| 244 | + Object srcValue = src.getPropertyValue(pd.getName()); | ||
| 245 | + if (srcValue == null) { | ||
| 246 | + emptyNames.add(pd.getName()); | ||
| 247 | + } | ||
| 248 | + } | ||
| 249 | + String[] result = new String[emptyNames.size()]; | ||
| 250 | + BeanUtils.copyProperties(work, this, (String[]) emptyNames.toArray(result)); | ||
| 251 | + | ||
| 252 | + } else { | ||
| 253 | + BeanUtils.copyProperties(work, this); | ||
| 254 | + } | ||
| 255 | + if (!StringUtils.hasText(work.getPages())) { | ||
| 256 | + ObjectMapper objectMapper = new ObjectMapper(); | ||
| 257 | + TypeReference<List<Object>> type = new TypeReference<List<Object>>() {}; | ||
| 258 | + try { | ||
| 259 | + List<Object> pages = objectMapper.readValue(work.getPages(), type); | ||
| 260 | + this.pages = pages; | ||
| 261 | + } catch (JsonProcessingException exp) { | ||
| 262 | + exp.printStackTrace(); | ||
| 263 | + | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + } | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + public WorkDto build() { | ||
| 270 | + return new WorkDto(this); | ||
| 271 | + } | ||
| 272 | + } | ||
| 273 | +} |
src/main/java/com/bsth/luban_springboot2/dto/request/WorkCreateRequest.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/dto/request/WorkCreateRequest.java | ||
| 1 | +package com.bsth.luban_springboot2.dto.request; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import java.util.Date; | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 作品创建请求(类似WorkDto) | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class WorkCreateRequest { | ||
| 13 | + private String title; | ||
| 14 | + | ||
| 15 | + private String description; | ||
| 16 | + | ||
| 17 | + private String coverImageUrl; | ||
| 18 | + | ||
| 19 | + private List<Object> pages; | ||
| 20 | + | ||
| 21 | + private Date createTime = new Date(); | ||
| 22 | + | ||
| 23 | + private Date updateTime = new Date(); | ||
| 24 | + | ||
| 25 | + private boolean publish = false; | ||
| 26 | + | ||
| 27 | + private boolean template = false; | ||
| 28 | +} |
src/main/java/com/bsth/luban_springboot2/dto/request/WorkQueryRequest.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/dto/request/WorkQueryRequest.java | ||
| 1 | +package com.bsth.luban_springboot2.dto.request; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import java.util.Date; | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 作品查询请求对象(类似WorkDto)。 | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class WorkQueryRequest { | ||
| 13 | + private String title; | ||
| 14 | + | ||
| 15 | + private String description; | ||
| 16 | + | ||
| 17 | + private String coverImageUrl; | ||
| 18 | + | ||
| 19 | + private List<Object> pages; | ||
| 20 | + | ||
| 21 | + private Date createTime; | ||
| 22 | + | ||
| 23 | + private Date updateTime; | ||
| 24 | + | ||
| 25 | + private String is_publish; | ||
| 26 | + | ||
| 27 | + private String is_template; | ||
| 28 | +} |
src/main/java/com/bsth/luban_springboot2/dto/request/WorkUpdateRequest.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/dto/request/WorkUpdateRequest.java | ||
| 1 | +package com.bsth.luban_springboot2.dto.request; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import java.util.Date; | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 作品更新请求(类似WorkDto)。 | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class WorkUpdateRequest { | ||
| 13 | + private String title; | ||
| 14 | + | ||
| 15 | + private String description; | ||
| 16 | + | ||
| 17 | + private String coverImageUrl; | ||
| 18 | + | ||
| 19 | + private List<Object> pages; | ||
| 20 | + | ||
| 21 | + private Date updateTime = new Date(); | ||
| 22 | + | ||
| 23 | + private boolean publish; | ||
| 24 | + | ||
| 25 | + private boolean template; | ||
| 26 | +} |
src/main/java/com/bsth/luban_springboot2/entity/Work.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/entity/Work.java | ||
| 1 | +package com.bsth.luban_springboot2.entity; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import javax.persistence.*; | ||
| 6 | +import java.io.Serializable; | ||
| 7 | +import java.util.Date; | ||
| 8 | +import java.util.HashSet; | ||
| 9 | +import java.util.Set; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 作品entity。 | ||
| 13 | + * 手动sql(注意:pages是json字段类型,mysql5.7及以上才能使用,以下使用longtext代替): | ||
| 14 | + * DROP TABLE IF EXISTS `work`; | ||
| 15 | + * CREATE TABLE `work` ( | ||
| 16 | + * `id` bigint(20) NOT NULL AUTO_INCREMENT, | ||
| 17 | + * `title` varchar(255) NOT NULL COMMENT '标题', | ||
| 18 | + * `description` longtext COMMENT '描述', | ||
| 19 | + * `cover_image_url` longtext, | ||
| 20 | + * `pages` json DEFAULT NULL, | ||
| 21 | + * `publish` tinyint(1) NOT NULL DEFAULT '0', | ||
| 22 | + * `template` tinyint(1) NOT NULL DEFAULT '0', | ||
| 23 | + * `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 24 | + * `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 25 | + * PRIMARY KEY (`id`) | ||
| 26 | + * ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8; | ||
| 27 | + * | ||
| 28 | + * pages字段值示例:TODO | ||
| 29 | + */ | ||
| 30 | +@Data | ||
| 31 | +@Entity | ||
| 32 | +@Table(name = "work") | ||
| 33 | +public class Work implements Serializable { | ||
| 34 | + private static final long serialVersionUID = -7998068854237393822L; | ||
| 35 | + | ||
| 36 | + /** 轮播信息Id */ | ||
| 37 | + @Id | ||
| 38 | + @GeneratedValue(strategy = GenerationType.AUTO) | ||
| 39 | + @Column(length = 11) | ||
| 40 | + private Long id; | ||
| 41 | + | ||
| 42 | + /** 标题 */ | ||
| 43 | + @Column(nullable = false) | ||
| 44 | + private String title; | ||
| 45 | + | ||
| 46 | + /** 描述 */ | ||
| 47 | + @Lob | ||
| 48 | + private String description; | ||
| 49 | + | ||
| 50 | + /** 封面图片url */ | ||
| 51 | + @Lob | ||
| 52 | + private String coverImageUrl; | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 放置作品的json字符串 | ||
| 56 | + * 注意:如果使用mysql5.7或以上版本,表字段可以是json字段类型,这里的映射就不用@Lob,用@Column | ||
| 57 | + * mysql5.7以下没有json字段类型,使用@Lob映射到longtext类型代替 | ||
| 58 | + */ | ||
| 59 | + @Lob | ||
| 60 | + private String pages; | ||
| 61 | + | ||
| 62 | + /** 创建时间 */ | ||
| 63 | + @Temporal(TemporalType.TIMESTAMP) | ||
| 64 | + @Column(nullable = false) | ||
| 65 | + private Date createTime = new Date(); | ||
| 66 | + | ||
| 67 | + /** 更新时间 */ | ||
| 68 | + @Temporal(TemporalType.TIMESTAMP) | ||
| 69 | + @Column(nullable = false) | ||
| 70 | + private Date updateTime = new Date(); | ||
| 71 | + | ||
| 72 | + /** 是否已经发布 */ | ||
| 73 | + @Column(nullable = false) | ||
| 74 | + private Boolean publish = Boolean.FALSE; | ||
| 75 | + | ||
| 76 | + /** 是否是模版 */ | ||
| 77 | + @Column(nullable = false) | ||
| 78 | + private Boolean template = Boolean.FALSE; | ||
| 79 | + | ||
| 80 | + //-------------------- 关联对象 -------------------// | ||
| 81 | + /** 关联的表单列表 */ | ||
| 82 | + @OneToMany(mappedBy = "work", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) | ||
| 83 | + @org.hibernate.annotations.ForeignKey(name = "none") | ||
| 84 | + private Set<WorkForm> workForms = new HashSet<>(); | ||
| 85 | + | ||
| 86 | +} |
src/main/java/com/bsth/luban_springboot2/entity/WorkForm.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/entity/WorkForm.java | ||
| 1 | +package com.bsth.luban_springboot2.entity; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import javax.persistence.*; | ||
| 6 | +import java.io.Serializable; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 表单entity。 | ||
| 10 | + * 手动sql: | ||
| 11 | + * DROP TABLE IF EXISTS `work_forms`; | ||
| 12 | + * CREATE TABLE `work_forms` ( | ||
| 13 | + * `id` bigint(20) NOT NULL AUTO_INCREMENT, | ||
| 14 | + * `form` longtext, | ||
| 15 | + * `work_id` bigint(20) NOT NULL, | ||
| 16 | + * PRIMARY KEY (`id`), | ||
| 17 | + * KEY `work_id` (`work_id`), | ||
| 18 | + * CONSTRAINT `work_forms_ibfk_1` FOREIGN KEY (`work_id`) REFERENCES `work` (`id`) | ||
| 19 | + * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
| 20 | + * | ||
| 21 | + * form示例: | ||
| 22 | + * { | ||
| 23 | + * "11": "张三", // 姓名 | ||
| 24 | + * "22": 18, // 年龄 | ||
| 25 | + * "33": "工程师" // 角色 | ||
| 26 | + * } | ||
| 27 | + */ | ||
| 28 | +@Data | ||
| 29 | +@Entity | ||
| 30 | +@Table(name = "work_forms") | ||
| 31 | +public class WorkForm implements Serializable { | ||
| 32 | + private static final long serialVersionUID = -3981275905628697501L; | ||
| 33 | + | ||
| 34 | + /** 主健 */ | ||
| 35 | + @Id | ||
| 36 | + @GeneratedValue(strategy = GenerationType.AUTO) | ||
| 37 | + private Long id; | ||
| 38 | + | ||
| 39 | + /** 一条表单记录 */ | ||
| 40 | + @Lob | ||
| 41 | + private String form; | ||
| 42 | + | ||
| 43 | + //----------------- 关联的对象 ---------------// | ||
| 44 | + /** 关联的作品 */ | ||
| 45 | + @ManyToOne(fetch = FetchType.LAZY) | ||
| 46 | + @JoinColumn(name = "work_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) | ||
| 47 | + private Work work; | ||
| 48 | + | ||
| 49 | +} |
src/main/java/com/bsth/luban_springboot2/repo/BaseRepository.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/repo/BaseRepository.java | ||
| 1 | +package com.bsth.luban_springboot2.repo; | ||
| 2 | + | ||
| 3 | +import org.springframework.data.jpa.repository.JpaRepository; | ||
| 4 | +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 5 | +import org.springframework.data.repository.NoRepositoryBean; | ||
| 6 | + | ||
| 7 | +import java.io.Serializable; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 基础仓库接口。 | ||
| 11 | + * @param <T> 实体类类型。 | ||
| 12 | + * @param <ID> 实体主键类型。 | ||
| 13 | + */ | ||
| 14 | +@NoRepositoryBean | ||
| 15 | +public interface BaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> { | ||
| 16 | + | ||
| 17 | +} |
src/main/java/com/bsth/luban_springboot2/repo/WorkRepo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/repo/WorkRepo.java | ||
| 1 | +package com.bsth.luban_springboot2.repo; | ||
| 2 | + | ||
| 3 | +import com.bsth.luban_springboot2.entity.Work; | ||
| 4 | +import org.springframework.stereotype.Repository; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 作品Repo。 | ||
| 8 | + */ | ||
| 9 | +@Repository | ||
| 10 | +public interface WorkRepo extends BaseRepository<Work, Long> { | ||
| 11 | +} |
src/main/java/com/bsth/luban_springboot2/service/WorkService.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/service/WorkService.java | ||
| 1 | +package com.bsth.luban_springboot2.service; | ||
| 2 | + | ||
| 3 | +import com.bsth.luban_springboot2.dto.WorkDto; | ||
| 4 | +import org.springframework.data.domain.Page; | ||
| 5 | +import org.springframework.data.domain.Pageable; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 作品Service。 | ||
| 11 | + */ | ||
| 12 | +public interface WorkService { | ||
| 13 | + /** | ||
| 14 | + * 查询所有work列表。 | ||
| 15 | + * @param workDto | ||
| 16 | + * @return | ||
| 17 | + */ | ||
| 18 | + List<WorkDto> listAllWorks(WorkDto workDto); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 分页查收work列表。 | ||
| 22 | + * @param workDto | ||
| 23 | + * @param pageable | ||
| 24 | + * @return | ||
| 25 | + */ | ||
| 26 | + Page<WorkDto> listWorks(WorkDto workDto, Pageable pageable); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 创建work。 | ||
| 30 | + * @param workDto | ||
| 31 | + * @return | ||
| 32 | + */ | ||
| 33 | + WorkDto createWork(WorkDto workDto); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 更新work。 | ||
| 37 | + * @param workDto | ||
| 38 | + * @return | ||
| 39 | + */ | ||
| 40 | + WorkDto updateWork(WorkDto workDto); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 根据Id查询work。 | ||
| 44 | + * @param id | ||
| 45 | + * @return | ||
| 46 | + */ | ||
| 47 | + WorkDto findWorkById(Long id); | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 根据Id删除work。 | ||
| 51 | + * @param id | ||
| 52 | + */ | ||
| 53 | + void deleteWorkById(Long id); | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 设置work为模版。 | ||
| 57 | + * @param id | ||
| 58 | + * @return | ||
| 59 | + */ | ||
| 60 | + WorkDto markWorkAsTemplate(Long id); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * work总数。 | ||
| 64 | + * @return | ||
| 65 | + */ | ||
| 66 | + Long countWork(); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 使用workId创建一个新的work。 | ||
| 70 | + * @param id | ||
| 71 | + * @return | ||
| 72 | + */ | ||
| 73 | + WorkDto useTemplate(Long id); | ||
| 74 | +} |
src/main/java/com/bsth/luban_springboot2/service/impl/WorkServiceImpl.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/service/impl/WorkServiceImpl.java | ||
| 1 | +package com.bsth.luban_springboot2.service.impl; | ||
| 2 | + | ||
| 3 | +import com.bsth.luban_springboot2.dto.WorkDto; | ||
| 4 | +import com.bsth.luban_springboot2.entity.Work; | ||
| 5 | +import com.bsth.luban_springboot2.repo.WorkRepo; | ||
| 6 | +import com.bsth.luban_springboot2.service.WorkService; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.data.domain.Example; | ||
| 9 | +import org.springframework.data.domain.Page; | ||
| 10 | +import org.springframework.data.domain.Pageable; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | +import org.springframework.transaction.annotation.Isolation; | ||
| 13 | +import org.springframework.transaction.annotation.Propagation; | ||
| 14 | +import org.springframework.transaction.annotation.Transactional; | ||
| 15 | + | ||
| 16 | +import java.util.Date; | ||
| 17 | +import java.util.List; | ||
| 18 | +import java.util.Optional; | ||
| 19 | +import java.util.stream.Collectors; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * 作品Service实现。 | ||
| 23 | + */ | ||
| 24 | +@Service | ||
| 25 | +public class WorkServiceImpl implements WorkService { | ||
| 26 | + @Autowired | ||
| 27 | + private WorkRepo workRepo; | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public List<WorkDto> listAllWorks(WorkDto workDto) { | ||
| 31 | + Work work = WorkDto.toWork(workDto); | ||
| 32 | + Example<Work> example = Example.of(work); | ||
| 33 | + List<Work> works = this.workRepo.findAll(example); | ||
| 34 | + List<WorkDto> workDtos = works.stream() | ||
| 35 | + .map(w -> WorkDto.getBuilder().setPropertyFromWork(w).build()) | ||
| 36 | + .collect(Collectors.toList()); | ||
| 37 | + return workDtos; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public Page<WorkDto> listWorks(WorkDto workDto, Pageable pageable) { | ||
| 42 | + // TODO:暂无业务驱动 | ||
| 43 | + | ||
| 44 | + return null; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | ||
| 49 | + public WorkDto createWork(WorkDto workDto) { | ||
| 50 | + Work work = WorkDto.toWork(workDto); | ||
| 51 | + work = this.workRepo.save(work); | ||
| 52 | + return WorkDto.getBuilder().setPropertyFromWork(work).build(); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | ||
| 57 | + public WorkDto updateWork(WorkDto workDto) { | ||
| 58 | + Optional<Work> optionalWork = this.workRepo.findById(workDto.getId()); | ||
| 59 | + Work work = optionalWork.isPresent() ? optionalWork.get() : null; | ||
| 60 | + if (work == null) { | ||
| 61 | + return null; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + WorkDto updateWorkDto = WorkDto | ||
| 65 | + .getBuilder() | ||
| 66 | + .setPropertyFromWorkIgnoreNullProperties(work) | ||
| 67 | + .setUpdateTime(new Date()) | ||
| 68 | + .build(); | ||
| 69 | + Work updateWork = WorkDto.toWork(updateWorkDto); | ||
| 70 | + updateWork = this.workRepo.save(updateWork); | ||
| 71 | + return WorkDto.getBuilder().setPropertyFromWork(updateWork).build(); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public WorkDto findWorkById(Long id) { | ||
| 76 | + Optional<Work> optionalWork = this.workRepo.findById(id); | ||
| 77 | + Work work = optionalWork.isPresent() ? optionalWork.get() : null; | ||
| 78 | + if (work == null) { | ||
| 79 | + return null; | ||
| 80 | + } else { | ||
| 81 | + return WorkDto.getBuilder().setPropertyFromWork(work).build(); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | ||
| 87 | + public void deleteWorkById(Long id) { | ||
| 88 | + this.workRepo.deleteById(id); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @Override | ||
| 92 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | ||
| 93 | + public WorkDto markWorkAsTemplate(Long id) { | ||
| 94 | + Optional<Work> optionalWork = this.workRepo.findById(id); | ||
| 95 | + Work work = optionalWork.isPresent() ? optionalWork.get() : null; | ||
| 96 | + if (work == null) { | ||
| 97 | + return null; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + work.setTemplate(true); | ||
| 101 | + work.setUpdateTime(new Date()); | ||
| 102 | + work = this.workRepo.save(work); | ||
| 103 | + return WorkDto.getBuilder().setPropertyFromWork(work).build(); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public Long countWork() { | ||
| 108 | + return this.workRepo.count(); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + @Override | ||
| 112 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | ||
| 113 | + public WorkDto useTemplate(Long id) { | ||
| 114 | + Optional<Work> optionalWork = this.workRepo.findById(id); | ||
| 115 | + Work work = optionalWork.isPresent() ? optionalWork.get() : null; | ||
| 116 | + if (work == null) { | ||
| 117 | + return null; | ||
| 118 | + } | ||
| 119 | + WorkDto templateWorkDto = WorkDto | ||
| 120 | + .getBuilder() | ||
| 121 | + .setPropertyFromWork(work) | ||
| 122 | + .setId(null) | ||
| 123 | + .setTemplate(false) | ||
| 124 | + .setPublish(false) | ||
| 125 | + .build(); | ||
| 126 | + Work newWork = WorkDto.toWork(templateWorkDto); | ||
| 127 | + newWork = this.workRepo.save(newWork); | ||
| 128 | + return WorkDto.getBuilder().setPropertyFromWork(newWork).build(); | ||
| 129 | + } | ||
| 130 | +} |
src/main/java/com/bsth/luban_springboot2/utils/MySQL5InnoDBDialectExt.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/luban_springboot2/utils/MySQL5InnoDBDialectExt.java | ||
| 1 | +package com.bsth.luban_springboot2.utils; | ||
| 2 | + | ||
| 3 | +import org.hibernate.dialect.InnoDBStorageEngine; | ||
| 4 | +import org.hibernate.dialect.MySQL5Dialect; | ||
| 5 | +import org.hibernate.dialect.MySQLStorageEngine; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * springBoot 2使用了新的mysql驱动类 com.mysql.cj.jdbc.Driver,和原来的比较会有一些问题 | ||
| 9 | + * 1、日期,默认保存日期会差12个小时,是时区问题,需要在数据库连接字符串上加 serverTimezone=GMT%2B8 | ||
| 10 | + * 2、默认创建表示使用的引擎是 MyIsam,默认的字符集为 latin1,需要在配置文件中设定 MySQL5Dialect,如下: | ||
| 11 | + * spring.jpa.database-platform=com.bsth.control_v3.plan_module.service.data_sync.vehicle.batch.MySQL5InnoDBDialectExt | ||
| 12 | + */ | ||
| 13 | +public class MySQL5InnoDBDialectExt extends MySQL5Dialect { | ||
| 14 | + @Override | ||
| 15 | + protected MySQLStorageEngine getDefaultMySQLStorageEngine() { | ||
| 16 | + return InnoDBStorageEngine.INSTANCE; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public String getTableTypeString() { | ||
| 21 | + return "ENGINE=InnoDB DEFAULT CHARSET=utf8"; | ||
| 22 | + } | ||
| 23 | +} | ||
| 0 | \ No newline at end of file | 24 | \ No newline at end of file |
src/main/resources/application-db.properties
0 → 100644
| 1 | +++ a/src/main/resources/application-db.properties | ||
| 1 | +#--- | ||
| 2 | +# h2 数据库配置 | ||
| 3 | +spring.config.activate.on-profile=h2_db_config | ||
| 4 | +# 数据库驱动 | ||
| 5 | +spring.datasource.driver-class-name=org.h2.Driver | ||
| 6 | +# 数据库url连接字符串 | ||
| 7 | +# h2 v1.4.200 不支持 mvcc了去除 | ||
| 8 | +# spring.datasource.url=jdbc:h2:mem:core;DB_CLOSE_DELAY=1000;MVCC=TRUE;LOCK_TIMEOUT=10000 | ||
| 9 | +spring.datasource.url=jdbc:h2:mem:core;DB_CLOSE_DELAY=1000;LOCK_TIMEOUT=10000 | ||
| 10 | +spring.datasource.username=sa | ||
| 11 | +spring.datasource.password= | ||
| 12 | +#--- | ||
| 13 | +# mysql 数据库配置 | ||
| 14 | +spring.config.activate.on-profile=mysql_db_config | ||
| 15 | +# 数据库url连接字符串 | ||
| 16 | +# serverTimezone参数解决数据库时区不一致的问题 | ||
| 17 | +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
| 18 | +spring.datasource.url=jdbc:mysql://127.0.0.1/lubanh5?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 | ||
| 19 | +spring.datasource.username=root | ||
| 20 | +spring.datasource.password= |
src/main/resources/application-ds.properties
0 → 100644
| 1 | +++ a/src/main/resources/application-ds.properties | ||
| 1 | +#--- | ||
| 2 | +# 数据库连接池配置 | ||
| 3 | +spring.config.activate.on-profile=ds_config | ||
| 4 | +# spring2.x默认使用HikariPool连接池 | ||
| 5 | +spring.datasource.hikari.maximum-pool-size=100 | ||
| 6 | +spring.datasource.hikari.minimum-idle=20 | ||
| 7 | +spring.datasource.hikari.connection-timeout=60000 | ||
| 8 | +spring.datasource.hikari.idle-timeout=60000 | ||
| 9 | +spring.datasource.hikari.validation-timeout=3000 | ||
| 10 | +spring.datasource.hikari.login-timeout=5 | ||
| 11 | +spring.datasource.hikari.max-lifetime=60000 |
src/main/resources/application-jpa.properties
0 → 100644
| 1 | +++ a/src/main/resources/application-jpa.properties | ||
| 1 | +#--- | ||
| 2 | +# h2 jpa配置 | ||
| 3 | +spring.config.activate.on-profile=h2_jpa_config | ||
| 4 | +# dialect | ||
| 5 | +spring.jpa.database= H2 | ||
| 6 | +# 是否显示sql,格式化sql,ddl schema是否更新 | ||
| 7 | +spring.jpa.properties.hibernate.show_sql= true | ||
| 8 | +spring.jpa.properties.hibernate.format_sql= true | ||
| 9 | +spring.jpa.properties.hibernate.hbm2ddl.auto = update | ||
| 10 | +# hibernate5的命名策略 | ||
| 11 | +spring.jpa.properties.hibernate.implicit_naming_strategy= org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy | ||
| 12 | +spring.jpa.properties.hibernate.physical_naming_strategy= org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy | ||
| 13 | +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect | ||
| 14 | +#--- | ||
| 15 | +# mysql jpa配置 | ||
| 16 | +spring.config.activate.on-profile=mysql_jpa_config | ||
| 17 | +# dialect | ||
| 18 | +spring.jpa.database= MYSQL | ||
| 19 | +# 是否显示sql,格式化sql,ddl schema是否更新 | ||
| 20 | +spring.jpa.properties.hibernate.show_sql= true | ||
| 21 | +spring.jpa.properties.hibernate.format_sql= true | ||
| 22 | +spring.jpa.properties.hibernate.hbm2ddl.auto= update | ||
| 23 | +# hibernate5的命名策略 | ||
| 24 | +spring.jpa.properties.hibernate.implicit_naming_strategy= org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy | ||
| 25 | +spring.jpa.properties.hibernate.physical_naming_strategy= org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy | ||
| 26 | +# 自定义MySQL方言(指定存储引擎和编码格式) | ||
| 27 | +spring.jpa.database-platform=com.bsth.luban_springboot2.utils.MySQL5InnoDBDialectExt |
src/main/resources/application.properties
0 → 100644
| 1 | +++ a/src/main/resources/application.properties | ||
| 1 | + | ||
| 2 | + | ||
| 3 | +#------------------ main profile 主配置 ----------------# | ||
| 4 | +# 内置tomcat启动端口 | ||
| 5 | +server.port=9008 | ||
| 6 | +# application名字 | ||
| 7 | +spring.application.name=luban_springboot2 | ||
| 8 | + | ||
| 9 | +# 关闭open session in view | ||
| 10 | +spring.jpa.open-in-view=false | ||
| 11 | + | ||
| 12 | +# spring2.4新增group功能,类似之前的include | ||
| 13 | +# 定义test group | ||
| 14 | +spring.profiles.group.test=db,h2_db_config,jpa,h2_jpa_config,ds,task | ||
| 15 | +# 定义prod group | ||
| 16 | +spring.profiles.group.prod=db,mysql_db_config,jpa,mysql_jpa_config,ds,task | ||
| 17 | + | ||
| 18 | +# 启动使用的profile(使用group) | ||
| 19 | +spring.profiles.active=test | ||
| 20 | + | ||
| 21 | +# hikari日志开关 | ||
| 22 | +logging.level.com.zaxxer.hikari.HikariConfig=DEBUG | ||
| 23 | +# logging.level.com.zaxxer.hikari=TRACE |
src/main/resources/logback-spring.xml
0 → 100644
| 1 | +++ a/src/main/resources/logback-spring.xml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!-- | ||
| 3 | + logback.xml加载早于application.properties,所以如果你在application.xml使用变量时, | ||
| 4 | + 而恰好这个变量是写在application.properties时,那么就会获取不到,只要改成logging-spring.xml就可以解决了。 | ||
| 5 | + | ||
| 6 | +--> | ||
| 7 | + | ||
| 8 | +<!-- scan="true" 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。 --> | ||
| 9 | +<!-- scanPeriod="30 seconds" 设置每30秒自动扫描,若没有指定具体单位则以milliseconds为标准(单位:milliseconds, seconds, minutes or hours) --> | ||
| 10 | +<!-- debug="false"当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。--> | ||
| 11 | +<configuration scan="true" scanPeriod="30 seconds"> | ||
| 12 | + <!-- 控制台输出 --> | ||
| 13 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| 14 | + <encoder> | ||
| 15 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> | ||
| 16 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n</pattern> | ||
| 17 | + </encoder> | ||
| 18 | + </appender> | ||
| 19 | + | ||
| 20 | + <!-- 日志输出级别 --> | ||
| 21 | + <logger name="org.hibernate.SQL" | ||
| 22 | + level="DEBUG" additivity="false"> | ||
| 23 | + <appender-ref ref="STDOUT" /> | ||
| 24 | + </logger> | ||
| 25 | + | ||
| 26 | + <logger name="com.xuxuan.hotel_service" | ||
| 27 | + level="DEBUG" additivity="false"> | ||
| 28 | + <appender-ref ref="STDOUT" /> | ||
| 29 | + </logger> | ||
| 30 | + | ||
| 31 | + <root level="INFO"> | ||
| 32 | + <appender-ref ref="STDOUT" /> | ||
| 33 | + </root> | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +</configuration> |
src/test/java/com/bsth/luban_springboot2/BaseTest_junit5.java
0 → 100644
| 1 | +++ a/src/test/java/com/bsth/luban_springboot2/BaseTest_junit5.java | ||
| 1 | +package com.bsth.luban_springboot2; | ||
| 2 | + | ||
| 3 | +import org.dbunit.database.DatabaseConfig; | ||
| 4 | +import org.dbunit.database.DatabaseConnection; | ||
| 5 | +import org.dbunit.database.DatabaseSequenceFilter; | ||
| 6 | +import org.dbunit.database.IDatabaseConnection; | ||
| 7 | +import org.dbunit.dataset.FilteredDataSet; | ||
| 8 | +import org.dbunit.dataset.IDataSet; | ||
| 9 | +import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; | ||
| 10 | +import org.dbunit.ext.h2.H2DataTypeFactory; | ||
| 11 | +import org.dbunit.operation.DatabaseOperation; | ||
| 12 | +import org.junit.jupiter.api.AfterEach; | ||
| 13 | +import org.junit.jupiter.api.BeforeEach; | ||
| 14 | +import org.junit.jupiter.api.TestInfo; | ||
| 15 | +import org.slf4j.Logger; | ||
| 16 | +import org.slf4j.LoggerFactory; | ||
| 17 | +import org.springframework.core.io.ClassPathResource; | ||
| 18 | +import org.springframework.core.io.Resource; | ||
| 19 | +import org.springframework.util.StringUtils; | ||
| 20 | + | ||
| 21 | +import javax.sql.DataSource; | ||
| 22 | +import java.util.Map; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * 基于junit5的基础测试类。 | ||
| 26 | + */ | ||
| 27 | +public abstract class BaseTest_junit5 { | ||
| 28 | + /** 日志记录器 */ | ||
| 29 | + public static final Logger LOG = LoggerFactory.getLogger(BaseTest_junit5.class); | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 初始化数据。 | ||
| 34 | + * @throws Exception | ||
| 35 | + */ | ||
| 36 | + @BeforeEach | ||
| 37 | + public void initDbunitDataSet(TestInfo testInfo) throws Exception { | ||
| 38 | + LOG.info("junit setup:dbunit-载入测试数据!===>"); | ||
| 39 | + IDatabaseConnection connection = getConnection(); | ||
| 40 | + DatabaseOperation.CLEAN_INSERT.execute(connection, getDataSet(testInfo)); | ||
| 41 | + connection.close(); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 销毁测试数据。 | ||
| 46 | + * @throws Exception | ||
| 47 | + */ | ||
| 48 | + @AfterEach | ||
| 49 | + public void afterDbunitDataSet() throws Exception { | ||
| 50 | + LOG.info("===>junit teardown:dbunit-销毁测试数据!"); | ||
| 51 | + IDatabaseConnection connection = getConnection(); | ||
| 52 | + // 使用FilteredDataSet重新定义数据库,否则删除的时候会发生外健依赖错误 | ||
| 53 | + // 因为默认删除是按照表名字母顺序删除的,如果外健关联的表先删除,则发生外健约束错误 | ||
| 54 | + IDataSet fullDataSet = new FilteredDataSet(new DatabaseSequenceFilter(connection), connection.createDataSet()); | ||
| 55 | + DatabaseOperation.DELETE_ALL.execute(getConnection(), fullDataSet); | ||
| 56 | + connection.close(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 获取数据库连接。 | ||
| 62 | + * @return | ||
| 63 | + */ | ||
| 64 | + private IDatabaseConnection getConnection() throws Exception { | ||
| 65 | + DatabaseConnection conn = new DatabaseConnection(getDataSource().getConnection()); | ||
| 66 | + DatabaseConfig config = conn.getConfig(); | ||
| 67 | + config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory()); | ||
| 68 | + return conn; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 获取DBUnit数据源。 | ||
| 73 | + */ | ||
| 74 | + private IDataSet getDataSet(TestInfo testInfo) throws Exception { | ||
| 75 | + Map<String, String> dbFileMap = getDbunitTestDbFileClassPathMap(); | ||
| 76 | + String methodName = testInfo.getTestMethod().get().getName(); | ||
| 77 | + String dbunitClassPath = dbFileMap.get(methodName); | ||
| 78 | + if (!StringUtils.hasText(dbunitClassPath)) { | ||
| 79 | + LOG.info("dbunit测试xml为空,key={}", methodName); | ||
| 80 | + } | ||
| 81 | + Resource res = new ClassPathResource(dbunitClassPath); | ||
| 82 | + FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); | ||
| 83 | + builder.setColumnSensing(true); | ||
| 84 | + return builder.build(res.getInputStream()); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 获取Dbunit测试数据文件xml映射,key=测试方法名,value=dbunit测试文件classpath | ||
| 89 | + * key:子类testCase方法名 | ||
| 90 | + * value:dbunit数据文件classpath(如:db/testdata/dbunit_testdata1.xml) | ||
| 91 | + */ | ||
| 92 | + public abstract Map<String, String> getDbunitTestDbFileClassPathMap(); | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 获取数据源。 | ||
| 96 | + */ | ||
| 97 | + public abstract DataSource getDataSource(); | ||
| 98 | + | ||
| 99 | +} |
src/test/java/com/bsth/luban_springboot2/LubanSpringboot2ServiceTests.java
0 → 100644
| 1 | +++ a/src/test/java/com/bsth/luban_springboot2/LubanSpringboot2ServiceTests.java | ||
| 1 | +package com.bsth.luban_springboot2; | ||
| 2 | + | ||
| 3 | +import org.junit.jupiter.api.DisplayName; | ||
| 4 | +import org.junit.jupiter.api.Test; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 7 | + | ||
| 8 | +import javax.sql.DataSource; | ||
| 9 | +import java.util.HashMap; | ||
| 10 | +import java.util.Map; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 鲁班h5springboot后台测试用例。 | ||
| 14 | + */ | ||
| 15 | +@SpringBootTest(classes = {LubanSpringboot2TestApplication.class}) | ||
| 16 | +class LubanSpringboot2ServiceTests extends BaseTest_junit5 { | ||
| 17 | + @Autowired | ||
| 18 | + private DataSource coreDataSource; | ||
| 19 | + @Override | ||
| 20 | + public DataSource getDataSource() { | ||
| 21 | + return coreDataSource; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public Map<String, String> getDbunitTestDbFileClassPathMap() { | ||
| 26 | + Map<String, String> dbFileMap = new HashMap<>(); | ||
| 27 | + dbFileMap.put("contextLoads", "testdata/contextLoads_test.xml"); | ||
| 28 | + return dbFileMap; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + @DisplayName("contextLoads测试项目启动是否异常,所有相关上下文都要初始化成功") | ||
| 32 | + @Test | ||
| 33 | + void contextLoads() { | ||
| 34 | + | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} |
src/test/java/com/bsth/luban_springboot2/LubanSpringboot2TestApplication.java
0 → 100644
| 1 | +++ a/src/test/java/com/bsth/luban_springboot2/LubanSpringboot2TestApplication.java | ||
| 1 | +package com.bsth.luban_springboot2; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.CommandLineRunner; | ||
| 4 | +import org.springframework.boot.SpringApplication; | ||
| 5 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 6 | +import org.springframework.context.annotation.ComponentScan; | ||
| 7 | +import org.springframework.context.annotation.FilterType; | ||
| 8 | +import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
| 9 | + | ||
| 10 | +@EnableTransactionManagement | ||
| 11 | +@SpringBootApplication | ||
| 12 | +@ComponentScan(excludeFilters = { | ||
| 13 | + @ComponentScan.Filter( | ||
| 14 | + type = FilterType.ASSIGNABLE_TYPE, | ||
| 15 | + value = { | ||
| 16 | + LubanSpringboot2Application.class | ||
| 17 | + } | ||
| 18 | + ) | ||
| 19 | +}) | ||
| 20 | +public class LubanSpringboot2TestApplication implements CommandLineRunner { | ||
| 21 | + @Override | ||
| 22 | + public void run(String... args) throws Exception { | ||
| 23 | + // TODO:其他初始化代码 | ||
| 24 | + | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public static void main(String[] args) throws Exception { | ||
| 28 | + SpringApplication.run(LubanSpringboot2TestApplication.class, args); | ||
| 29 | + } | ||
| 30 | +} |