From 8a0a53dbf3d6c426ef299eca8ddb1703d9fc5eb7 Mon Sep 17 00:00:00 2001 From: javaguy Date: Sun, 30 Mar 2025 21:38:18 -0400 Subject: [PATCH] add-support-for-pagination Problem: We want to add pagination support to our existing spring app with thymeleaf. This commit adds pagination support with instruction.md on the list of changes and nuances to make it work with thymeleaf. --- .../HELP.md | 22 ++ .../INSTRUCTIONS.md | 100 ++++++ .../mvnw | 316 ++++++++++++++++++ .../mvnw.cmd | 188 +++++++++++ .../pom.xml | 68 ++++ .../ThymeleafdemoApplication.java | 13 + .../controller/DemoController.java | 27 ++ .../controller/EmployeeController.java | 92 +++++ .../thymeleafdemo/dao/EmployeeRepository.java | 21 ++ .../thymeleafdemo/entity/Employee.java | 103 ++++++ .../service/EmployeeService.java | 21 ++ .../service/EmployeeServiceImpl.java | 71 ++++ .../src/main/resources/application.properties | 6 + .../main/resources/sql/employee-directory.sql | 134 ++++++++ .../src/main/resources/static/index.html | 2 + .../templates/employees/employee-form.html | 58 ++++ .../templates/employees/list-employees.html | 104 ++++++ .../main/resources/templates/helloworld.html | 25 ++ .../ThymeleafdemoApplicationTests.java | 13 + 19 files changed, 1384 insertions(+) create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/HELP.md create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/INSTRUCTIONS.md create mode 100755 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw.cmd create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/pom.xml create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplication.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/DemoController.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/EmployeeController.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/dao/EmployeeRepository.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/entity/Employee.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeService.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeServiceImpl.java create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/application.properties create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/sql/employee-directory.sql create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/static/index.html create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/employee-form.html create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/list-employees.html create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/helloworld.html create mode 100644 07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/test/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplicationTests.java diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/HELP.md b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/HELP.md new file mode 100644 index 00000000..ad0039e6 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/HELP.md @@ -0,0 +1,22 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.0.0-RC1/maven-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.0.0-RC1/maven-plugin/reference/html/#build-image) +* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.0.0-RC1/reference/htmlsingle/#data.sql.jpa-and-spring-data) +* [Thymeleaf](https://docs.spring.io/spring-boot/docs/3.0.0-RC1/reference/htmlsingle/#web.servlet.spring-mvc.template-engines) +* [Spring Web](https://docs.spring.io/spring-boot/docs/3.0.0-RC1/reference/htmlsingle/#web) +* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.0.0-RC1/reference/htmlsingle/#using.devtools) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/INSTRUCTIONS.md b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/INSTRUCTIONS.md new file mode 100644 index 00000000..811fb62a --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/INSTRUCTIONS.md @@ -0,0 +1,100 @@ +Steps to Add Pagination (Complete Step-by-Step Guide) + +Repository Layer + +Updated EmployeeRepository to support pagination: +```java +public interface EmployeeRepository extends JpaRepository { + Page findAllByOrderByLastNameAsc(Pageable pageable); +} +``` + +Service Layer + +Updated EmployeeService interface: +```java +public interface EmployeeService { + Page findPaginated(int pageNo, int pageSize); +} +``` + +Implemented pagination in EmployeeServiceImpl: +```java + + +@Service +public class EmployeeServiceImpl implements EmployeeService { + + @Override + public Page findPaginated(int pageNo, int pageSize) { + Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by("lastName").ascending()); + return employeeRepository.findAllByOrderByLastNameAsc(pageable); + } +} +``` +Controller Layer + +Modified the /list endpoint to accept pagination parameters: +```java +@GetMapping("/list") +public String listEmployees( + @RequestParam(name="page", required=false, defaultValue="1") int page, + @RequestParam(name="size", required=false, defaultValue="5") int size, + Model model) { + + Page employeePage = employeeService.findPaginated(page, size); + model.addAttribute("employeePage", employeePage); + + return "employees/list-employees"; +} +``` + + +Thymeleaf Template Changes (list-employees.html) + +Updated table iteration to use `employeePage.content`: + +```html + + + + + + + Update + Delete + + + +``` +Added pagination controls with page-size preservation: +```html + +``` +Added dropdown form for users to select page size: +```html +
+ + + + +
+``` diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw new file mode 100755 index 00000000..8a8fb228 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw.cmd b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw.cmd new file mode 100644 index 00000000..1d8ab018 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/pom.xml b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/pom.xml new file mode 100644 index 00000000..4bc5fa87 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.4.0 + + + + com.luv2code.springboot + thymeleafdemo + 0.0.1-SNAPSHOT + thymeleafdemo + Demo project for Spring Boot + + + 17 + + + + + + com.mysql + mysql-connector-j + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplication.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplication.java new file mode 100644 index 00000000..ea38dd85 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplication.java @@ -0,0 +1,13 @@ +package com.luv2code.springboot.thymeleafdemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ThymeleafdemoApplication { + + public static void main(String[] args) { + SpringApplication.run(ThymeleafdemoApplication.class, args); + } + +} diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/DemoController.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/DemoController.java new file mode 100644 index 00000000..f8fe58b6 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/DemoController.java @@ -0,0 +1,27 @@ +package com.luv2code.springboot.thymeleafdemo.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class DemoController { + + // create a mapping for "/hello" + + @GetMapping("/hello") + public String sayHello(Model theModel) { + + theModel.addAttribute("theDate", new java.util.Date()); + + return "helloworld"; + } +} + + + + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/EmployeeController.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/EmployeeController.java new file mode 100644 index 00000000..af496ed6 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/controller/EmployeeController.java @@ -0,0 +1,92 @@ +package com.luv2code.springboot.thymeleafdemo.controller; + +import java.util.List; + +import com.luv2code.springboot.thymeleafdemo.service.EmployeeService; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import com.luv2code.springboot.thymeleafdemo.entity.Employee; + +@Controller +@RequestMapping("/employees") +public class EmployeeController { + + private final EmployeeService employeeService; + + public EmployeeController(EmployeeService theEmployeeService) { + employeeService = theEmployeeService; + } + + // add mapping for "/list" + + @GetMapping("/list") + public String listEmployees(@RequestParam(name="page", required=false, defaultValue="10") int page, + @RequestParam(name="size", required=false, defaultValue="5") int size, + Model theModel) { + + Page employeePage = employeeService.findPaginated(page, size); + theModel.addAttribute("employeePage", employeePage); + return "employees/list-employees"; + } + + @GetMapping("/showFormForAdd") + public String showFormForAdd(Model theModel) { + + // create model attribute to bind form data + Employee theEmployee = new Employee(); + + theModel.addAttribute("employee", theEmployee); + + return "employees/employee-form"; + } + + @GetMapping("/showFormForUpdate") + public String showFormForUpdate(@RequestParam("employeeId") int theId, + Model theModel) { + + // get the employee from the service + Employee theEmployee = employeeService.findById(theId); + + // set employee as a model attribute to pre-populate the form + theModel.addAttribute("employee", theEmployee); + + // send over to our form + return "employees/employee-form"; + } + + @PostMapping("/save") + public String saveEmployee(@ModelAttribute("employee") Employee theEmployee) { + + // save the employee + employeeService.save(theEmployee); + + // use a redirect to prevent duplicate submissions + return "redirect:/employees/list"; + } + + @GetMapping("/delete") + public String delete(@RequestParam("employeeId") int theId) { + + // delete the employee + employeeService.deleteById(theId); + + // redirect to /employees/list + return "redirect:/employees/list"; + + } +} + + + + + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/dao/EmployeeRepository.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/dao/EmployeeRepository.java new file mode 100644 index 00000000..5dc1cf9a --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/dao/EmployeeRepository.java @@ -0,0 +1,21 @@ +package com.luv2code.springboot.thymeleafdemo.dao; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.luv2code.springboot.thymeleafdemo.entity.Employee; + +import java.util.List; + +public interface EmployeeRepository extends JpaRepository { + + // that's it ... no need to write any code LOL! + + // add a method to sort by last name + public List findAllByOrderByLastNameAsc(); + + + Page findAllByOrderByLastNameAsc(Pageable pageable); + +} diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/entity/Employee.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/entity/Employee.java new file mode 100644 index 00000000..be7ca061 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/entity/Employee.java @@ -0,0 +1,103 @@ +package com.luv2code.springboot.thymeleafdemo.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@Entity +@Table(name="employee") +public class Employee { + + // define fields + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + private int id; + + @Column(name="first_name") + private String firstName; + + @Column(name="last_name") + private String lastName; + + @Column(name="email") + private String email; + + + // define constructors + + public Employee() { + + } + + public Employee(int id, String firstName, String lastName, String email) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + } + + + public Employee(String firstName, String lastName, String email) { + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + } + + // define getter/setter + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + // define tostring + + @Override + public String toString() { + return "Employee [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]"; + } + +} + + + + + + + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeService.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeService.java new file mode 100644 index 00000000..c93c60d6 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeService.java @@ -0,0 +1,21 @@ +package com.luv2code.springboot.thymeleafdemo.service; + +import java.util.List; + +import com.luv2code.springboot.thymeleafdemo.entity.Employee; +import org.springframework.data.domain.Page; + +public interface EmployeeService { + + List findAll(); + + // New method for pagination + Page findPaginated(int pageNo, int pageSize); + + Employee findById(int theId); + + void save(Employee theEmployee); + + void deleteById(int theId); + +} diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeServiceImpl.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeServiceImpl.java new file mode 100644 index 00000000..49c900b1 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/java/com/luv2code/springboot/thymeleafdemo/service/EmployeeServiceImpl.java @@ -0,0 +1,71 @@ +package com.luv2code.springboot.thymeleafdemo.service; + +import java.util.List; +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import com.luv2code.springboot.thymeleafdemo.dao.EmployeeRepository; +import com.luv2code.springboot.thymeleafdemo.entity.Employee; + +@Service +public class EmployeeServiceImpl implements EmployeeService { + + private EmployeeRepository employeeRepository; + + @Autowired + public EmployeeServiceImpl(EmployeeRepository theEmployeeRepository) { + employeeRepository = theEmployeeRepository; + } + + @Override + public List findAll() { + return employeeRepository.findAllByOrderByLastNameAsc(); + } + + @Override + public Page findPaginated(int pageNo, int pageSize) { + // Adjust pageNo if you're receiving 1-indexed values from the controller: + Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by("lastName").ascending()); + return employeeRepository.findAllByOrderByLastNameAsc(pageable); + } + + @Override + public Employee findById(int theId) { + Optional result = employeeRepository.findById(theId); + + Employee theEmployee = null; + + if (result.isPresent()) { + theEmployee = result.get(); + } + else { + // we didn't find the employee + throw new RuntimeException("Did not find employee id - " + theId); + } + + return theEmployee; + } + + @Override + public void save(Employee theEmployee) { + employeeRepository.save(theEmployee); + } + + @Override + public void deleteById(int theId) { + employeeRepository.deleteById(theId); + } + +} + + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/application.properties b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/application.properties new file mode 100644 index 00000000..6118b8f3 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/application.properties @@ -0,0 +1,6 @@ +# +# JDBC properties +# +spring.datasource.url=jdbc:mysql://localhost:3306/employee_directory +spring.datasource.username=springstudent +spring.datasource.password=springstudent diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/sql/employee-directory.sql b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/sql/employee-directory.sql new file mode 100644 index 00000000..c2d3d35d --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/sql/employee-directory.sql @@ -0,0 +1,134 @@ + + +CREATE DATABASE IF NOT EXISTS `employee_directory`; +USE `employee_directory`; + +-- +-- Table structure for table `employee` +-- + +DROP TABLE IF EXISTS `employee`; + +CREATE TABLE `employee` ( + `id` int NOT NULL AUTO_INCREMENT, + `first_name` varchar(45) DEFAULT NULL, + `last_name` varchar(45) DEFAULT NULL, + `email` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; + +-- +-- Data for table `employee` +-- + +INSERT INTO `employee` VALUES + (1,'Leslie','Andrews','leslie@luv2code.com'), + (2,'Emma','Baumgarten','emma@luv2code.com'), + (3,'Avani','Gupta','avani@luv2code.com'), + (4,'Yuri','Petrov','yuri@luv2code.com'), + (5,'Juan','Vega','juan@luv2code.com'); + + +INSERT INTO employee (id, first_name, last_name, email) VALUES (6, 'Employee6', 'Test6', 'employee6.test6@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (7, 'Employee7', 'Test7', 'employee7.test7@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (8, 'Employee8', 'Test8', 'employee8.test8@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (9, 'Employee9', 'Test9', 'employee9.test9@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (10, 'Employee10', 'Test10', 'employee10.test10@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (11, 'Employee11', 'Test11', 'employee11.test11@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (12, 'Employee12', 'Test12', 'employee12.test12@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (13, 'Employee13', 'Test13', 'employee13.test13@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (14, 'Employee14', 'Test14', 'employee14.test14@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (15, 'Employee15', 'Test15', 'employee15.test15@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (16, 'Employee16', 'Test16', 'employee16.test16@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (17, 'Employee17', 'Test17', 'employee17.test17@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (18, 'Employee18', 'Test18', 'employee18.test18@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (19, 'Employee19', 'Test19', 'employee19.test19@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (20, 'Employee20', 'Test20', 'employee20.test20@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (21, 'Employee21', 'Test21', 'employee21.test21@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (22, 'Employee22', 'Test22', 'employee22.test22@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (23, 'Employee23', 'Test23', 'employee23.test23@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (24, 'Employee24', 'Test24', 'employee24.test24@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (25, 'Employee25', 'Test25', 'employee25.test25@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (26, 'Employee26', 'Test26', 'employee26.test26@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (27, 'Employee27', 'Test27', 'employee27.test27@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (28, 'Employee28', 'Test28', 'employee28.test28@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (29, 'Employee29', 'Test29', 'employee29.test29@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (30, 'Employee30', 'Test30', 'employee30.test30@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (31, 'Employee31', 'Test31', 'employee31.test31@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (32, 'Employee32', 'Test32', 'employee32.test32@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (33, 'Employee33', 'Test33', 'employee33.test33@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (34, 'Employee34', 'Test34', 'employee34.test34@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (35, 'Employee35', 'Test35', 'employee35.test35@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (36, 'Employee36', 'Test36', 'employee36.test36@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (37, 'Employee37', 'Test37', 'employee37.test37@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (38, 'Employee38', 'Test38', 'employee38.test38@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (39, 'Employee39', 'Test39', 'employee39.test39@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (40, 'Employee40', 'Test40', 'employee40.test40@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (41, 'Employee41', 'Test41', 'employee41.test41@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (42, 'Employee42', 'Test42', 'employee42.test42@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (43, 'Employee43', 'Test43', 'employee43.test43@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (44, 'Employee44', 'Test44', 'employee44.test44@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (45, 'Employee45', 'Test45', 'employee45.test45@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (46, 'Employee46', 'Test46', 'employee46.test46@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (47, 'Employee47', 'Test47', 'employee47.test47@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (48, 'Employee48', 'Test48', 'employee48.test48@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (49, 'Employee49', 'Test49', 'employee49.test49@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (50, 'Employee50', 'Test50', 'employee50.test50@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (51, 'Employee51', 'Test51', 'employee51.test51@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (52, 'Employee52', 'Test52', 'employee52.test52@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (53, 'Employee53', 'Test53', 'employee53.test53@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (54, 'Employee54', 'Test54', 'employee54.test54@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (55, 'Employee55', 'Test55', 'employee55.test55@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (56, 'Employee56', 'Test56', 'employee56.test56@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (57, 'Employee57', 'Test57', 'employee57.test57@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (58, 'Employee58', 'Test58', 'employee58.test58@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (59, 'Employee59', 'Test59', 'employee59.test59@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (60, 'Employee60', 'Test60', 'employee60.test60@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (61, 'Employee61', 'Test61', 'employee61.test61@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (62, 'Employee62', 'Test62', 'employee62.test62@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (63, 'Employee63', 'Test63', 'employee63.test63@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (64, 'Employee64', 'Test64', 'employee64.test64@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (65, 'Employee65', 'Test65', 'employee65.test65@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (66, 'Employee66', 'Test66', 'employee66.test66@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (67, 'Employee67', 'Test67', 'employee67.test67@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (68, 'Employee68', 'Test68', 'employee68.test68@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (69, 'Employee69', 'Test69', 'employee69.test69@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (70, 'Employee70', 'Test70', 'employee70.test70@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (71, 'Employee71', 'Test71', 'employee71.test71@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (72, 'Employee72', 'Test72', 'employee72.test72@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (73, 'Employee73', 'Test73', 'employee73.test73@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (74, 'Employee74', 'Test74', 'employee74.test74@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (75, 'Employee75', 'Test75', 'employee75.test75@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (76, 'Employee76', 'Test76', 'employee76.test76@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (77, 'Employee77', 'Test77', 'employee77.test77@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (78, 'Employee78', 'Test78', 'employee78.test78@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (79, 'Employee79', 'Test79', 'employee79.test79@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (80, 'Employee80', 'Test80', 'employee80.test80@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (81, 'Employee81', 'Test81', 'employee81.test81@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (82, 'Employee82', 'Test82', 'employee82.test82@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (83, 'Employee83', 'Test83', 'employee83.test83@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (84, 'Employee84', 'Test84', 'employee84.test84@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (85, 'Employee85', 'Test85', 'employee85.test85@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (86, 'Employee86', 'Test86', 'employee86.test86@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (87, 'Employee87', 'Test87', 'employee87.test87@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (88, 'Employee88', 'Test88', 'employee88.test88@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (89, 'Employee89', 'Test89', 'employee89.test89@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (90, 'Employee90', 'Test90', 'employee90.test90@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (91, 'Employee91', 'Test91', 'employee91.test91@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (92, 'Employee92', 'Test92', 'employee92.test92@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (93, 'Employee93', 'Test93', 'employee93.test93@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (94, 'Employee94', 'Test94', 'employee94.test94@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (95, 'Employee95', 'Test95', 'employee95.test95@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (96, 'Employee96', 'Test96', 'employee96.test96@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (97, 'Employee97', 'Test97', 'employee97.test97@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (98, 'Employee98', 'Test98', 'employee98.test98@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (99, 'Employee99', 'Test99', 'employee99.test99@example.com'); +INSERT INTO employee (id, first_name, last_name, email) VALUES (100, 'Employee100', 'Test100', 'employee100.test100@example.com'); + + +DESC table employee; + +SELECT CURRENT_USER(); + + +select * from employee; \ No newline at end of file diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/static/index.html b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/static/index.html new file mode 100644 index 00000000..da401393 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/static/index.html @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/employee-form.html b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/employee-form.html new file mode 100644 index 00000000..42b6c99a --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/employee-form.html @@ -0,0 +1,58 @@ + + + + + + + + + + + + Save Employee + + + + +
+ +

Employee Directory

+
+ +

Save Employee

+ +
+ + + + + + + + + + + + +
+ +
+ Back to Employees List + +
+ + + + + + + + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/list-employees.html b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/list-employees.html new file mode 100644 index 00000000..58fe2855 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/employees/list-employees.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + Employee Directory + + + + +
+ +

Employee Directory

+
+ + + + Add Employee + + + + + + + + + + + + + + + + + + + + +
First NameLast NameEmailAction
+ Update + Delete +
+ +
+ + + + + +
+ + + + + +
+ + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/helloworld.html b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/helloworld.html new file mode 100644 index 00000000..d15872bf --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/main/resources/templates/helloworld.html @@ -0,0 +1,25 @@ + + + + + Thymeleaf Demo + + + + + + + + +

+ + + + + + + + + + diff --git a/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/test/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplicationTests.java b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/test/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplicationTests.java new file mode 100644 index 00000000..eb8940c6 --- /dev/null +++ b/07-spring-boot-spring-mvc-crud/04-03-thymeleaf-pagination-for-employees/src/test/java/com/luv2code/springboot/thymeleafdemo/ThymeleafdemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.luv2code.springboot.thymeleafdemo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ThymeleafdemoApplicationTests { + + @Test + void contextLoads() { + } + +}