parent
f3f3f51843
commit
50ffee212d
@ -0,0 +1,3 @@
|
||||
/gradlew text eol=lf
|
||||
*.bat text eol=crlf
|
||||
*.jar binary
|
@ -0,0 +1,37 @@
|
||||
HELP.md
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -0,0 +1,31 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.4.0'
|
||||
id 'io.spring.dependency-management' version '1.1.6'
|
||||
}
|
||||
|
||||
group = 'com.blog'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.4'
|
||||
runtimeOnly 'com.mysql:mysql-connector-j'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.4'
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
@ -0,0 +1,252 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
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
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
@ -0,0 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem 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, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
@ -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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.blog.demo</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>demo</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.5.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot Starter Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter Data JPA -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL Connector -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version> <!-- 请使用最新稳定版本 -->
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis Spring Boot Starter -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
<mainClass>com.blog.demo.DemoApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
rootProject.name = 'demo'
|
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.blog.demo.DemoApplication
|
||||
|
@ -0,0 +1,81 @@
|
||||
package com.blog.demo.Controller;
|
||||
|
||||
import com.blog.demo.entity.Post;
|
||||
import com.blog.demo.Service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/posts")
|
||||
public class PostController {
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 查询所有文章
|
||||
*
|
||||
* @return 文章列表
|
||||
*/
|
||||
@GetMapping("/findAll")
|
||||
public List<Post> getAllPosts() {
|
||||
return postService.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新文章
|
||||
*
|
||||
* @param post 新文章对象
|
||||
* @return 创建成功的响应
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<Void> addPost(@RequestBody Post post) {
|
||||
postService.insert(post);
|
||||
return ResponseEntity.created(null).build(); // 返回 201 Created 状态码
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章信息
|
||||
*
|
||||
* @param post 文章对象
|
||||
* @return 更新成功的响应
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public ResponseEntity<Void> updatePost(@RequestBody Post post) {
|
||||
try {
|
||||
postService.update(post);
|
||||
return ResponseEntity.noContent().build(); // 返回 204 No Content 状态码
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.badRequest().body(null); // 返回 400 Bad Request 状态码
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除文章
|
||||
*
|
||||
* @param id 文章ID
|
||||
* @return 删除成功的响应
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity<Void> deletePost(@PathVariable int id) {
|
||||
postService.deleteById(id);
|
||||
return ResponseEntity.noContent().build(); // 返回 204 No Content 状态码
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询文章
|
||||
*
|
||||
* @param id 文章ID
|
||||
* @return 文章对象或 404 Not Found 响应
|
||||
*/
|
||||
@GetMapping("/findById/{id}")
|
||||
public ResponseEntity<Post> findById(@PathVariable int id) {
|
||||
Optional<Post> post = postService.findById(id);
|
||||
return post.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
package com.blog.demo.Controller;
|
||||
|
||||
import com.blog.demo.entity.User;
|
||||
import com.blog.demo.Service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 查询所有用户
|
||||
*
|
||||
* @return 用户列表
|
||||
*/
|
||||
@GetMapping("/findAll")
|
||||
public List<User> getAllUsers() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新用户
|
||||
*
|
||||
* @param user 新用户对象
|
||||
* @return 创建成功的响应
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<Void> addUser(@RequestBody User user) {
|
||||
userService.insert(user);
|
||||
return ResponseEntity.created(null).build(); // 返回 201 Created 状态码
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @return 更新成功的响应
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public ResponseEntity<Void> updateUser(@RequestBody User user) {
|
||||
try {
|
||||
userService.update(user);
|
||||
return ResponseEntity.noContent().build(); // 返回 204 No Content 状态码
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.badRequest().body(null); // 返回 400 Bad Request 状态码
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 删除成功的响应
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity<Void> deleteUser(@PathVariable int id) {
|
||||
userService.deleteById(id);
|
||||
return ResponseEntity.noContent().build(); // 返回 204 No Content 状态码
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 用户对象或 404 Not Found 响应
|
||||
*/
|
||||
@GetMapping("/findById/{id}")
|
||||
public ResponseEntity<User> findById(@PathVariable int id) {
|
||||
Optional<User> user = userService.findById(id);
|
||||
return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.blog.demo.Controller;
|
||||
|
||||
import com.blog.demo.Service.UserSecurityQuestionsAnswersService;
|
||||
import com.blog.demo.entity.UserSecurityQuestionsAnswers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/usqa")
|
||||
public class UserSecurityQuestionsAnswersController {
|
||||
|
||||
@Autowired
|
||||
private UserSecurityQuestionsAnswersService userSecurityQuestionsAnswersService;
|
||||
|
||||
/**
|
||||
* 查询所有用户密保问题和答案
|
||||
*
|
||||
* @return 用户密保问题和答案列表
|
||||
*/
|
||||
@GetMapping("/findAll")
|
||||
public List<UserSecurityQuestionsAnswers> getAllUserSecurityQuestionsAnswers() {
|
||||
return userSecurityQuestionsAnswersService.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询用户密保问题和答案
|
||||
*
|
||||
* @param userID 记录ID
|
||||
* @return 用户密保问题和答案对象或 404 Not Found 响应
|
||||
*/
|
||||
@GetMapping("/findAllByUserId/{userID}")
|
||||
public ResponseEntity<List<UserSecurityQuestionsAnswers>> findAllByUserId(@PathVariable int userID) {
|
||||
List<UserSecurityQuestionsAnswers> results = userSecurityQuestionsAnswersService.findAllByUserId(userID);
|
||||
return ResponseEntity.ok(results);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新用户密保问题和答案
|
||||
*
|
||||
* @param userSecurityQuestionsAnswers 新用户密保问题和答案对象
|
||||
* @return 创建成功的响应
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<Void> addUserSecurityQuestionsAnswers(@RequestBody UserSecurityQuestionsAnswers userSecurityQuestionsAnswers) {
|
||||
userSecurityQuestionsAnswersService.insert(userSecurityQuestionsAnswers);
|
||||
return ResponseEntity.created(null).build(); // 返回 201 Created 状态码
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户密保问题和答案
|
||||
*
|
||||
* @param userSecurityQuestionsAnswers 用户密保问题和答案对象
|
||||
* @return 更新成功的响应
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public ResponseEntity<Void> updateUserSecurityQuestionsAnswers(@RequestBody UserSecurityQuestionsAnswers userSecurityQuestionsAnswers) {
|
||||
userSecurityQuestionsAnswersService.update(userSecurityQuestionsAnswers);
|
||||
return ResponseEntity.noContent().build(); // 返回 204 No Content 状态码
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除用户密保问题和答案
|
||||
*
|
||||
* @param recordID 记录ID
|
||||
* @return 删除成功的响应
|
||||
*/
|
||||
@DeleteMapping("/delete/{recordID}")
|
||||
public ResponseEntity<Void> deleteUserSecurityQuestionsAnswers(@PathVariable int recordID) {
|
||||
userSecurityQuestionsAnswersService.deleteById(recordID);
|
||||
return ResponseEntity.noContent().build(); // 返回 204 No Content 状态码
|
||||
}
|
||||
/**
|
||||
* 根据 userID 删除记录
|
||||
*
|
||||
* @param userID 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/delete-by-user-id/{userID}")
|
||||
public ResponseEntity<String> deleteByUserID(@PathVariable int userID) {
|
||||
userSecurityQuestionsAnswersService.deleteByUserID(userID);
|
||||
return ResponseEntity.ok("Records deleted successfully");
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.blog.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.blog.demo.Mapper;
|
||||
|
||||
import com.blog.demo.entity.Post;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper {
|
||||
|
||||
List<Post> findAll();
|
||||
|
||||
Post findById(int postID);
|
||||
|
||||
void insert(Post post);
|
||||
|
||||
void update(Post post);
|
||||
|
||||
void deleteById(int postID);
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.blog.demo.Mapper;
|
||||
|
||||
import com.blog.demo.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
List<User> findAll();
|
||||
|
||||
void insert(User user);
|
||||
|
||||
void update(User user);
|
||||
|
||||
void deleteById(int id);
|
||||
|
||||
User findById(int id);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.blog.demo.Mapper;
|
||||
|
||||
import com.blog.demo.entity.UserSecurityQuestionsAnswers;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserSecurityQuestionsAnswersMapper {
|
||||
|
||||
List<UserSecurityQuestionsAnswers> findAll();
|
||||
|
||||
void insert(UserSecurityQuestionsAnswers userSecurityQuestionsAnswers);
|
||||
|
||||
void update(UserSecurityQuestionsAnswers userSecurityQuestionsAnswers);
|
||||
|
||||
void deleteById(int recordID);
|
||||
|
||||
List<UserSecurityQuestionsAnswers> findAllByUserId(int userId);
|
||||
/**
|
||||
* 根据 userID 删除记录
|
||||
*
|
||||
* @param userID 用户ID
|
||||
*/
|
||||
void deleteByUserID(int userID);
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
package com.blog.demo.Service;
|
||||
|
||||
import com.blog.demo.Mapper.PostMapper;
|
||||
import com.blog.demo.entity.Post;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class PostService {
|
||||
|
||||
@Autowired
|
||||
private PostMapper postMapper;
|
||||
|
||||
/**
|
||||
* 查询所有文章
|
||||
*
|
||||
* @return 文章列表
|
||||
*/
|
||||
public List<Post> findAll() {
|
||||
return postMapper.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入新文章
|
||||
*
|
||||
* @param post 新文章对象
|
||||
*/
|
||||
public void insert(Post post) {
|
||||
postMapper.insert(post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章信息
|
||||
*
|
||||
* @param post 文章对象
|
||||
*/
|
||||
public void update(Post post) {
|
||||
if (post.getPostID() == 0) {
|
||||
throw new IllegalArgumentException("文章ID不能为空");
|
||||
}
|
||||
postMapper.update(post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除文章
|
||||
*
|
||||
* @param id 文章ID
|
||||
*/
|
||||
public void deleteById(int id) {
|
||||
postMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询文章
|
||||
*
|
||||
* @param id 文章ID
|
||||
* @return 可选的文章对象
|
||||
*/
|
||||
public Optional<Post> findById(int id) {
|
||||
return Optional.ofNullable(postMapper.findById(id));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
package com.blog.demo.Service;
|
||||
|
||||
import com.blog.demo.Mapper.UserSecurityQuestionsAnswersMapper;
|
||||
import com.blog.demo.entity.UserSecurityQuestionsAnswers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class UserSecurityQuestionsAnswersService {
|
||||
|
||||
@Autowired
|
||||
private UserSecurityQuestionsAnswersMapper userSecurityQuestionsAnswersMapper;
|
||||
|
||||
/**
|
||||
* 查询所有用户安全问题答案
|
||||
*
|
||||
* @return 用户安全问题答案列表
|
||||
*/
|
||||
public List<UserSecurityQuestionsAnswers> findAll() {
|
||||
return userSecurityQuestionsAnswersMapper.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入新的用户安全问题答案
|
||||
*
|
||||
* @param userSecurityQuestionsAnswers 新的用户安全问题答案对象
|
||||
*/
|
||||
public void insert(UserSecurityQuestionsAnswers userSecurityQuestionsAnswers) {
|
||||
userSecurityQuestionsAnswersMapper.insert(userSecurityQuestionsAnswers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户安全问题答案
|
||||
*
|
||||
* @param userSecurityQuestionsAnswers 用户安全问题答案对象
|
||||
*/
|
||||
public void update(UserSecurityQuestionsAnswers userSecurityQuestionsAnswers) {
|
||||
if (userSecurityQuestionsAnswers.getRecordID() == 0) {
|
||||
throw new IllegalArgumentException("记录ID不能为空");
|
||||
}
|
||||
userSecurityQuestionsAnswersMapper.update(userSecurityQuestionsAnswers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除用户安全问题答案
|
||||
*
|
||||
* @param recordID 记录ID
|
||||
*/
|
||||
public void deleteById(int recordID) {
|
||||
userSecurityQuestionsAnswersMapper.deleteById(recordID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询用户安全问题答案
|
||||
*
|
||||
* @param userID 记录ID
|
||||
* @return 可选的用户安全问题答案对象
|
||||
*/
|
||||
public List<UserSecurityQuestionsAnswers> findAllByUserId(int userID) {
|
||||
return userSecurityQuestionsAnswersMapper.findAllByUserId(userID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 userID 删除记录
|
||||
*
|
||||
* @param userID 用户ID
|
||||
*/
|
||||
public void deleteByUserID(int userID) {
|
||||
userSecurityQuestionsAnswersMapper.deleteByUserID(userID);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.blog.demo.Service;
|
||||
|
||||
import com.blog.demo.Mapper.UserMapper;
|
||||
import com.blog.demo.entity.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有用户
|
||||
*
|
||||
* @return 用户列表
|
||||
*/
|
||||
public List<User> findAll() {
|
||||
return userMapper.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入新用户
|
||||
*
|
||||
* @param user 新用户对象
|
||||
*/
|
||||
public void insert(User user) {
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
public void update(User user) {
|
||||
if (user.getUserID() == 0) {
|
||||
throw new IllegalArgumentException("用户ID不能为空");
|
||||
}
|
||||
userMapper.update(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
*/
|
||||
public void deleteById(int id) {
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 可选的用户对象
|
||||
*/
|
||||
public Optional<User> findById(int id) {
|
||||
return Optional.ofNullable(userMapper.findById(id));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.blog.demo.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**") // 允许所有路径
|
||||
.allowedOrigins("http://localhost:5173") // 允许的前端地址
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的 HTTP 方法
|
||||
.allowedHeaders("*") // 允许的头部
|
||||
.allowCredentials(true); // 是否允许发送 Cookie
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.blog.demo.entity;
|
||||
|
||||
public class Post {
|
||||
private int postID;
|
||||
private String title;
|
||||
private String content;
|
||||
private String publishTime;
|
||||
private int authorID;
|
||||
private String reviewStatus;
|
||||
private int isRecommended;
|
||||
|
||||
// 无参构造函数
|
||||
public Post() {
|
||||
}
|
||||
|
||||
// 有参构造函数
|
||||
public Post(int postID, String title, String content, String publishTime, int authorID, String reviewStatus, int isRecommended) {
|
||||
this.postID = postID;
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.publishTime = publishTime;
|
||||
this.authorID = authorID;
|
||||
this.reviewStatus = reviewStatus;
|
||||
this.isRecommended = isRecommended;
|
||||
}
|
||||
|
||||
// Getter 和 Setter 方法
|
||||
public int getPostID() {
|
||||
return postID;
|
||||
}
|
||||
|
||||
public void setPostID(int postID) {
|
||||
this.postID = postID;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getPublishTime() {
|
||||
return publishTime;
|
||||
}
|
||||
|
||||
public void setPublishTime(String publishTime) {
|
||||
this.publishTime = publishTime;
|
||||
}
|
||||
|
||||
public int getAuthorID() {
|
||||
return authorID;
|
||||
}
|
||||
|
||||
public void setAuthorID(int authorID) {
|
||||
this.authorID = authorID;
|
||||
}
|
||||
|
||||
public String getReviewStatus() {
|
||||
return reviewStatus;
|
||||
}
|
||||
|
||||
public void setReviewStatus(String reviewStatus) {
|
||||
this.reviewStatus = reviewStatus;
|
||||
}
|
||||
|
||||
public int getIsRecommended() {
|
||||
return isRecommended;
|
||||
}
|
||||
|
||||
public void setIsRecommended(int isRecommended) {
|
||||
this.isRecommended = isRecommended;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Post{" +
|
||||
"postID=" + postID +
|
||||
", title='" + title + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", publishTime='" + publishTime + '\'' +
|
||||
", authorID=" + authorID +
|
||||
", reviewStatus='" + reviewStatus + '\'' +
|
||||
", isRecommended=" + isRecommended +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.blog.demo.entity;
|
||||
|
||||
|
||||
public class User {
|
||||
|
||||
private int userID;
|
||||
private String username;
|
||||
private String phoneNumber;
|
||||
private String passwordHash;
|
||||
private String joinDate;
|
||||
private String userType;
|
||||
private String birthday;
|
||||
private String signature;
|
||||
private int login_status;
|
||||
|
||||
public User(int userID, String username, String phoneNumber, String passwordHash, String joinDate, String userType, String birthday, String signature, int login_status) {
|
||||
this.userID = userID;
|
||||
this.username = username;
|
||||
this.phoneNumber = phoneNumber;
|
||||
this.passwordHash = passwordHash;
|
||||
this.joinDate = joinDate;
|
||||
this.userType = userType;
|
||||
this.birthday = birthday;
|
||||
this.signature = signature;
|
||||
this.login_status = login_status;
|
||||
}
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public int getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
public void setUserID(int userID) {
|
||||
this.userID = userID;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
public void setPasswordHash(String passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
}
|
||||
|
||||
public String getJoinDate() {
|
||||
return joinDate;
|
||||
}
|
||||
|
||||
public void setJoinDate(String joinDate) {
|
||||
this.joinDate = joinDate;
|
||||
}
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public String getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public void setBirthday(String birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(String signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getLogin_status() {
|
||||
return login_status;
|
||||
}
|
||||
|
||||
public void setLogin_status(int login_status) {
|
||||
this.login_status = login_status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"userID=" + userID +
|
||||
", username='" + username + '\'' +
|
||||
", phoneNumber='" + phoneNumber + '\'' +
|
||||
", passwordHash='" + passwordHash + '\'' +
|
||||
", joinDate='" + joinDate + '\'' +
|
||||
", userType='" + userType + '\'' +
|
||||
", birthday='" + birthday + '\'' +
|
||||
", signature='" + signature + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.blog.demo.entity;
|
||||
|
||||
public class UserSecurityQuestionsAnswers {
|
||||
private int recordID;
|
||||
private int userID;
|
||||
private int questionNumber;
|
||||
private String questionContent;
|
||||
private String answerHash;
|
||||
|
||||
// 无参构造函数
|
||||
public UserSecurityQuestionsAnswers() {
|
||||
}
|
||||
|
||||
// 有参构造函数
|
||||
public UserSecurityQuestionsAnswers(int recordID, int userID, int questionNumber, String questionContent, String answerHash) {
|
||||
this.recordID = recordID;
|
||||
this.userID = userID;
|
||||
this.questionNumber = questionNumber;
|
||||
this.questionContent = questionContent;
|
||||
this.answerHash = answerHash;
|
||||
}
|
||||
|
||||
// Getter 和 Setter 方法
|
||||
public int getRecordID() {
|
||||
return recordID;
|
||||
}
|
||||
|
||||
public void setRecordID(int recordID) {
|
||||
this.recordID = recordID;
|
||||
}
|
||||
|
||||
public int getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
public void setUserID(int userID) {
|
||||
this.userID = userID;
|
||||
}
|
||||
|
||||
public int getQuestionNumber() {
|
||||
return questionNumber;
|
||||
}
|
||||
|
||||
public void setQuestionNumber(int questionNumber) {
|
||||
this.questionNumber = questionNumber;
|
||||
}
|
||||
|
||||
public String getQuestionContent() {
|
||||
return questionContent;
|
||||
}
|
||||
|
||||
public void setQuestionContent(String questionContent) {
|
||||
this.questionContent = questionContent;
|
||||
}
|
||||
|
||||
public String getAnswerHash() {
|
||||
return answerHash;
|
||||
}
|
||||
|
||||
public void setAnswerHash(String answerHash) {
|
||||
this.answerHash = answerHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserSecurityQuestionsAnswers{" +
|
||||
"recordID=" + recordID +
|
||||
", userID=" + userID +
|
||||
", questionNumber=" + questionNumber +
|
||||
", questionContent='" + questionContent + '\'' +
|
||||
", answerHash='" + answerHash + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.blog.demo.DemoApplication
|
||||
|
@ -0,0 +1,19 @@
|
||||
spring:
|
||||
mvc:
|
||||
hiddenmethod:
|
||||
filter:
|
||||
enabled: true
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
||||
username: root
|
||||
password: zxcvbnm
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mappers/*.xml
|
||||
type-aliases-package: com.blog.demo.Mapper
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
server:
|
||||
port: 8080
|
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.blog.demo.Mapper.PostMapper">
|
||||
|
||||
<select id="findAll" resultType="com.blog.demo.entity.Post">
|
||||
SELECT * FROM posts
|
||||
</select>
|
||||
|
||||
<select id="findById" parameterType="int" resultType="com.blog.demo.entity.Post">
|
||||
SELECT * FROM posts WHERE PostID = #{postID}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.blog.demo.entity.Post" useGeneratedKeys="true" keyProperty="postID">
|
||||
INSERT INTO posts (Title, Content, PublishTime, AuthorID, ReviewStatus, IsRecommended)
|
||||
VALUES (#{title}, #{content}, #{publishTime}, #{authorID}, #{reviewStatus}, #{isRecommended})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.blog.demo.entity.Post">
|
||||
UPDATE posts
|
||||
SET Title = #{title},
|
||||
Content = #{content},
|
||||
PublishTime = #{publishTime},
|
||||
AuthorID = #{authorID},
|
||||
ReviewStatus = #{reviewStatus},
|
||||
IsRecommended = #{isRecommended}
|
||||
WHERE PostID = #{postID}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="int">
|
||||
DELETE FROM posts WHERE PostID = #{postID}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.blog.demo.Mapper.UserMapper">
|
||||
|
||||
<resultMap id="UserResult" type="com.blog.demo.entity.User">
|
||||
<id column="userID" property="userID"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="phoneNumber" property="phoneNumber"/>
|
||||
<result column="passwordHash" property="passwordHash"/>
|
||||
<result column="joinDate" property="joinDate"/>
|
||||
<result column="userType" property="userType"/>
|
||||
<result column="birthday" property="birthday"/>
|
||||
<result column="signature" property="signature"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- findAll -->
|
||||
<select id="findAll" resultMap="UserResult">
|
||||
SELECT userID, username, phoneNumber, passwordHash, joinDate, userType, birthday, signature FROM users
|
||||
</select>
|
||||
|
||||
<!-- insert -->
|
||||
<insert id="insert" parameterType="com.blog.demo.entity.User">
|
||||
INSERT INTO users (userID, username, phoneNumber, passwordHash, joinDate, userType, birthday, signature)
|
||||
VALUES (#{userID}, #{username}, #{phoneNumber}, #{passwordHash}, #{joinDate}, #{userType}, #{birthday}, #{signature})
|
||||
</insert>
|
||||
|
||||
<!-- update -->
|
||||
<update id="update" parameterType="com.blog.demo.entity.User">
|
||||
UPDATE users SET username = #{username}, phoneNumber = #{phoneNumber}, passwordHash = #{passwordHash},
|
||||
joinDate = #{joinDate}, userType = #{userType}, birthday = #{birthday},
|
||||
signature = #{signature} WHERE userID = #{userID}
|
||||
</update>
|
||||
|
||||
<!-- deleteById -->
|
||||
<delete id="deleteById" parameterType="int">
|
||||
DELETE FROM users WHERE userID = #{userID}
|
||||
</delete>
|
||||
|
||||
<!-- findById -->
|
||||
<select id="findById" resultMap="UserResult" parameterType="int">
|
||||
SELECT userID, username, phoneNumber, passwordHash, joinDate, userType, birthday, signature FROM users WHERE userID = #{userID}
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.blog.demo.Mapper.UserSecurityQuestionsAnswersMapper">
|
||||
|
||||
<select id="findAll" resultType="com.blog.demo.entity.UserSecurityQuestionsAnswers">
|
||||
SELECT * FROM user_security_questions_answers
|
||||
</select>
|
||||
|
||||
<select id="findAllByUserId" resultType="com.blog.demo.entity.UserSecurityQuestionsAnswers">
|
||||
SELECT * FROM user_security_questions_answers WHERE userID = #{userID}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.blog.demo.entity.UserSecurityQuestionsAnswers" useGeneratedKeys="true" keyProperty="recordID">
|
||||
INSERT INTO user_security_questions_answers (userID, questionNumber, questionContent, answerHash)
|
||||
VALUES (#{userID}, #{questionNumber}, #{questionContent}, #{answerHash})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.blog.demo.entity.UserSecurityQuestionsAnswers">
|
||||
UPDATE user_security_questions_answers
|
||||
SET userID = #{userID},
|
||||
questionNumber = #{questionNumber},
|
||||
questionContent = #{questionContent},
|
||||
answerHash = #{answerHash}
|
||||
WHERE recordID = #{recordID}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="int">
|
||||
DELETE FROM user_security_questions_answers WHERE recordID = #{recordID}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByUserID">
|
||||
DELETE FROM user_security_questions_answers
|
||||
WHERE userID = #{userID}
|
||||
</delete>
|
||||
</mapper>
|
@ -0,0 +1,13 @@
|
||||
package com.blog.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DemoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.blog.demo.DemoApplication
|
||||
|
@ -0,0 +1,19 @@
|
||||
spring:
|
||||
mvc:
|
||||
hiddenmethod:
|
||||
filter:
|
||||
enabled: true
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
||||
username: root
|
||||
password: zxcvbnm
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mappers/*.xml
|
||||
type-aliases-package: com.blog.demo.Mapper
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
server:
|
||||
port: 8080
|
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,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.blog.demo.Mapper.PostMapper">
|
||||
|
||||
<select id="findAll" resultType="com.blog.demo.entity.Post">
|
||||
SELECT * FROM posts
|
||||
</select>
|
||||
|
||||
<select id="findById" parameterType="int" resultType="com.blog.demo.entity.Post">
|
||||
SELECT * FROM posts WHERE PostID = #{postID}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.blog.demo.entity.Post" useGeneratedKeys="true" keyProperty="postID">
|
||||
INSERT INTO posts (Title, Content, PublishTime, AuthorID, ReviewStatus, IsRecommended)
|
||||
VALUES (#{title}, #{content}, #{publishTime}, #{authorID}, #{reviewStatus}, #{isRecommended})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.blog.demo.entity.Post">
|
||||
UPDATE posts
|
||||
SET Title = #{title},
|
||||
Content = #{content},
|
||||
PublishTime = #{publishTime},
|
||||
AuthorID = #{authorID},
|
||||
ReviewStatus = #{reviewStatus},
|
||||
IsRecommended = #{isRecommended}
|
||||
WHERE PostID = #{postID}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="int">
|
||||
DELETE FROM posts WHERE PostID = #{postID}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.blog.demo.Mapper.UserMapper">
|
||||
|
||||
<resultMap id="UserResult" type="com.blog.demo.entity.User">
|
||||
<id column="userID" property="userID"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="phoneNumber" property="phoneNumber"/>
|
||||
<result column="passwordHash" property="passwordHash"/>
|
||||
<result column="joinDate" property="joinDate"/>
|
||||
<result column="userType" property="userType"/>
|
||||
<result column="birthday" property="birthday"/>
|
||||
<result column="signature" property="signature"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- findAll -->
|
||||
<select id="findAll" resultMap="UserResult">
|
||||
SELECT userID, username, phoneNumber, passwordHash, joinDate, userType, birthday, signature FROM users
|
||||
</select>
|
||||
|
||||
<!-- insert -->
|
||||
<insert id="insert" parameterType="com.blog.demo.entity.User">
|
||||
INSERT INTO users (userID, username, phoneNumber, passwordHash, joinDate, userType, birthday, signature)
|
||||
VALUES (#{userID}, #{username}, #{phoneNumber}, #{passwordHash}, #{joinDate}, #{userType}, #{birthday}, #{signature})
|
||||
</insert>
|
||||
|
||||
<!-- update -->
|
||||
<update id="update" parameterType="com.blog.demo.entity.User">
|
||||
UPDATE users SET username = #{username}, phoneNumber = #{phoneNumber}, passwordHash = #{passwordHash},
|
||||
joinDate = #{joinDate}, userType = #{userType}, birthday = #{birthday},
|
||||
signature = #{signature} WHERE userID = #{userID}
|
||||
</update>
|
||||
|
||||
<!-- deleteById -->
|
||||
<delete id="deleteById" parameterType="int">
|
||||
DELETE FROM users WHERE userID = #{userID}
|
||||
</delete>
|
||||
|
||||
<!-- findById -->
|
||||
<select id="findById" resultMap="UserResult" parameterType="int">
|
||||
SELECT userID, username, phoneNumber, passwordHash, joinDate, userType, birthday, signature FROM users WHERE userID = #{userID}
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.blog.demo.Mapper.UserSecurityQuestionsAnswersMapper">
|
||||
|
||||
<select id="findAll" resultType="com.blog.demo.entity.UserSecurityQuestionsAnswers">
|
||||
SELECT * FROM user_security_questions_answers
|
||||
</select>
|
||||
|
||||
<select id="findAllByUserId" resultType="com.blog.demo.entity.UserSecurityQuestionsAnswers">
|
||||
SELECT * FROM user_security_questions_answers WHERE userID = #{userID}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.blog.demo.entity.UserSecurityQuestionsAnswers" useGeneratedKeys="true" keyProperty="recordID">
|
||||
INSERT INTO user_security_questions_answers (userID, questionNumber, questionContent, answerHash)
|
||||
VALUES (#{userID}, #{questionNumber}, #{questionContent}, #{answerHash})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.blog.demo.entity.UserSecurityQuestionsAnswers">
|
||||
UPDATE user_security_questions_answers
|
||||
SET userID = #{userID},
|
||||
questionNumber = #{questionNumber},
|
||||
questionContent = #{questionContent},
|
||||
answerHash = #{answerHash}
|
||||
WHERE recordID = #{recordID}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="int">
|
||||
DELETE FROM user_security_questions_answers WHERE recordID = #{recordID}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByUserID">
|
||||
DELETE FROM user_security_questions_answers
|
||||
WHERE userID = #{userID}
|
||||
</delete>
|
||||
</mapper>
|
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
artifactId=demo
|
||||
groupId=com.blog.demo
|
||||
version=1.0.0
|
@ -0,0 +1,14 @@
|
||||
com\blog\demo\Controller\PostController.class
|
||||
com\blog\demo\entity\Post.class
|
||||
com\blog\demo\Mapper\PostMapper.class
|
||||
com\blog\demo\Service\UserService.class
|
||||
com\blog\demo\Controller\UserSecurityQuestionsAnswersController.class
|
||||
com\blog\demo\DemoApplication.class
|
||||
com\blog\demo\Controller\UserController.class
|
||||
com\blog\demo\Service\PostService.class
|
||||
com\blog\demo\config\WebConfig.class
|
||||
com\blog\demo\Mapper\UserSecurityQuestionsAnswersMapper.class
|
||||
com\blog\demo\Service\UserSecurityQuestionsAnswersService.class
|
||||
com\blog\demo\entity\User.class
|
||||
com\blog\demo\entity\UserSecurityQuestionsAnswers.class
|
||||
com\blog\demo\Mapper\UserMapper.class
|
@ -0,0 +1,14 @@
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Controller\PostController.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\DemoApplication.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Controller\UserSecurityQuestionsAnswersController.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Controller\UserController.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\entity\User.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\entity\UserSecurityQuestionsAnswers.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Service\UserSecurityQuestionsAnswersService.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Mapper\PostMapper.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Service\PostService.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\config\WebConfig.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\entity\Post.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Service\UserService.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Mapper\UserMapper.java
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\main\java\com\blog\demo\Mapper\UserSecurityQuestionsAnswersMapper.java
|
@ -0,0 +1 @@
|
||||
com\blog\demo\DemoApplicationTests.class
|
@ -0,0 +1 @@
|
||||
C:\Users\YIQI\IdeaProjects\demo\src\test\java\com\blog\demo\DemoApplicationTests.java
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,4 @@
|
||||
-------------------------------------------------------------------------------
|
||||
Test set: com.blog.demo.DemoApplicationTests
|
||||
-------------------------------------------------------------------------------
|
||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.141 s - in com.blog.demo.DemoApplicationTests
|
Binary file not shown.
Loading…
Reference in new issue