parent
c20451c67c
commit
50c3dc0d34
155 changed files with 8265 additions and 3 deletions
@ -0,0 +1,33 @@ |
||||
HELP.md |
||||
target/ |
||||
!.mvn/wrapper/maven-wrapper.jar |
||||
!**/src/main/**/target/ |
||||
!**/src/test/**/target/ |
||||
|
||||
### STS ### |
||||
.apt_generated |
||||
.classpath |
||||
.factorypath |
||||
.project |
||||
.settings |
||||
.springBeans |
||||
.sts4-cache |
||||
|
||||
### IntelliJ IDEA ### |
||||
.idea |
||||
*.iws |
||||
*.iml |
||||
*.ipr |
||||
|
||||
### NetBeans ### |
||||
/nbproject/private/ |
||||
/nbbuild/ |
||||
/dist/ |
||||
/nbdist/ |
||||
/.nb-gradle/ |
||||
build/ |
||||
!**/src/main/**/build/ |
||||
!**/src/test/**/build/ |
||||
|
||||
### VS Code ### |
||||
.vscode/ |
Binary file not shown.
@ -0,0 +1,18 @@ |
||||
# 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. |
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip |
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar |
@ -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 "$@" |
@ -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% |
@ -0,0 +1,70 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-parent</artifactId> |
||||
<version>2.7.9</version> |
||||
<relativePath/> <!-- lookup parent from repository --> |
||||
</parent> |
||||
<groupId>cc.bnblogs</groupId> |
||||
<artifactId>SpringBasis</artifactId> |
||||
<version>0.0.1-SNAPSHOT</version> |
||||
<name>SpringBasis</name> |
||||
<description>SpringBasis</description> |
||||
<properties> |
||||
<java.version>1.8</java.version> |
||||
</properties> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-devtools</artifactId> |
||||
<scope>runtime</scope> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.mysql</groupId> |
||||
<artifactId>mysql-connector-j</artifactId> |
||||
<version>8.0.32</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
<version>3.5.3.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<excludes> |
||||
<exclude> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</exclude> |
||||
</excludes> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,24 @@ |
||||
package cc.bnblogs.springbasis; |
||||
|
||||
import cc.bnblogs.springbasis.demo.service.CalculateService; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.WebApplicationType; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.builder.SpringApplicationBuilder; |
||||
import org.springframework.context.ConfigurableApplicationContext; |
||||
import org.springframework.context.annotation.ComponentScan; |
||||
|
||||
@SpringBootApplication |
||||
public class SpringBasisApplication { |
||||
public static void main(String[] args) { |
||||
// SpringApplication.run(SpringBasisApplication.class, args);
|
||||
ConfigurableApplicationContext context1 = new SpringApplicationBuilder(SpringBasisApplication.class) |
||||
.web(WebApplicationType.NONE) |
||||
.profiles("java7") |
||||
.run(args); |
||||
|
||||
CalculateService service = context1.getBean(CalculateService.class); |
||||
System.out.println("求合结果: " + service.sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
package cc.bnblogs.springbasis.demo.config; |
||||
|
||||
import cc.bnblogs.springbasis.demo.test.Cherry; |
||||
import org.springframework.beans.factory.FactoryBean; |
||||
|
||||
public class CherryFactoryBean implements FactoryBean<Cherry> { |
||||
/** |
||||
* 返回注册的组件对象 |
||||
*/ |
||||
@Override |
||||
public Cherry getObject() { |
||||
return new Cherry(); |
||||
} |
||||
|
||||
/** |
||||
*返回需要注册的组件类型 |
||||
*/ |
||||
@Override |
||||
public Class<?> getObjectType() { |
||||
return Cherry.class; |
||||
} |
||||
|
||||
/** |
||||
*该组件使用单例模式 |
||||
*/ |
||||
@Override |
||||
public boolean isSingleton() { |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package cc.bnblogs.springbasis.demo.config; |
||||
|
||||
|
||||
import org.springframework.context.annotation.Condition; |
||||
import org.springframework.context.annotation.ConditionContext; |
||||
import org.springframework.core.type.AnnotatedTypeMetadata; |
||||
|
||||
|
||||
public class MyCondition implements Condition { |
||||
/** |
||||
* @param context 上下文信息 |
||||
* @param metadata 注解信息 |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { |
||||
String osName = context.getEnvironment().getProperty("os.name"); |
||||
return osName != null && osName.contains("Windows"); |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
package cc.bnblogs.springbasis.demo.config; |
||||
|
||||
import org.springframework.context.annotation.ImportSelector; |
||||
import org.springframework.core.type.AnnotationMetadata; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
public class MyImportSelector implements ImportSelector { |
||||
@Override |
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) { |
||||
return new String[]{ |
||||
"cc.bnblogs.springbasis.demo.test.Apple", |
||||
"cc.bnblogs.springbasis.demo.test.Banana", |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package cc.bnblogs.springbasis.demo.config; |
||||
|
||||
import cc.bnblogs.springbasis.demo.pojo.User; |
||||
import cc.bnblogs.springbasis.demo.test.Test; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.context.annotation.*; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.stereotype.Repository; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/20 18:23 |
||||
*/ |
||||
@Configuration |
||||
//@ComponentScan(value = "cc.bnblogs.springbasis.demo.pojo")
|
||||
@Import({MyImportSelector.class}) |
||||
|
||||
public class WebConfig { |
||||
/** |
||||
* 通过@Bean注解,我们向IOC容器注册了一个名称为user的组件 |
||||
*/ |
||||
@Bean(name = "myUser") |
||||
@Conditional(MyCondition.class) |
||||
public User user() { |
||||
return new User("tom",18); |
||||
} |
||||
|
||||
@Bean |
||||
public CherryFactoryBean cherryFactoryBean() { |
||||
return new CherryFactoryBean(); |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
package cc.bnblogs.springbasis.demo.controller; |
||||
|
||||
import cc.bnblogs.springbasis.demo.mapper.UserMapper; |
||||
import cc.bnblogs.springbasis.demo.pojo.User; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 14:59 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("user") |
||||
public class UserController { |
||||
@Resource |
||||
private UserMapper userMapper; |
||||
@GetMapping |
||||
public List<User> getAllUser() { |
||||
return userMapper.selectList(null); |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
package cc.bnblogs.springbasis.demo.mapper; |
||||
|
||||
import cc.bnblogs.springbasis.demo.pojo.User; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 15:00 |
||||
*/ |
||||
@Mapper |
||||
public interface UserMapper extends BaseMapper<User> { |
||||
} |
@ -0,0 +1,24 @@ |
||||
package cc.bnblogs.springbasis.demo.pojo; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/20 18:22 |
||||
*/ |
||||
@Data |
||||
@AllArgsConstructor |
||||
@NoArgsConstructor |
||||
public class User { |
||||
|
||||
private String name; |
||||
private Integer age; |
||||
|
||||
// public User(String name,Integer age) {
|
||||
// this.name = name;
|
||||
// this.age = age;
|
||||
// }
|
||||
} |
@ -0,0 +1,5 @@ |
||||
package cc.bnblogs.springbasis.demo.service; |
||||
|
||||
public interface CalculateService { |
||||
Integer sum(Integer... value); |
||||
} |
@ -0,0 +1,12 @@ |
||||
package cc.bnblogs.springbasis.demo.service; |
||||
|
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 15:04 |
||||
*/ |
||||
@Service |
||||
public class UserService { |
||||
} |
@ -0,0 +1,19 @@ |
||||
package cc.bnblogs.springbasis.demo.service.impl; |
||||
|
||||
import cc.bnblogs.springbasis.demo.service.CalculateService; |
||||
import org.springframework.context.annotation.Profile; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
@Profile("java7") |
||||
public class Java7CalculateServiceImpl implements CalculateService { |
||||
@Override |
||||
public Integer sum(Integer... value) { |
||||
System.out.println("Java 7环境下执行"); |
||||
int result = 0; |
||||
for (int i = 0; i <= value.length; i++) { |
||||
result += i; |
||||
} |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
package cc.bnblogs.springbasis.demo.service.impl; |
||||
|
||||
import cc.bnblogs.springbasis.demo.service.CalculateService; |
||||
import org.springframework.context.annotation.Profile; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
@Service |
||||
@Profile("java8") |
||||
public class Java8CalculateServiceImpl implements CalculateService { |
||||
@Override |
||||
public Integer sum(Integer... value) { |
||||
System.out.println("Java 8环境下执行"); |
||||
return Arrays.stream(value).reduce(0, Integer::sum); |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package cc.bnblogs.springbasis.demo.test; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 17:54 |
||||
*/ |
||||
public class Apple { |
||||
public Apple() { |
||||
System.out.println("Apple类初始化成功"); |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package cc.bnblogs.springbasis.demo.test; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 17:54 |
||||
*/ |
||||
public class Banana { |
||||
public Banana() { |
||||
System.out.println("Banana类初始化成功"); |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package cc.bnblogs.springbasis.demo.test; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 18:21 |
||||
*/ |
||||
public class Cherry { |
||||
public void sayHello() { |
||||
System.out.println("hello"); |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
package cc.bnblogs.springbasis.demo.test; |
||||
|
||||
/** |
||||
* @description: 测试使用Import导入组件 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/21 17:52 |
||||
*/ |
||||
|
||||
public class Test { |
||||
public Test() { |
||||
System.out.println("Test类初始化成功"); |
||||
} |
||||
} |
@ -0,0 +1,6 @@ |
||||
spring: |
||||
datasource: |
||||
username: root |
||||
password: zfp251217 |
||||
url: jdbc:mysql://192.168.153.135:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 |
||||
driver-class-name: com.mysql.cj.jdbc.Driver |
@ -0,0 +1,16 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" |
||||
xmlns:p="http://www.springframework.org/schema/p"> |
||||
<!--set方法注入属性--> |
||||
<bean id="user" class="cc.bnblogs.springbasis.demo.pojo.User" |
||||
p:name="alice" p:age="25"> |
||||
<!--构造方法注入--> |
||||
<!-- <constructor-arg name="name" value="tom"/>--> |
||||
<!-- <constructor-arg name="age" value="18"/>--> |
||||
<!-- <property name="name" value="admin"/>--> |
||||
<!-- <property name="age" value="19"/>--> |
||||
</bean> |
||||
|
||||
</beans> |
@ -0,0 +1,11 @@ |
||||
package cc.bnblogs.springbasis; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
||||
@SpringBootTest |
||||
class SpringBasisApplicationTests { |
||||
@Test |
||||
void contextLoads() { |
||||
} |
||||
} |
@ -0,0 +1,98 @@ |
||||
package cc.bnblogs.springbasis.pojo; |
||||
|
||||
import cc.bnblogs.springbasis.SpringBasisApplication; |
||||
import cc.bnblogs.springbasis.demo.config.CherryFactoryBean; |
||||
import cc.bnblogs.springbasis.demo.config.WebConfig; |
||||
import cc.bnblogs.springbasis.demo.pojo.User; |
||||
import cc.bnblogs.springbasis.demo.test.Cherry; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.boot.builder.SpringApplicationBuilder; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.ConfigurableApplicationContext; |
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
import org.springframework.context.support.FileSystemXmlApplicationContext; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/20 18:26 |
||||
*/ |
||||
@SpringBootTest |
||||
public class UserTest { |
||||
// @Autowired
|
||||
// private User user;
|
||||
// @Test
|
||||
// void testUser() {
|
||||
// System.out.println(user);
|
||||
// }
|
||||
|
||||
|
||||
@Test |
||||
void test1() { |
||||
// 使用AnnotationConfigApplicationContext来获取相应的IOC容器,入参为配置类
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class); |
||||
User user = context.getBean(User.class); |
||||
System.out.println(user); |
||||
// 查看组件的名称
|
||||
String[] beanNames = context.getBeanNamesForType(User.class); |
||||
Arrays.stream(beanNames).forEach(System.out::println); |
||||
} |
||||
|
||||
@Test |
||||
void test2() { |
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class); |
||||
// 查看基于注解的 IOC容器中所有组件名称
|
||||
String[] beanNames = context.getBeanDefinitionNames(); |
||||
Arrays.stream(beanNames).forEach(System.out::println); |
||||
} |
||||
|
||||
@Test |
||||
void test3() { |
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class); |
||||
User user1 = context.getBean(User.class); |
||||
User user2 = context.getBean(User.class); |
||||
System.out.println(user1 == user2); |
||||
} |
||||
|
||||
@Test |
||||
void test4() { |
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class); |
||||
User user1 = context.getBean(User.class); |
||||
// User user2 = context.getBean(User.class);
|
||||
// User user3 = context.getBean(User.class);
|
||||
// System.out.println(user1 == user2); // 输出false
|
||||
// System.out.println(user1 == user3); // 输出false
|
||||
} |
||||
|
||||
@Test |
||||
void test5() { |
||||
ApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class); |
||||
// 查看基于注解的 IOC容器中所有组件名称
|
||||
|
||||
Object object = context.getBean("&cherryFactoryBean"); |
||||
System.out.println(object.getClass()); |
||||
// context.close();
|
||||
} |
||||
|
||||
@Test |
||||
void test6() { |
||||
ApplicationContext fx = new FileSystemXmlApplicationContext("src/main/resources/user.xml"); |
||||
User user = fx.getBean(User.class); |
||||
System.out.println(user.getName()); |
||||
System.out.println(user.getAge()); |
||||
|
||||
|
||||
// AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class);
|
||||
// User user = context.getBean(User.class);
|
||||
// System.out.println(user);
|
||||
// User user = fx.getBean("user", User.class);
|
||||
// System.out.println(user.getAge());
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,8 @@ |
||||
# 默认忽略的文件 |
||||
/shelf/ |
||||
/workspace.xml |
||||
# 基于编辑器的 HTTP 客户端请求 |
||||
/httpRequests/ |
||||
# Datasource local storage ignored files |
||||
/dataSources/ |
||||
/dataSources.local.xml |
@ -0,0 +1,14 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="CompilerConfiguration"> |
||||
<annotationProcessing> |
||||
<profile default="true" name="Default" enabled="true" /> |
||||
<profile name="Maven default annotation processors profile" enabled="true"> |
||||
<sourceOutputDir name="target/generated-sources/annotations" /> |
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> |
||||
<outputRelativeToContentRoot value="true" /> |
||||
<module name="springmvcdemo" /> |
||||
</profile> |
||||
</annotationProcessing> |
||||
</component> |
||||
</project> |
@ -0,0 +1,7 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="Encoding"> |
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> |
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> |
||||
</component> |
||||
</project> |
@ -0,0 +1,8 @@ |
||||
<component name="InspectionProjectProfileManager"> |
||||
<profile version="1.0"> |
||||
<option name="myName" value="Project Default" /> |
||||
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true"> |
||||
<option name="ADDITIONAL_TAGS" value="description:,author:,date:" /> |
||||
</inspection_tool> |
||||
</profile> |
||||
</component> |
@ -0,0 +1,20 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="RemoteRepositoriesConfiguration"> |
||||
<remote-repository> |
||||
<option name="id" value="central" /> |
||||
<option name="name" value="Maven Central repository" /> |
||||
<option name="url" value="https://repo1.maven.org/maven2" /> |
||||
</remote-repository> |
||||
<remote-repository> |
||||
<option name="id" value="jboss.community" /> |
||||
<option name="name" value="JBoss Community repository" /> |
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> |
||||
</remote-repository> |
||||
<remote-repository> |
||||
<option name="id" value="central" /> |
||||
<option name="name" value="Central Repository" /> |
||||
<option name="url" value="https://maven.aliyun.com/repository/public" /> |
||||
</remote-repository> |
||||
</component> |
||||
</project> |
@ -0,0 +1,17 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ExternalStorageConfigurationManager" enabled="true" /> |
||||
<component name="FrameworkDetectionExcludesConfiguration"> |
||||
<file type="web" url="file://$PROJECT_DIR$" /> |
||||
</component> |
||||
<component name="MavenProjectsManager"> |
||||
<option name="originalFiles"> |
||||
<list> |
||||
<option value="$PROJECT_DIR$/pom.xml" /> |
||||
</list> |
||||
</option> |
||||
</component> |
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> |
||||
<output url="file://$PROJECT_DIR$/out" /> |
||||
</component> |
||||
</project> |
@ -0,0 +1,8 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectModuleManager"> |
||||
<modules> |
||||
<module fileurl="file://$PROJECT_DIR$/springmvcdemo.iml" filepath="$PROJECT_DIR$/springmvcdemo.iml" /> |
||||
</modules> |
||||
</component> |
||||
</project> |
@ -0,0 +1,124 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="Palette2"> |
||||
<group name="Swing"> |
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> |
||||
</item> |
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> |
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> |
||||
<initial-values> |
||||
<property name="text" value="Button" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="RadioButton" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="CheckBox" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="Label" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
||||
<preferred-size width="200" height="200" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
||||
<preferred-size width="200" height="200" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> |
||||
<preferred-size width="-1" height="20" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> |
||||
</item> |
||||
</group> |
||||
</component> |
||||
</project> |
@ -0,0 +1,6 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="VcsDirectoryMappings"> |
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" /> |
||||
</component> |
||||
</project> |
@ -0,0 +1,78 @@ |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<groupId>cc.bnblogs</groupId> |
||||
<artifactId>springmvcdemo</artifactId> |
||||
<packaging>war</packaging> |
||||
<version>1.0-SNAPSHOT</version> |
||||
<name>springmvcdemo Maven Webapp</name> |
||||
<url>http://maven.apache.org</url> |
||||
<dependencies> |
||||
<!--添加依赖--> |
||||
<dependency> |
||||
<groupId>org.springframework</groupId> |
||||
<artifactId>spring-webmvc</artifactId> |
||||
<version>5.3.0</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<version>1.18.26</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>2.0.25</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>javax.servlet</groupId> |
||||
<artifactId>javax.servlet-api</artifactId> |
||||
<version>4.0.1</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>commons-io</groupId> |
||||
<artifactId>commons-io</artifactId> |
||||
<version>2.11.0</version> |
||||
</dependency> |
||||
<!--文件上传--> |
||||
<dependency> |
||||
<groupId>commons-fileupload</groupId> |
||||
<artifactId>commons-fileupload</artifactId> |
||||
<version>1.5</version> |
||||
</dependency> |
||||
|
||||
<!--jstl--> |
||||
<dependency> |
||||
<groupId>jstl</groupId> |
||||
<artifactId>jstl</artifactId> |
||||
<version>1.2</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.apache.taglibs</groupId> |
||||
<artifactId>taglibs-standard-impl</artifactId> |
||||
<version>1.2.5</version> |
||||
<scope>runtime</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>javax.validation</groupId> |
||||
<artifactId>validation-api</artifactId> |
||||
<version>2.0.1.Final</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.hibernate.validator</groupId> |
||||
<artifactId>hibernate-validator</artifactId> |
||||
<version>6.0.23.Final</version> |
||||
</dependency> |
||||
</dependencies> |
||||
<build> |
||||
<finalName>springmvcdemo</finalName> |
||||
</build> |
||||
</project> |
@ -0,0 +1,8 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module version="4"> |
||||
<component name="NewModuleRootManager"> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
||||
</content> |
||||
</component> |
||||
</module> |
@ -0,0 +1,27 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import cc.bnblogs.entity.Student; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @description: 测试自定义数据转换器 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 21:03 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("convert") |
||||
public class ConvertHandler { |
||||
@RequestMapping(value = "date",method = RequestMethod.POST) |
||||
public String getDate(Date date) { |
||||
return date.toString(); |
||||
} |
||||
|
||||
@RequestMapping(value = "student",method = RequestMethod.POST) |
||||
public String getDate(Student student) { |
||||
return student.toString(); |
||||
} |
||||
} |
@ -0,0 +1,80 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import cc.bnblogs.entity.User; |
||||
import cc.bnblogs.entity.UserList; |
||||
import cc.bnblogs.entity.UserMap; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @description: SpringMVC数据绑定 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 15:05 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("data") |
||||
public class DataHandler { |
||||
/** |
||||
* 请求url: http://localhost:8080/data/id?id=10
|
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@RequestMapping("id") |
||||
public String getId(Integer id) { |
||||
System.out.println(id); |
||||
return id+""; |
||||
} |
||||
|
||||
/** |
||||
* 请求url: http://localhost:8080/data/name?names=aaa&names=bbb&names=cccc
|
||||
* @param names |
||||
* @return |
||||
*/ |
||||
@RequestMapping("name") |
||||
public String getNames(String[] names) { |
||||
return Arrays.toString(names); |
||||
} |
||||
|
||||
/** |
||||
* 返回用户列表,SpringMVC不能直接接收一个List集合,只能将List集合封装为一个类 |
||||
* @param userList 用户数据保存在列表中 |
||||
* @return |
||||
*/ |
||||
@RequestMapping(value = "list",method = RequestMethod.POST) |
||||
public String list(UserList userList) { |
||||
// System.out.println(userList); // 输出list中的数据
|
||||
StringBuilder str = new StringBuilder(); |
||||
for (User user : userList.getUsers()) { |
||||
str.append(user); |
||||
} |
||||
return str.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 返回用户数据,SpringMVC不能直接接收一个Map,只能将Map封装为一个类 |
||||
* @param userMap 用户数据保存在Map的value中 |
||||
* @return |
||||
*/ |
||||
@RequestMapping(value = "map",method = RequestMethod.POST) |
||||
public String map(UserMap userMap) { |
||||
// System.out.println(userMap); // 输出map中的数据
|
||||
StringBuilder str = new StringBuilder(); |
||||
for (String key : userMap.getUsers().keySet()) { |
||||
User user = userMap.getUsers().get(key); |
||||
str.append(user); |
||||
} |
||||
return str.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 接收一个json数据,返回User对象 |
||||
*/ |
||||
@RequestMapping(value = "json",method = RequestMethod.POST) |
||||
public User getJson(@RequestBody User user) { |
||||
System.out.println("user = " + user); |
||||
return user; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,99 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import org.apache.commons.io.FileUtils; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @description: 文件上传和下载 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 23:21 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("file") |
||||
public class FileHandler { |
||||
@PostMapping("upload") |
||||
public String imgUpload(MultipartFile img, HttpServletRequest request) throws IOException { |
||||
if (!img.isEmpty()) { |
||||
// 保存路径: D:\apache-tomcat-9.0.73\webapps\ROOT\files
|
||||
// 每次重启tomcat后会删掉
|
||||
String path = request.getServletContext().getRealPath("files"); |
||||
// 获取上传文件的文件名
|
||||
String name= img.getOriginalFilename(); |
||||
// 存到tomcat安装目录下的bin文件夹下的files文件夹
|
||||
File file = new File(path,name); |
||||
// 保存内容到文件中
|
||||
img.transferTo(file); |
||||
// 保存到request中用于回显
|
||||
request.setAttribute("path","/files/" + name); |
||||
} |
||||
return "upload"; |
||||
} |
||||
|
||||
@PostMapping("uploads") |
||||
public String uploadImages(MultipartFile[] images,HttpServletRequest request) throws IOException { |
||||
List<String> paths = new ArrayList<String>(); |
||||
for (MultipartFile img: images) { |
||||
if (!img.isEmpty()) { |
||||
// 保存路径: D:\apache-tomcat-9.0.73\webapps\ROOT\files
|
||||
// 每次重启tomcat后会删掉
|
||||
String path = request.getServletContext().getRealPath("files"); |
||||
// 获取上传文件的文件名
|
||||
String name= img.getOriginalFilename(); |
||||
// 存到tomcat安装目录下的bin文件夹下的files文件夹
|
||||
File file = new File(path,name); |
||||
// 保存内容到文件中
|
||||
img.transferTo(file); |
||||
// 保存到request中用于回显
|
||||
paths.add("/files/"+name); |
||||
} |
||||
} |
||||
request.setAttribute("path",paths); |
||||
return "uploads"; |
||||
} |
||||
|
||||
@GetMapping("download/{name}") |
||||
public void download(@PathVariable("name") String name, HttpServletRequest request, |
||||
HttpServletResponse response) throws IOException { |
||||
if (name != null) { |
||||
// 加上后缀名
|
||||
if (!name.endsWith(".png")) { |
||||
name += ".png"; |
||||
} |
||||
// 下载文件所在路径就在之前上传文件的那个文件夹
|
||||
String path = request.getServletContext().getRealPath("files"); |
||||
// 获取图片
|
||||
File file = new File(path,name); |
||||
// 创建输出流
|
||||
OutputStream outputStream = null; |
||||
if (file.exists()) { |
||||
// 设置响应头和类型
|
||||
response.setContentType("application/force-download"); |
||||
response.setHeader("Content-Disposition","attachment;filename="+name); |
||||
try { |
||||
outputStream = response.getOutputStream(); |
||||
outputStream.write(FileUtils.readFileToByteArray(file)); |
||||
outputStream.flush(); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} finally { |
||||
if (outputStream != null) { |
||||
outputStream.close(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,86 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import cc.bnblogs.entity.User; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 1:03 |
||||
*/ |
||||
@Controller |
||||
public class HelloHandler { |
||||
// 入参和params中的参数一一对应,且id必须等于10
|
||||
/** |
||||
* 请求url:http://localhost:8080/index?name=aaa&id=10
|
||||
* 通过@RequestMapping的params进行参数映射 |
||||
* 数据绑定: 在后端的业务方法中直接获取客户端HTTP请求中的参数,将请求参数映射到业务方法的形参中 |
||||
*/ |
||||
@RequestMapping(value = "/index",params = {"name","id=10"}) |
||||
public String index(String name,int id) { |
||||
System.out.println(name); |
||||
System.out.println(id); |
||||
System.out.println("执行了index方法"); |
||||
return "index"; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 请求url:http://localhost:8080/index1?name=aaa&id=10
|
||||
* 使用@RequestParam进行参数映射,将请求中的name参数值赋给str,id参数值赋给number |
||||
*/ |
||||
@RequestMapping(value = "/index1",params = {"name","id=10"}) |
||||
public String index1(@RequestParam("name") String str, @RequestParam("id") int number) { |
||||
System.out.println(str); |
||||
System.out.println(number); |
||||
System.out.println("执行了index1方法"); |
||||
return "index"; |
||||
} |
||||
|
||||
/** |
||||
* 编写RESTful风格API |
||||
* @param name |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
|
||||
@RequestMapping("rest/{name}/{id}/") |
||||
public String rest(@PathVariable("name") String name,@PathVariable("id") int id) { |
||||
System.out.println("执行了rest方法"); |
||||
return "index"; |
||||
} |
||||
|
||||
/** |
||||
* 从cookie中取出sessionId |
||||
* @param sessionId |
||||
* @return |
||||
*/ |
||||
@RequestMapping("cookie") |
||||
public String getSessionId(@CookieValue(value = "JSESSIONID") String sessionId) { |
||||
System.out.println(sessionId); |
||||
return "index"; |
||||
} |
||||
|
||||
@RequestMapping(value = "save",method = RequestMethod.POST) |
||||
public String save(User user) { |
||||
System.out.println(user); |
||||
return "index"; |
||||
} |
||||
|
||||
@RequestMapping("forward") |
||||
public String forward() { |
||||
// 默认就是转发请求,转发请求浏览器地址不会变
|
||||
// 相当于return "index";
|
||||
System.out.println("这是转发请求"); |
||||
return "forward:index.jsp"; |
||||
} |
||||
|
||||
@RequestMapping("redirect") |
||||
public String redirect() { |
||||
// 重定向到index.jsp,重定向请求浏览器地址会变
|
||||
System.out.println("这是重定向请求"); |
||||
return "redirect:index.jsp"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import cc.bnblogs.entity.Student; |
||||
import cc.bnblogs.service.StudentService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Collection; |
||||
|
||||
/** |
||||
* @description: 使用RESTful风格API |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 22:28 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("rest") |
||||
public class RestHandler { |
||||
@Autowired |
||||
private StudentService studentService; |
||||
@GetMapping("all") |
||||
public Collection<Student> findAllStudents() { |
||||
return studentService.findAll(); |
||||
} |
||||
@GetMapping("/") |
||||
public Student findStudentById(Integer id) { |
||||
return studentService.findById(id); |
||||
} |
||||
@PostMapping("save") |
||||
public void saveOrUpdateStudent(@RequestBody Student student) { |
||||
studentService.saveOrUpdate(student); |
||||
} |
||||
|
||||
@DeleteMapping("delete") |
||||
public void deleteStudentById(Integer id) { |
||||
studentService.deleteById(id); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,59 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import cc.bnblogs.entity.Account; |
||||
import cc.bnblogs.entity.Person; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.ui.Model; |
||||
import org.springframework.validation.BindingResult; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
import javax.validation.Valid; |
||||
|
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/26 17:57 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("validator") |
||||
public class ValidatorHandler { |
||||
@GetMapping("login") |
||||
public String login(Model model) { |
||||
// 绑定一个空数据,便于测试jsp
|
||||
model.addAttribute("account",new Account()); |
||||
return "login"; |
||||
} |
||||
|
||||
@PostMapping("/login") |
||||
public String login(@Validated Account account, BindingResult bindingResult) { |
||||
// 表单校验失败,返回登录页面
|
||||
if (bindingResult.hasErrors()) { |
||||
return "login"; |
||||
} |
||||
return "index"; |
||||
} |
||||
|
||||
@GetMapping("person") |
||||
public String person(Model model) { |
||||
model.addAttribute("person",new Person()); |
||||
return "person"; |
||||
} |
||||
|
||||
/** |
||||
* 校验person数据 |
||||
* @param person |
||||
* @param bindingResult |
||||
* @return |
||||
*/ |
||||
@PostMapping("/person") |
||||
public String person(@Valid Person person, BindingResult bindingResult) { |
||||
if (bindingResult.hasErrors()) { |
||||
return "person"; |
||||
} |
||||
return "index"; |
||||
} |
||||
} |
@ -0,0 +1,187 @@ |
||||
package cc.bnblogs.controller; |
||||
|
||||
import cc.bnblogs.entity.User; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.ui.Model; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.servlet.ModelAndView; |
||||
import org.springframework.web.servlet.View; |
||||
import org.springframework.web.servlet.view.InternalResourceView; |
||||
|
||||
import javax.servlet.ServletContext; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 17:40 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("view") |
||||
//@SessionAttributes(value = "user") // 所有添加到request的键为user的对象都保存到session中
|
||||
public class ViewHandler { |
||||
/** |
||||
* userMap不再是用来接收参数的,而是保存模型数据用来给view提供数据的 |
||||
* 使用Map保存数据 |
||||
* @param userMap |
||||
* @return |
||||
*/ |
||||
@RequestMapping("map") |
||||
public String map(Map<String, User> userMap) { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
userMap.put("user",user); |
||||
return "view"; |
||||
} |
||||
|
||||
/** |
||||
* 使用Model保存数据 |
||||
* @param model |
||||
* @return |
||||
*/ |
||||
@RequestMapping("model") |
||||
public String model(Model model) { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
model.addAttribute("user",user); |
||||
return "view"; |
||||
} |
||||
|
||||
/** |
||||
* 将模型和数据同时返回 |
||||
* @return |
||||
*/ |
||||
@RequestMapping("modelAndView") |
||||
public ModelAndView modelAndView() { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
ModelAndView modelAndView = new ModelAndView(); |
||||
// 添加model数据
|
||||
modelAndView.addObject("user",user); |
||||
// 添加view
|
||||
modelAndView.setViewName("view"); |
||||
return modelAndView; |
||||
} |
||||
|
||||
@RequestMapping("modelAndView1") |
||||
public ModelAndView modelAndView1() { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
ModelAndView modelAndView = new ModelAndView(); |
||||
// 添加model数据
|
||||
modelAndView.addObject("user",user); |
||||
View view = new InternalResourceView("/view.jsp"); |
||||
modelAndView.setView(view); |
||||
return modelAndView; |
||||
} |
||||
|
||||
@RequestMapping("modelAndView2") |
||||
public ModelAndView modelAndView2() { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
// 直接提供一个视图的名字
|
||||
ModelAndView modelAndView = new ModelAndView("view"); |
||||
modelAndView.addObject("user",user); |
||||
return modelAndView; |
||||
} |
||||
|
||||
@RequestMapping("modelAndView3") |
||||
public ModelAndView modelAndView3() { |
||||
Map<String,User> userMap = new HashMap<String, User>(); |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
userMap.put("user",user); |
||||
// 直接提供一个视图的名字
|
||||
return new ModelAndView("view",userMap); |
||||
} |
||||
|
||||
@RequestMapping("modelAndView4") |
||||
public ModelAndView modelAndView4() { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("张三"); |
||||
// 直接提供一个视图的名字
|
||||
return new ModelAndView("view","user",user); |
||||
} |
||||
|
||||
@RequestMapping("request") |
||||
public String request(HttpServletRequest request) { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("李四"); |
||||
request.setAttribute("user",user); |
||||
return "view"; |
||||
} |
||||
|
||||
/** |
||||
* 所有业务方法执行前都会先执行这个方法 |
||||
* request方式获取模型数据 |
||||
* @return |
||||
*/ |
||||
// @ModelAttribute
|
||||
public User getUser() { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("李四"); |
||||
return user; |
||||
} |
||||
|
||||
@RequestMapping("modelAttr") |
||||
public String getUserAttribute(){ |
||||
return "view"; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* session方式获取模型数据 |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
@RequestMapping("session") |
||||
public String session(HttpServletRequest request) { |
||||
HttpSession httpSession = request.getSession(); |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("李四"); |
||||
httpSession.setAttribute("user",user); |
||||
return "view"; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* session方式获取模型数据实现方式2 |
||||
* 直接获取session |
||||
* @param httpSession |
||||
* @return |
||||
*/ |
||||
@RequestMapping("session2") |
||||
public String session2(HttpSession httpSession) { |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("李四"); |
||||
httpSession.setAttribute("user",user); |
||||
return "view"; |
||||
} |
||||
|
||||
/** |
||||
* 从application中获取数据 |
||||
*/ |
||||
@RequestMapping("application") |
||||
public String application(HttpServletRequest request) { |
||||
ServletContext application = request.getServletContext(); |
||||
User user = new User(); |
||||
user.setId(18); |
||||
user.setName("李四"); |
||||
application.setAttribute("user",user); |
||||
return "view"; |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
package cc.bnblogs.converter; |
||||
|
||||
import org.springframework.core.convert.converter.Converter; |
||||
|
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @description: 自定义数据转换器,这里将String类型的数据转化为Date类型 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 20:47 |
||||
*/ |
||||
public class DateConverter implements Converter<String, Date> { |
||||
private final String pattern; |
||||
|
||||
public DateConverter(String pattern) { |
||||
this.pattern = pattern; |
||||
} |
||||
|
||||
public Date convert(String s) { |
||||
SimpleDateFormat format = new SimpleDateFormat(pattern); |
||||
Date date = null; |
||||
try { |
||||
date = format.parse(s); |
||||
} catch (ParseException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
return date; |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package cc.bnblogs.converter; |
||||
|
||||
import cc.bnblogs.entity.Student; |
||||
import org.springframework.core.convert.converter.Converter; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 21:26 |
||||
*/ |
||||
public class StudentConverter implements Converter<String, Student> { |
||||
public Student convert(String s) { |
||||
String[] args = s.split("-"); |
||||
Student student = new Student(); |
||||
student.setId(Integer.parseInt(args[0])); |
||||
student.setName(args[1]); |
||||
student.setAge(Integer.parseInt(args[2])); |
||||
return student; |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/26 17:49 |
||||
*/ |
||||
@Data |
||||
public class Account { |
||||
private String username; |
||||
private String password; |
||||
} |
@ -0,0 +1,13 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 14:45 |
||||
*/ |
||||
@Data |
||||
public class Address { |
||||
private String value; |
||||
} |
@ -0,0 +1,29 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.Email; |
||||
import javax.validation.constraints.NotEmpty; |
||||
import javax.validation.constraints.Pattern; |
||||
import javax.validation.constraints.Size; |
||||
|
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/26 18:35 |
||||
*/ |
||||
@Data |
||||
public class Person { |
||||
@NotEmpty(message = "用户名不能为空") |
||||
private String username; |
||||
@Size(min = 6,max=12,message = "密码必须为6-12位") |
||||
private String password; |
||||
@Email(regexp = "^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$",message = "请输入正确的邮箱") |
||||
private String email; |
||||
@Pattern(regexp = "^(?:(?:\\+|00)86)?1(?:(?:3[\\d])|(?:4[5-79])|\n" + |
||||
"(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|\n" + |
||||
"(?:8[\\d])|(?:9[189]))\\d{8}$",message = "请输入正确的电话") |
||||
private String phone; |
||||
|
||||
} |
@ -0,0 +1,19 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 21:21 |
||||
*/ |
||||
@Data |
||||
@AllArgsConstructor |
||||
@NoArgsConstructor |
||||
public class Student { |
||||
private Integer id; |
||||
private String name; |
||||
private Integer age; |
||||
} |
@ -0,0 +1,19 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* @description: 用户实体类 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 14:18 |
||||
*/ |
||||
@Data |
||||
@AllArgsConstructor |
||||
@NoArgsConstructor |
||||
public class User { |
||||
private Integer id; |
||||
private String name; |
||||
private Address address; |
||||
} |
@ -0,0 +1,15 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 15:37 |
||||
*/ |
||||
@Data |
||||
public class UserList { |
||||
private List<User> users; |
||||
} |
@ -0,0 +1,15 @@ |
||||
package cc.bnblogs.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 16:30 |
||||
*/ |
||||
@Data |
||||
public class UserMap { |
||||
private Map<String,User> users; |
||||
} |
@ -0,0 +1,18 @@ |
||||
package cc.bnblogs.service; |
||||
|
||||
import cc.bnblogs.entity.Student; |
||||
|
||||
import java.util.Collection; |
||||
|
||||
/** |
||||
* @description: Student业务接口 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 22:20 |
||||
*/ |
||||
public interface StudentService { |
||||
Collection<Student> findAll(); |
||||
Student findById(Integer id); |
||||
void saveOrUpdate(Student student); |
||||
void deleteById(Integer id); |
||||
|
||||
} |
@ -0,0 +1,43 @@ |
||||
package cc.bnblogs.service.impl; |
||||
|
||||
import cc.bnblogs.entity.Student; |
||||
import cc.bnblogs.service.StudentService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @description: Student业务具体实现 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/25 22:21 |
||||
*/ |
||||
@Service |
||||
public class StudentServiceImpl implements StudentService { |
||||
private static Map<Integer,Student> studentMap; |
||||
|
||||
static { |
||||
studentMap = new HashMap<Integer, Student>(); |
||||
studentMap.put(1,new Student(1,"张三",28)); |
||||
studentMap.put(2,new Student(2,"李四",20)); |
||||
studentMap.put(3,new Student(3,"王五",25)); |
||||
|
||||
} |
||||
|
||||
public Collection<Student> findAll() { |
||||
return studentMap.values(); |
||||
} |
||||
|
||||
public Student findById(Integer id) { |
||||
return studentMap.get(id); |
||||
} |
||||
|
||||
public void saveOrUpdate(Student student) { |
||||
studentMap.put(student.getId(),student); |
||||
} |
||||
|
||||
public void deleteById(Integer id) { |
||||
studentMap.remove(id); |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package cc.bnblogs.validator; |
||||
|
||||
import cc.bnblogs.entity.Account; |
||||
import org.springframework.validation.Errors; |
||||
import org.springframework.validation.ValidationUtils; |
||||
import org.springframework.validation.Validator; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/26 17:52 |
||||
*/ |
||||
|
||||
public class AccountValidator implements Validator { |
||||
/** |
||||
* 是否支持对该数据类型进行验证 |
||||
* @param aClass |
||||
* @return |
||||
*/ |
||||
public boolean supports(Class<?> aClass) { |
||||
return aClass.equals(Account.class); |
||||
} |
||||
|
||||
/** |
||||
* 验证的具体逻辑 |
||||
* @param o |
||||
* @param errors |
||||
*/ |
||||
public void validate(Object o, Errors errors) { |
||||
// 校验用户名
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"username",null,"用户名不能为空或空格"); |
||||
// 校验密码
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"password",null,"密码不能为空或空格"); |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:context="http://www.springframework.org/schema/context" |
||||
xmlns:mvc="http://www.springframework.org/schema/mvc" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> |
||||
<!--自动扫描--> |
||||
<!--扫描的包名和自己项目保持一致--> |
||||
<context:component-scan base-package="cc.bnblogs"></context:component-scan> |
||||
<!--配置视图解析器--> |
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> |
||||
<property name="prefix" value="/"></property> |
||||
<property name="suffix" value=".jsp"></property> |
||||
</bean> |
||||
<mvc:annotation-driven conversion-service="conversionService"> |
||||
<!--消息转换器配置--> |
||||
<!--用于解决controller返回给前端的数据乱码的问题--> |
||||
<mvc:message-converters register-defaults="true"> |
||||
<bean class="org.springframework.http.converter.StringHttpMessageConverter"> |
||||
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/> |
||||
</bean> |
||||
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> |
||||
<property name="supportedMediaTypes"> |
||||
<list> |
||||
<value>application/json;charset=UTF-8</value> |
||||
</list> |
||||
</property> |
||||
</bean> |
||||
</mvc:message-converters> |
||||
</mvc:annotation-driven> |
||||
|
||||
<!--配置自定义转换器--> |
||||
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> |
||||
<property name="converters"> |
||||
<list> |
||||
<!--配置日期转换器--> |
||||
<bean class="cc.bnblogs.converter.DateConverter"> |
||||
<constructor-arg type="java.lang.String" value="yyyy-MM-dd"/> |
||||
</bean> |
||||
|
||||
<!--配置学生数据转换器--> |
||||
<bean class="cc.bnblogs.converter.StudentConverter"> |
||||
</bean> |
||||
</list> |
||||
|
||||
</property> |
||||
</bean> |
||||
<!--配置文件组件--> |
||||
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> |
||||
</bean> |
||||
<!--注入自定义验证器--> |
||||
<bean id="accountValidator" class="cc.bnblogs.validator.AccountValidator" /> |
||||
<!--注册自定义验证器--> |
||||
<mvc:annotation-driven validator="accountValidator"/> |
||||
<!--使用JSR303校验必须加上这个配置--> |
||||
<mvc:annotation-driven></mvc:annotation-driven> |
||||
</beans> |
@ -0,0 +1,51 @@ |
||||
<!DOCTYPE web-app PUBLIC |
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" |
||||
"http://java.sun.com/dtd/web-app_2_3.dtd" > |
||||
|
||||
<web-app> |
||||
<display-name>Archetype Created Web Application</display-name> |
||||
<!--添加一个过滤器,避免终端乱码--> |
||||
<filter> |
||||
<filter-name>encodingFilter</filter-name> |
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> |
||||
<init-param> |
||||
<param-name>encoding</param-name> |
||||
<param-value>UTF-8</param-value> |
||||
</init-param> |
||||
</filter> |
||||
<!--拦截所有请求--> |
||||
<filter-mapping> |
||||
<filter-name>encodingFilter</filter-name> |
||||
<url-pattern>/*</url-pattern> |
||||
</filter-mapping> |
||||
<!--设置DispatcherServlet--> |
||||
<servlet> |
||||
<servlet-name>dispatcherServlet</servlet-name> |
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> |
||||
<init-param> |
||||
<param-name>contextConfigLocation</param-name> |
||||
<param-value>classpath:springmvc.xml</param-value> |
||||
</init-param> |
||||
</servlet> |
||||
<!--所有请求将会被拦截--> |
||||
<servlet-mapping> |
||||
<servlet-name>dispatcherServlet</servlet-name> |
||||
<url-pattern>/</url-pattern> |
||||
</servlet-mapping> |
||||
<!--js文件不交给dispatcherServlet处理,放行!--> |
||||
<servlet-mapping> |
||||
<servlet-name>default</servlet-name> |
||||
<url-pattern>*.js</url-pattern> |
||||
</servlet-mapping> |
||||
|
||||
<!--图片特殊处理!--> |
||||
<servlet-mapping> |
||||
<servlet-name>default</servlet-name> |
||||
<url-pattern>*.png</url-pattern> |
||||
</servlet-mapping> |
||||
|
||||
<servlet-mapping> |
||||
<servlet-name>default</servlet-name> |
||||
<url-pattern>*.jpg</url-pattern> |
||||
</servlet-mapping> |
||||
</web-app> |
@ -0,0 +1,37 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 16:47 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
<script type="text/javascript" src="js/jquery-3.6.4.min.js"> |
||||
</script> |
||||
<script type="text/javascript"> |
||||
$(function(){ |
||||
// 发送的json数据 |
||||
var user = { |
||||
id: 1, |
||||
name: "张三" |
||||
}; |
||||
// 发送一个ajax请求 |
||||
$.ajax({ |
||||
url: "data/json", |
||||
data: JSON.stringify(user), |
||||
type: "POST", |
||||
contentType: "application/json;charset=UTF-8", |
||||
dataType: "JSON", |
||||
success: function (data) { |
||||
alert(data.id + "---" + data.name); |
||||
} |
||||
}) |
||||
}) |
||||
</script> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
@ -0,0 +1,19 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 21:08 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form action="/convert/date" method="post"> |
||||
请输入一个日期: <input type="text" name="date" /> 格式(yyyy-MM-dd) <hr/> |
||||
<input type="submit" value="提交"> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,18 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/26 |
||||
Time: 15:17 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<a href="/file/download/1">1.png</a> |
||||
<a href="/file/download/2">2.png</a> |
||||
<a href="/file/download/3">3.png</a> |
||||
</body> |
||||
</html> |
@ -0,0 +1,6 @@ |
||||
<%@ page contentType="text/html;charset=utf-8" %> |
||||
<html> |
||||
<body> |
||||
<h2>Hello World!打印一些中文</h2> |
||||
</body> |
||||
</html> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/26 |
||||
Time: 18:04 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<%@ page isELIgnored="false" %> |
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form:form modelAttribute="account" action="/validator/login" method="post"> |
||||
姓名: <form:input path="username"/> <form:errors path="username"/><br /> |
||||
密码: <form:password path="password"/> <form:errors path="password"/><br /> |
||||
<input type="submit" value="登录"> |
||||
</form:form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,24 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/26 |
||||
Time: 19:40 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<%@ page isELIgnored="false" %> |
||||
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form:form modelAttribute="person" action="/validator/person" method="post"> |
||||
姓名: <form:input path="username"/> <form:errors path="username"/><br /> |
||||
密码: <form:password path="password"/> <form:errors path="password"/><br /> |
||||
邮箱: <form:input path="email"/> <form:errors path="email"/><br /> |
||||
电话: <form:input path="phone"/> <form:errors path="phone"/><br /> |
||||
<input type="submit" value="提交"> |
||||
</form:form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,23 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 14:21 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form action="save" method="post"> |
||||
<%--表单中name值和参数User的属性值对应--%> |
||||
<%--属性支持级联--%> |
||||
用户id: <input type="text" name="id"/><br/> |
||||
用户名: <input type="text" name="name"/><br/> |
||||
地址: <input type="text" name="address.value"/><br/> |
||||
<input type="submit" value="注册"> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,20 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 21:20 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form action="/convert/student" method="post"> |
||||
请输入学生信息: <input type="text" name="student" /> 格式(id-name-age) |
||||
<hr /> |
||||
<input type="submit" value="提交"> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,27 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 23:19 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<%@ page isELIgnored="false" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
<style> |
||||
img { |
||||
width: 200px; |
||||
} |
||||
</style> |
||||
</head> |
||||
<body> |
||||
<form action="/file/upload" method="post" enctype="multipart/form-data"> |
||||
<input type="file" name="img" /> |
||||
<hr/> |
||||
<input type="submit" value="上传"> |
||||
<img src="${requestScope.path}"> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,26 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/26 |
||||
Time: 14:21 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<%@ page isELIgnored="false" %> |
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form action="/file/uploads" method="post" enctype="multipart/form-data"> |
||||
file1: <input type="file" name="images" /> <br/> |
||||
file2: <input type="file" name="images" /> <br/> |
||||
file3: <input type="file" name="images" /> <br/> |
||||
<input type="submit" value="上传"> |
||||
</form> |
||||
<c:forEach items="${requestScope.path}" var="file"> |
||||
<img src="${file}" width="300px"> |
||||
</c:forEach> |
||||
</body> |
||||
</html> |
@ -0,0 +1,25 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 15:44 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<%--使用表单来发送post请求--%> |
||||
<form action="/data/list" method="post"> |
||||
用户1的id: <input type="text" name="users[0].id" /></br> |
||||
用户1的name: <input type="text" name="users[0].name" /></br> |
||||
用户2的id: <input type="text" name="users[1].id" /></br> |
||||
用户2的name: <input type="text" name="users[1].name" /></br> |
||||
用户3的id: <input type="text" name="users[2].id" /></br> |
||||
用户3的name: <input type="text" name="users[2].name" /></br> |
||||
<input type="submit" value="提交"> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,24 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 16:36 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<form action="/data/map" method="post"> |
||||
用户1的id: <input type="text" name="users['a'].id" /></br> |
||||
用户1的name: <input type="text" name="users['a'].name" /></br> |
||||
用户2的id: <input type="text" name="users['b'].id" /></br> |
||||
用户2的name: <input type="text" name="users['b'].name" /></br> |
||||
用户3的id: <input type="text" name="users['c'].id" /></br> |
||||
用户3的name: <input type="text" name="users['c'].name" /></br> |
||||
<input type="submit" value="提交"> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,20 @@ |
||||
<%-- |
||||
Created by IntelliJ IDEA. |
||||
User: 15270 |
||||
Date: 2023/3/25 |
||||
Time: 17:45 |
||||
To change this template use File | Settings | File Templates. |
||||
--%> |
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||
<%@page isELIgnored="false" %> |
||||
<%--注意添加上面这一行配置--%> |
||||
<html> |
||||
<head> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
${requestScope.user}<hr/> |
||||
${sessionScope.user}<hr/> |
||||
${applicationScope.user} |
||||
</body> |
||||
</html> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,57 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:context="http://www.springframework.org/schema/context" |
||||
xmlns:mvc="http://www.springframework.org/schema/mvc" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> |
||||
<!--自动扫描--> |
||||
<!--扫描的包名和自己项目保持一致--> |
||||
<context:component-scan base-package="cc.bnblogs"></context:component-scan> |
||||
<!--配置视图解析器--> |
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> |
||||
<property name="prefix" value="/"></property> |
||||
<property name="suffix" value=".jsp"></property> |
||||
</bean> |
||||
<mvc:annotation-driven conversion-service="conversionService"> |
||||
<!--消息转换器配置--> |
||||
<!--用于解决controller返回给前端的数据乱码的问题--> |
||||
<mvc:message-converters register-defaults="true"> |
||||
<bean class="org.springframework.http.converter.StringHttpMessageConverter"> |
||||
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/> |
||||
</bean> |
||||
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> |
||||
<property name="supportedMediaTypes"> |
||||
<list> |
||||
<value>application/json;charset=UTF-8</value> |
||||
</list> |
||||
</property> |
||||
</bean> |
||||
</mvc:message-converters> |
||||
</mvc:annotation-driven> |
||||
|
||||
<!--配置自定义转换器--> |
||||
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> |
||||
<property name="converters"> |
||||
<list> |
||||
<!--配置日期转换器--> |
||||
<bean class="cc.bnblogs.converter.DateConverter"> |
||||
<constructor-arg type="java.lang.String" value="yyyy-MM-dd"/> |
||||
</bean> |
||||
|
||||
<!--配置学生数据转换器--> |
||||
<bean class="cc.bnblogs.converter.StudentConverter"> |
||||
</bean> |
||||
</list> |
||||
|
||||
</property> |
||||
</bean> |
||||
<!--配置文件组件--> |
||||
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> |
||||
</bean> |
||||
<!--注入自定义验证器--> |
||||
<bean id="accountValidator" class="cc.bnblogs.validator.AccountValidator" /> |
||||
<!--注册自定义验证器--> |
||||
<mvc:annotation-driven validator="accountValidator"/> |
||||
<!--使用JSR303校验必须加上这个配置--> |
||||
<mvc:annotation-driven></mvc:annotation-driven> |
||||
</beans> |
@ -0,0 +1,5 @@ |
||||
#Generated by Maven |
||||
#Sat Mar 25 16:59:12 CST 2023 |
||||
version=1.0-SNAPSHOT |
||||
groupId=cc.bnblogs |
||||
artifactId=springmvcdemo |
@ -0,0 +1,6 @@ |
||||
cc\bnblogs\entity\UserMap.class |
||||
cc\bnblogs\entity\User.class |
||||
cc\bnblogs\entity\Address.class |
||||
cc\bnblogs\entity\UserList.class |
||||
cc\bnblogs\controller\DataController.class |
||||
cc\bnblogs\controller\HelloHandler.class |
@ -0,0 +1,6 @@ |
||||
D:\spring_study\springmvcdemo\src\main\java\cc\bnblogs\controller\DataController.java |
||||
D:\spring_study\springmvcdemo\src\main\java\cc\bnblogs\entity\User.java |
||||
D:\spring_study\springmvcdemo\src\main\java\cc\bnblogs\entity\Address.java |
||||
D:\spring_study\springmvcdemo\src\main\java\cc\bnblogs\entity\UserList.java |
||||
D:\spring_study\springmvcdemo\src\main\java\cc\bnblogs\controller\HelloHandler.java |
||||
D:\spring_study\springmvcdemo\src\main\java\cc\bnblogs\entity\UserMap.java |
Binary file not shown.
@ -0,0 +1,5 @@ |
||||
Manifest-Version: 1.0 |
||||
Created-By: IntelliJ IDEA |
||||
Built-By: 15270 |
||||
Build-Jdk: 1.8.0_342 |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue