├── springboot-core ├── groovy-joint │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ └── main │ │ ├── groovy │ │ └── grokwich │ │ │ └── springbootcore │ │ │ └── groovyjoint │ │ │ ├── GroovyJointApplication.groovy │ │ │ └── beans │ │ │ ├── GroovyBeanB.groovy │ │ │ ├── GroovyBeanD.groovy │ │ │ ├── JavaBeanA.java │ │ │ ├── JavaBeanC.java │ │ │ └── JointBean.groovy │ │ └── resources │ │ └── application.properties └── helloworld │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ ├── java │ │ └── grokwich │ │ │ └── springbootcore │ │ │ └── helloworld │ │ │ └── HelloworldApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── grokwich │ └── springbootcore │ └── helloworld │ └── HelloworldApplicationTests.java └── springboot-web ├── web-thymeleaf-JSR303-validation ├── .gitignore ├── README.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── groovy │ │ └── grokwich │ │ │ └── springboot │ │ │ └── web │ │ │ └── thymeleaf │ │ │ └── validation │ │ │ ├── WebThymeleafValidationApplication.java │ │ │ ├── command │ │ │ └── FormCommand.java │ │ │ └── controller │ │ │ └── FormController.java │ └── resources │ │ ├── ValidationMessages.properties │ │ ├── application.properties │ │ ├── messages.properties │ │ └── templates │ │ ├── fooForm.html │ │ └── fooResult.html │ └── test │ └── groovy │ └── grokwich │ └── springboot │ └── web │ └── thymeleaf │ └── validation │ └── WebThymeleafFormsApplicationTests.java └── web-thymeleaf-forms ├── .gitignore ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main ├── groovy │ └── grokwich │ │ └── springboot │ │ └── web │ │ └── thymeleaf │ │ └── forms │ │ ├── WebThymeleafFormsApplication.java │ │ ├── command │ │ └── FormCommand.java │ │ └── controller │ │ └── FormController.java └── resources │ ├── ValidationMessages.properties │ ├── application.properties │ ├── messages.properties │ └── templates │ ├── fooForm.html │ └── fooResult.html └── test └── groovy └── grokwich └── springboot └── web └── thymeleaf └── forms └── WebThymeleafFormsApplicationTests.java /springboot-core/groovy-joint/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | bin/ 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | .nb-gradle/ -------------------------------------------------------------------------------- /springboot-core/groovy-joint/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.7.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | apply plugin: 'groovy' 17 | 18 | group = 'grokwich.springboot-core' 19 | version = '0.0.1-SNAPSHOT' 20 | sourceCompatibility = 1.8 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter') 29 | compile('org.codehaus.groovy:groovy') 30 | 31 | runtime('org.springframework.boot:spring-boot-devtools') 32 | 33 | testCompile('org.springframework.boot:spring-boot-starter-test') 34 | } 35 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grokwich/spring-snacks/a6f29c5eec3e66db931f35b5069439a26b4e08a2/springboot-core/groovy-joint/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /springboot-core/groovy-joint/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/groovy/grokwich/springbootcore/groovyjoint/GroovyJointApplication.groovy: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.groovyjoint; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean 6 | 7 | import grokwich.springbootcore.groovyjoint.beans.GroovyBeanD 8 | 9 | 10 | @SpringBootApplication 11 | public class GroovyJointApplication { 12 | 13 | public static void main(String[] args) { 14 | def context = SpringApplication.run(GroovyJointApplication.class, args) 15 | 16 | def bean = context.getBean("beanX") 17 | 18 | println bean.msg() 19 | } 20 | 21 | 22 | @Bean 23 | def beanX() { 24 | return new GroovyBeanD() 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/groovy/grokwich/springbootcore/groovyjoint/beans/GroovyBeanB.groovy: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.groovyjoint.beans; 2 | 3 | class GroovyBeanB extends JavaBeanA { 4 | String msg() { 5 | "${super.msg()} > GroovyBeanB" 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/groovy/grokwich/springbootcore/groovyjoint/beans/GroovyBeanD.groovy: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.groovyjoint.beans; 2 | 3 | class GroovyBeanD extends JavaBeanC { 4 | String msg() { 5 | "${super.msg()} > GroovyBeanD" 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/groovy/grokwich/springbootcore/groovyjoint/beans/JavaBeanA.java: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.groovyjoint.beans; 2 | 3 | class JavaBeanA implements JointBean { 4 | public String msg() { 5 | return "JavaBeanA"; 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/groovy/grokwich/springbootcore/groovyjoint/beans/JavaBeanC.java: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.groovyjoint.beans; 2 | 3 | class JavaBeanC extends GroovyBeanB { 4 | public String msg() { 5 | return super.msg() + " > JavaBeanC"; 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/groovy/grokwich/springbootcore/groovyjoint/beans/JointBean.groovy: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.groovyjoint.beans 2 | 3 | interface JointBean { 4 | String msg() 5 | } 6 | 7 | -------------------------------------------------------------------------------- /springboot-core/groovy-joint/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grokwich/spring-snacks/a6f29c5eec3e66db931f35b5069439a26b4e08a2/springboot-core/groovy-joint/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot-core/helloworld/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | bin/ 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | .nb-gradle/ -------------------------------------------------------------------------------- /springboot-core/helloworld/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.7.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | group = 'grokwich.springboot-core' 18 | version = '0.0.1-SNAPSHOT' 19 | sourceCompatibility = 1.8 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | 26 | dependencies { 27 | compile('org.springframework.boot:spring-boot-starter') 28 | runtime('org.springframework.boot:spring-boot-devtools') 29 | testCompile('org.springframework.boot:spring-boot-starter-test') 30 | } 31 | -------------------------------------------------------------------------------- /springboot-core/helloworld/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grokwich/spring-snacks/a6f29c5eec3e66db931f35b5069439a26b4e08a2/springboot-core/helloworld/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /springboot-core/helloworld/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | -------------------------------------------------------------------------------- /springboot-core/helloworld/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /springboot-core/helloworld/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /springboot-core/helloworld/src/main/java/grokwich/springbootcore/helloworld/HelloworldApplication.java: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.helloworld; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.Bean; 7 | 8 | @SpringBootApplication 9 | public class HelloworldApplication { 10 | 11 | public static void main(String[] args) { 12 | ApplicationContext context = SpringApplication.run(HelloworldApplication.class, args); 13 | 14 | TestBean bean = context.getBean(TestBean.class); 15 | 16 | System.out.println( bean.getMessage() ); 17 | } 18 | 19 | static class TestBean { 20 | String getMessage() { 21 | return "Hello World!"; 22 | } 23 | } 24 | 25 | @Bean 26 | TestBean getBean() { 27 | return new TestBean(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-core/helloworld/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grokwich/spring-snacks/a6f29c5eec3e66db931f35b5069439a26b4e08a2/springboot-core/helloworld/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot-core/helloworld/src/test/java/grokwich/springbootcore/helloworld/HelloworldApplicationTests.java: -------------------------------------------------------------------------------- 1 | package grokwich.springbootcore.helloworld; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class HelloworldApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | bin/ 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | .nb-gradle/ -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/README.md: -------------------------------------------------------------------------------- 1 | # web-thymeleaf-JSR303-validation (Part #2) 2 | 3 | Snack-sample that demonstrates JSR303-validation (bean validation annotations). 4 | 5 | The Command pattern is used and most form elements have been demonstrated. 6 | 7 | ## Blog Discussion 8 | https://medium.com/@grokwich/spring-boot-thymeleaf-html-form-handling-part-2-b4c9e83a189c 9 | 10 | ## Validation error messages. 11 | 12 | The code demonstrates Validation message configuration options: 13 | * messages.properties vs. validationMessages.properties 14 | 15 | Recommendation is to use validationMessages.properties (JSR-303 native). 16 | Using (default) messages.properties will only provide simple localization message 17 | configuration for validation messages (only numeric param interpolation). 18 | 19 | ## Unit Tests 20 | MockMVC tests that demonstrate happy-case and expected validation errors. 21 | 22 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.7.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'groovy' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | group = 'grokwich.springboot-web' 18 | version = '0.0.1-SNAPSHOT' 19 | sourceCompatibility = 1.8 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | 26 | dependencies { 27 | compile('org.springframework.boot:spring-boot-starter-thymeleaf') 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | compile('org.codehaus.groovy:groovy') 30 | runtime('org.springframework.boot:spring-boot-devtools') 31 | compileOnly('org.projectlombok:lombok') 32 | testCompile('org.springframework.boot:spring-boot-starter-test') 33 | } 34 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grokwich/spring-snacks/a6f29c5eec3e66db931f35b5069439a26b4e08a2/springboot-web/web-thymeleaf-JSR303-validation/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/groovy/grokwich/springboot/web/thymeleaf/validation/WebThymeleafValidationApplication.java: -------------------------------------------------------------------------------- 1 | package grokwich.springboot.web.thymeleaf.validation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import grokwich.springboot.web.thymeleaf.validation.WebThymeleafValidationApplication; 7 | 8 | 9 | @SpringBootApplication 10 | public class WebThymeleafValidationApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run( WebThymeleafValidationApplication.class, args ); 14 | } 15 | 16 | 17 | /* 18 | If it was really important to you that JSR-303 validation messages be stored in messages.properties 19 | (rather that the default ValidationMessages.properties), 20 | then you could do the following... 21 | 22 | @Autowired 23 | private MessageSource messageSource; 24 | 25 | @Override 26 | public Validator getValidator() { 27 | LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean(); 28 | factory.setValidationMessageSource(messageSource); 29 | return factory; 30 | } 31 | */ 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/groovy/grokwich/springboot/web/thymeleaf/validation/command/FormCommand.java: -------------------------------------------------------------------------------- 1 | package grokwich.springboot.web.thymeleaf.validation.command; 2 | 3 | import javax.validation.constraints.Size; 4 | import org.hibernate.validator.constraints.Email; 5 | 6 | import lombok.Data; 7 | 8 | @Data 9 | public class FormCommand { 10 | 11 | // textField messages are configured/handled by ValidationMessages. 12 | @Size.List({ 13 | @Size(min = 5, message = "{fooCommand.textField.min.message}"), 14 | @Size(max = 20, message = "{fooCommand.textField.max.message}") 15 | }) 16 | @Email(message = "{fooCommand.textField.email.message}") 17 | String textField; 18 | 19 | 20 | // textareaField messages are configured/handled by messages.properties. 21 | @Size(min=3, max=50) 22 | String textareaField; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/groovy/grokwich/springboot/web/thymeleaf/validation/controller/FormController.java: -------------------------------------------------------------------------------- 1 | package grokwich.springboot.web.thymeleaf.validation.controller; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.validation.BindingResult; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 12 | 13 | import grokwich.springboot.web.thymeleaf.validation.command.FormCommand; 14 | import lombok.extern.slf4j.Slf4j; 15 | 16 | 17 | @Slf4j 18 | @Controller 19 | public class FormController { 20 | 21 | @GetMapping("/fooform") 22 | public String fooForm(Model model) { 23 | model.addAttribute( "command", new FormCommand()); 24 | 25 | return "fooForm"; 26 | } 27 | 28 | 29 | @PostMapping("/fooform") 30 | public String foobarPost( 31 | @Valid @ModelAttribute("command") FormCommand command, 32 | // WARN: BindingResult *must* immediately follow the Command (otherwise silent non-validation). 33 | // https://stackoverflow.com/a/29883178/1626026 34 | BindingResult bindingResult, 35 | Model model, 36 | RedirectAttributes ra ) { 37 | 38 | log.debug("form submission."); 39 | 40 | if ( bindingResult.hasErrors() ) { 41 | return "fooForm"; 42 | } 43 | 44 | ra.addFlashAttribute("command", command); 45 | 46 | return "redirect:/fooresult"; 47 | } 48 | 49 | 50 | @GetMapping("/fooresult") 51 | public String fooresult( 52 | @ModelAttribute("command") FormCommand command, 53 | Model model) { 54 | 55 | log.debug( "!!!" + command.toString()); 56 | 57 | return "fooResult"; 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/resources/ValidationMessages.properties: -------------------------------------------------------------------------------- 1 | # ValidationMessages.properties is the SpringBoot default message bundle for the JSR-303 specification. 2 | # RECOMMENDATION: 3 | # Use the full power of JSR-303 by maintaining all Validation messages here (ValidationMessages.properties). 4 | # ie. do not maintain Validation messages in messages.properties. 5 | # 6 | # http://beanvalidation.org/1.0/spec/#default-resolution-algorithm 7 | 8 | fooCommand.textField.min.message=The Text Field ${validatedValue.length() < 1 ? 'is empty': 'has only ' + validatedValue.length() + 'characters'}, but the length must be at least {min} characters. 9 | fooCommand.textField.max.message=The Text Field value has ${validatedValue.length()}, but the length cannot exceed {max}. 10 | 11 | # NOTE: For demo purposes the validation message for textareaField configured in (@see) messages.properties. 12 | 13 | fooCommand.textField.email.message=The Text Field requires an email address. 14 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.root=WARN 2 | #logging.level.org.springframework.web=DEBUG 3 | logging.level.grokwich.springboot.web.thymeleaf.forms=DEBUG 4 | 5 | spring.thymeleaf.cache=false -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | # The Validation framework will use messages.properties by default if present, 2 | # but the Validation msg integration is adapted to the i18n message bundle api. 3 | # So just simple interpolation of parameters by number. 4 | # One nice behavior of the simple message api is auto-key generation. 5 | # By default, you do not need to be explicit about the constraint annotation specifying a message key. 6 | # The default key convention is .. 7 | # Normally the command-name is the Command Class Name. 8 | # WARN! 9 | # But if the command-name is aliased by a @ModelAttribute("command-name-alias"), 10 | # then the alias must be used as the command-name. 11 | # example: 12 | # // @Valid @ModelAttribute("command") FormCommand command, 13 | # In this example command-name -> "command" (rather than 'formCommand'). 14 | # The default key in this case is demonstrated below by the @Size validation message. 15 | # 16 | 17 | Size.command.textareaField=The Textarea Field must have at least {2} characters, but no mare than {1} 18 | 19 | 20 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/resources/templates/fooForm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Thymeleaf Form Validation 5 | 6 | 9 | 10 | 11 |

12 | 13 |

14 |

Simple Text Field: 15 | 16 |

17 | 18 | 19 |

Text Area Field: 20 | 21 |

22 | 23 | 24 |

25 |
26 | 27 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/main/resources/templates/fooResult.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Thymeleaf Form Result 5 | 6 | 7 | 8 |

9 | 10 |

11 |

12 | 13 | resubmit form 14 | 15 | 16 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-JSR303-validation/src/test/groovy/grokwich/springboot/web/thymeleaf/validation/WebThymeleafFormsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package grokwich.springboot.web.thymeleaf.validation; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import org.springframework.test.web.servlet.MockMvc; 10 | 11 | import grokwich.springboot.web.thymeleaf.validation.command.FormCommand; 12 | 13 | import static org.hamcrest.Matchers.*; 14 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 15 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 17 | 18 | 19 | 20 | @RunWith(SpringRunner.class) 21 | @WebMvcTest 22 | public class WebThymeleafFormsApplicationTests { 23 | 24 | @Autowired 25 | private MockMvc mockMvc; 26 | 27 | @Test 28 | public void fooFormTest() throws Exception { 29 | mockMvc.perform(get("/fooform")) 30 | .andExpect(model().attribute("command", any(FormCommand.class))) 31 | .andExpect(view().name("fooForm")) 32 | .andExpect(status().isOk()); 33 | } 34 | 35 | 36 | @Test 37 | public void happyPostTest() throws Exception { 38 | final String textFieldValue = "foo@bar.com"; 39 | final String textareaFieldValue = "This is a couple of lines\nof content."; 40 | 41 | mockMvc 42 | .perform(post("/fooform") 43 | .param("textField", textFieldValue) 44 | .param("textareaField", textareaFieldValue) 45 | .contentType(MediaType.APPLICATION_FORM_URLENCODED)) 46 | .andExpect(status().is3xxRedirection()) 47 | .andExpect(flash().attribute("command", hasProperty("textField", equalTo(textFieldValue)))) 48 | .andExpect(flash().attribute("command", hasProperty("textareaField", equalTo(textareaFieldValue)))); 49 | } 50 | 51 | 52 | @Test 53 | public void emptyFieldsTest() throws Exception { 54 | final String textFieldValue = ""; 55 | final String textareaFieldValue = ""; 56 | 57 | mockMvc 58 | .perform(post("/fooform") 59 | .param("textField", textFieldValue) 60 | .param("textareaField", textareaFieldValue) 61 | .contentType(MediaType.APPLICATION_FORM_URLENCODED)) 62 | .andExpect(status().isOk()) 63 | .andExpect(content().string( 64 | allOf( 65 | containsString("The Text Field is empty, but the length must be at least 5 characters"), 66 | containsString("The Textarea Field must have at least 3 characters, but no mare than 50") 67 | ) 68 | ) 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-forms/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | bin/ 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | .nb-gradle/ -------------------------------------------------------------------------------- /springboot-web/web-thymeleaf-forms/README.md: -------------------------------------------------------------------------------- 1 | # web-thymeleaf-forms 2 | Snack-sample that demonstrates integration of HTML Form workflow between Spring Boot and Thymeleaf. 3 | 4 | ## Blog Discussion 5 | https://medium.com/@grokwich/spring-boot-thymeleaf-html-form-handling-762ef0d51327 6 | 7 | ## HTML Form Elements 8 | 9 | Most form elements have been demonstrated. 10 | * `