learn02
This commit is contained in:
parent
63b67ae57f
commit
3f8d7e5fc5
@ -1,16 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="BUILD_PROCESS_HEAP_SIZE" value="2048" />
|
||||
<option name="USE_RELEASE_OPTION" value="false" />
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile default="true" name="Default" enabled="true">
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<processorPath useProcessorModulePath="true">
|
||||
<entry name="$PROJECT_DIR$/lib/lombok.jar" />
|
||||
</processorPath>
|
||||
</profile>
|
||||
<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="test05" />
|
||||
</profile>
|
||||
<profile name="Annotation profile for learn03-springboot" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<processorPath useClasspath="false">
|
||||
<entry name="D:/software/dev/maven/apache-maven-3.9.9/repository/org/projectlombok/lombok/release/lombok-release.jar" />
|
||||
</processorPath>
|
||||
<module name="learn03-springboot" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel target="21">
|
||||
<module name="learn03" target="21" />
|
||||
</bytecodeTargetLevel>
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="learn03-springboot" options="-parameters" />
|
||||
<module name="test05" options="-parameters" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@ -10,6 +10,7 @@
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
|
||||
@ -1,13 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" defaultCharsetForPropertiesFiles="GBK">
|
||||
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="GBK">
|
||||
<file url="file://$PROJECT_DIR$/.gitignore" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn02/web/js/course-edit.js" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn02/web/js/index.js" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03/src/main/java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/learn03/src/main/resources" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/Learn03SpringbootApplication.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/ServletInitializer.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/common/DBTool.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/controller/CourseController.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/controller/HelloController.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/CourseDB.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/ScoreDB.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/StudentDB.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/TeacherDB.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/UserDB.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/impl/CourseDBImpl.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/impl/TeacherDBImpl.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/dao/impl/UserDBImpl.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/Course.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/CourseInfo.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/Result.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/ScoreInfo.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/StudentInfo.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/TeacherInfo.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/main/java/top/awin_x/learn/pojo/UserInfo.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn03-springboot/src/test/java/top/awin_x/learn/Learn03SpringbootApplicationTests.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn1/web/js/course-edit.js" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn1/web/js/index.js" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/test05/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/test05/src/main/java/test05/mapper/CourseMapper.java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/test05/src/test/java/test05/Test05ApplicationTests.java" charset="UTF-8" />
|
||||
<file url="PROJECT" charset="GBK" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
@ -16,5 +21,10 @@
|
||||
<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>
|
||||
@ -1,9 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lombok">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/lombok.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@ -6,13 +6,9 @@
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/learn03/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/learn03-springboot/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/test05/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="ignoredFiles">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$/learn03/pom.xml" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
|
||||
@ -22,5 +22,6 @@
|
||||
<orderEntry type="library" name="commons-dbcp2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="commons-logging-1.3.4" level="project" />
|
||||
<orderEntry type="library" name="commons-pool2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@ -24,7 +24,7 @@
|
||||
<orderEntry type="library" name="commons-pool2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="mysql-connector" level="project" />
|
||||
<orderEntry type="library" name="sqlite-jdbc-3.47.0.0" level="project" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
<orderEntry type="library" name="Tomcat 10.1.31" level="application_server_libraries" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@ -25,35 +25,35 @@ new Vue({
|
||||
});
|
||||
|
||||
function getCourses(){
|
||||
// $.ajax({
|
||||
// url: path+"/courseAction/list",
|
||||
// method: "GET",
|
||||
// success: (data, status, xhr)=>{
|
||||
// const course_list = document.getElementById('course-list');
|
||||
// console.log(xhr.status);
|
||||
// course_list.innerHTML = "<tr class=\"tr-head\"><td class=\"tr-head\" colspan=\"6\">课程信息列表</td></tr> <tr> <td>名称</td> <td>性质</td> <td>学分</td> <td>开设年级</td> <td>开设专业</td> </tr>"
|
||||
// courses = data;
|
||||
// for (let i in data){
|
||||
// const course_tr = document.createElement('tr');
|
||||
// course_tr.innerHTML="<td>"+ data[i].name +"</td>" +
|
||||
// "<td>"+types[data[i].type]+"</td>" +
|
||||
// "<td>"+ data[i].credit +"</td>" +
|
||||
// "<td>"+ data[i].grade + "</td>" +
|
||||
// "<td>"+ majors[data[i].major]+"</td>" +
|
||||
// "<td><a class='blue' onclick=\"editCourse("+ i + ")\" " +
|
||||
// ">编辑</a> <a class='red' href=\""+path+"/courseAction/delete?id=" +
|
||||
// data[i].id+"\">删除</a></td>";
|
||||
// course_list.appendChild(course_tr);
|
||||
// }
|
||||
// const end_tr = document.createElement('tr');
|
||||
// end_tr.innerHTML="<td><a href=\"#\" class='blue' onclick=\"addCourse()\">添加</a></td><td></td><td></td><td></td><td>" +
|
||||
// "<a href=\"#\" class='blue' onclick=\"getCourses()\">刷新数据列表</a></td><td></td>";
|
||||
// course_list.appendChild(end_tr);
|
||||
// },
|
||||
// error: ()=>{
|
||||
// window.location=path+"/login/login.jsp";
|
||||
// }
|
||||
// });
|
||||
$.ajax({
|
||||
url: path+"/courseAction/list",
|
||||
method: "GET",
|
||||
success: (data, status, xhr)=>{
|
||||
const course_list = document.getElementById('course-list');
|
||||
console.log(xhr.status);
|
||||
course_list.innerHTML = "<tr class=\"tr-head\"><td class=\"tr-head\" colspan=\"6\">课程信息列表</td></tr> <tr> <td>名称</td> <td>性质</td> <td>学分</td> <td>开设年级</td> <td>开设专业</td> </tr>"
|
||||
courses = data;
|
||||
for (let i in data){
|
||||
const course_tr = document.createElement('tr');
|
||||
course_tr.innerHTML="<td>"+ data[i].name +"</td>" +
|
||||
"<td>"+types[data[i].type]+"</td>" +
|
||||
"<td>"+ data[i].credit +"</td>" +
|
||||
"<td>"+ data[i].grade + "</td>" +
|
||||
"<td>"+ majors[data[i].major]+"</td>" +
|
||||
"<td><a class='blue' onclick=\"editCourse("+ i + ")\" " +
|
||||
">编辑</a> <a class='red' href=\""+path+"/courseAction/delete?id=" +
|
||||
data[i].id+"\">删除</a></td>";
|
||||
course_list.appendChild(course_tr);
|
||||
}
|
||||
const end_tr = document.createElement('tr');
|
||||
end_tr.innerHTML="<td><a href=\"#\" class='blue' onclick=\"addCourse()\">添加</a></td><td></td><td></td><td></td><td>" +
|
||||
"<a href=\"#\" class='blue' onclick=\"getCourses()\">刷新数据列表</a></td><td></td>";
|
||||
course_list.appendChild(end_tr);
|
||||
},
|
||||
error: ()=>{
|
||||
window.location=path+"/login/login.jsp";
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).ready(getCourses);
|
||||
|
||||
|
||||
2
learn03-springboot/.gitattributes
vendored
2
learn03-springboot/.gitattributes
vendored
@ -1,2 +0,0 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
1
learn03-springboot/.gitignore
vendored
1
learn03-springboot/.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
# 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
|
||||
#
|
||||
# http://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.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
259
learn03-springboot/mvnw
vendored
259
learn03-springboot/mvnw
vendored
@ -1,259 +0,0 @@
|
||||
#!/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
|
||||
#
|
||||
# http://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.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
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"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||
|
||||
exec_maven() {
|
||||
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||
}
|
||||
|
||||
if [ -d "$MAVEN_HOME" ]; then
|
||||
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
exec_maven "$@"
|
||||
fi
|
||||
|
||||
case "${distributionUrl-}" in
|
||||
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||
esac
|
||||
|
||||
# prepare tmp dir
|
||||
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||
trap clean HUP INT TERM EXIT
|
||||
else
|
||||
die "cannot create temp dir"
|
||||
fi
|
||||
|
||||
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||
|
||||
# Download and Install Apache Maven
|
||||
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
verbose "Downloading from: $distributionUrl"
|
||||
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
# select .zip or .tar.gz
|
||||
if ! command -v unzip >/dev/null; then
|
||||
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
fi
|
||||
|
||||
# verbose opt
|
||||
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||
|
||||
# normalize http auth
|
||||
case "${MVNW_PASSWORD:+has-password}" in
|
||||
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
esac
|
||||
|
||||
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||
verbose "Found wget ... using wget"
|
||||
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||
verbose "Found curl ... using curl"
|
||||
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||
elif set_java_home; then
|
||||
verbose "Falling back to use Java to download"
|
||||
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
cat >"$javaSource" <<-END
|
||||
public class Downloader extends java.net.Authenticator
|
||||
{
|
||||
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||
}
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
setDefault( new Downloader() );
|
||||
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||
}
|
||||
}
|
||||
END
|
||||
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||
verbose " - Compiling Downloader.java ..."
|
||||
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||
verbose " - Running Downloader.java ..."
|
||||
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||
fi
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
if [ -n "${distributionSha256Sum-}" ]; then
|
||||
distributionSha256Result=false
|
||||
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
elif command -v sha256sum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
elif command -v shasum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $distributionSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# unzip and move
|
||||
if command -v unzip >/dev/null; then
|
||||
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||
else
|
||||
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||
fi
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
||||
149
learn03-springboot/mvnw.cmd
vendored
149
learn03-springboot/mvnw.cmd
vendored
@ -1,149 +0,0 @@
|
||||
<# : batch portion
|
||||
@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 http://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 Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||
}
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
@ -39,7 +39,8 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
<version>1.18.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -51,6 +52,38 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intellij</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>6.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.47.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
<version>1.2.24</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -63,6 +96,7 @@
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>release</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
package top.awin_x.learn.common;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSourceFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* 这是一个数据库工具类,创建了一个数据库连接池
|
||||
* 需要在database.properties中配置数据库连接属性
|
||||
* @author Awin-x
|
||||
*/
|
||||
public class DBTool {
|
||||
static DataSource ds;
|
||||
static{
|
||||
Properties prop = new Properties();
|
||||
try {
|
||||
InputStream database_info = DBTool.class.getClassLoader().getResourceAsStream("database.properties");
|
||||
if (database_info != null) {
|
||||
prop.load(new InputStreamReader(database_info, "GBK"));
|
||||
prop.list(System.out);
|
||||
}else{
|
||||
throw new FileNotFoundException("database.properties file does not exist in the classpath");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("数据库配置加载失败!");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
ds = BasicDataSourceFactory.createDataSource(prop);
|
||||
} catch (Exception e) {
|
||||
System.out.println("数据库连接池初始化失败");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection(){
|
||||
try{
|
||||
return ds.getConnection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PreparedStatement getPreparedStatement(String sql) throws SQLException{
|
||||
//noinspection SqlSourceToSinkFlow
|
||||
return ds.getConnection().prepareStatement(sql);
|
||||
}
|
||||
|
||||
public static void close(Connection conn, PreparedStatement ps, ResultSet rs){
|
||||
try{
|
||||
if(rs != null){
|
||||
rs.close();
|
||||
}
|
||||
if(ps != null){
|
||||
ps.close();
|
||||
}
|
||||
if(conn != null){
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.out.println("关闭失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void close(PreparedStatement ps, ResultSet rs) throws SQLException {
|
||||
close(ps.getConnection(), ps, rs);
|
||||
}
|
||||
|
||||
public static void close(PreparedStatement ps) throws SQLException {
|
||||
close(ps.getConnection(), ps, null);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package top.awin_x.learn.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.awin_x.learn.pojo.CourseInfo;
|
||||
import top.awin_x.learn.pojo.Result;
|
||||
import top.awin_x.learn.service.CourseService;
|
||||
import top.awin_x.learn.service.impl.CourseServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RestController
|
||||
public class CourseController {
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@RequestMapping("/courseAction/list")
|
||||
public Result listCourse(Integer page, Integer pageSize, String keyword, Integer type) {
|
||||
ArrayList<CourseInfo> list = courseService.listCourses(page, pageSize, keyword, type);
|
||||
return Result.success(list);
|
||||
}
|
||||
@RequestMapping("/courseAction/edit")
|
||||
public Result editCourse(CourseInfo course) {
|
||||
return Result.success(new CourseServiceImpl().editCourse(course));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package top.awin_x.learn.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.awin_x.learn.pojo.CourseInfo;
|
||||
import top.awin_x.learn.pojo.Result;
|
||||
import top.awin_x.learn.service.impl.CourseServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class HelloController {
|
||||
@GetMapping("/hello1")
|
||||
public String hello() {
|
||||
System.out.println("Hello World");
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
@GetMapping("/helloWithParam")
|
||||
public String helloWithParam(HttpServletRequest request) {
|
||||
String name = request.getParameter("name");
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
@GetMapping("/helloWithParam2")
|
||||
public String helloWithParam2(String name, Integer age) {
|
||||
return "Hello " + name + " " + age;
|
||||
}
|
||||
|
||||
@GetMapping("/helloWithParam3")
|
||||
public String helloWithParam3(CourseInfo courseInfo) {
|
||||
System.out.println(courseInfo);
|
||||
return "Hello " + courseInfo.getName();
|
||||
}
|
||||
|
||||
@GetMapping("/helloWithJSON")
|
||||
public String helloWithJSON(@RequestBody CourseInfo courseInfo) {
|
||||
System.out.println(courseInfo);
|
||||
return "Hello " + courseInfo.getName();
|
||||
}
|
||||
|
||||
@GetMapping("/helloWithPath/{name}")
|
||||
public String helloWithPath(@PathVariable String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
@GetMapping("/helloWithResultReturn")
|
||||
public Result helloWithResultReturn(String name) {
|
||||
Result result = new Result();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(name);
|
||||
result.setData(list);
|
||||
result.setMsg("Hello " + name);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package top.awin_x.learn.dao;
|
||||
|
||||
|
||||
|
||||
import top.awin_x.learn.pojo.CourseInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface CourseDB {
|
||||
/**
|
||||
* 用于列出全部课程
|
||||
* @return 返回从数据库中查询到的全部课程
|
||||
*/
|
||||
ArrayList<CourseInfo> getAllCourseInfo();
|
||||
|
||||
/**
|
||||
* 用于分页列出筛选课程
|
||||
* @param page 页码
|
||||
* @param pageSize 每页条数
|
||||
* @param keyword 关键词筛选,为空字符串表示不筛选
|
||||
* @param type 类型筛选,为0表示不筛选
|
||||
* @return 返回从数据库查询到的该页课程
|
||||
*/
|
||||
ArrayList<CourseInfo> getCourseInfos(int page, int pageSize, String keyword, int type);
|
||||
|
||||
/**
|
||||
* 用于获取一个课程
|
||||
* @param id 目标课程的id
|
||||
* @return 根据id从数据库查询到的课程信息
|
||||
*/
|
||||
CourseInfo getCourseInfoByID(int id);
|
||||
|
||||
/**
|
||||
* 用于获取课程总数
|
||||
* @return 返回数据库中课程信息条数
|
||||
*/
|
||||
int getAllCourseInfoCount();
|
||||
|
||||
/**
|
||||
* 获取一个课程筛选结果集的总数
|
||||
* @param keyword 关键词筛选,为空字符串表示不筛选
|
||||
* @param type 类型筛选,为0表示不筛选
|
||||
* @return 课程筛选结果集的总数
|
||||
*/
|
||||
int getAllCourseInfoCount(String keyword, int type);
|
||||
|
||||
/**
|
||||
* 用于添加课程
|
||||
* @param courseInfo 要添加的课程
|
||||
* @return 影响数据库行数,行数大于0则说明添加成功
|
||||
*/
|
||||
int addCourseInfo(CourseInfo courseInfo);
|
||||
|
||||
/**
|
||||
* 用于更新一个课程信息
|
||||
* @param courseInfo 修改的课程信息,id不可修改,id作为修改目标查找参数
|
||||
* @return 影响的行数,行数大于0则说明更新成功
|
||||
*/
|
||||
int updateCourseInfo(CourseInfo courseInfo);
|
||||
|
||||
/**
|
||||
* 用于删除一个课程
|
||||
* @param id 要删除的课程的id
|
||||
* @return 影响的行数,行数大于0则说明更新成功
|
||||
*/
|
||||
int deleteCourseInfo(int id);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package top.awin_x.learn.dao;
|
||||
|
||||
|
||||
import top.awin_x.learn.pojo.ScoreInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ScoreDB {
|
||||
ScoreInfo getScoreInfoByID(int studentID, int courseID);
|
||||
ArrayList<ScoreInfo> getScoreInfoByStudentID(int studentID);
|
||||
ArrayList<ScoreInfo> getScoreInfoByCourseID(int courseID);
|
||||
int getScoreByStudentID(int studentID);
|
||||
int addScoreInfo(ScoreInfo scoreInfo);
|
||||
int updateScoreInfo(ScoreInfo scoreInfo);
|
||||
int deleteScoreInfo(int studentID, int courseID);
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package top.awin_x.learn.dao;
|
||||
|
||||
|
||||
import top.awin_x.learn.pojo.StudentInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface StudentDB {
|
||||
ArrayList<StudentInfo> getAllStudentInfo();
|
||||
|
||||
StudentInfo getStudentInfoByID(int id);
|
||||
|
||||
StudentInfo getStudentInfoByName(String name);
|
||||
|
||||
StudentInfo getStudentInfoByCode(String code);
|
||||
|
||||
int addStudentInfo(StudentInfo studentInfo);
|
||||
|
||||
int updateStudentInfo(StudentInfo studentInfo);
|
||||
|
||||
int deleteStudentInfo(int id);
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package top.awin_x.learn.dao;
|
||||
|
||||
|
||||
import top.awin_x.learn.pojo.TeacherInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface TeacherDB {
|
||||
ArrayList<TeacherInfo> getAllTeacherInfo();
|
||||
|
||||
TeacherInfo getTeacherInfoByID(int id);
|
||||
|
||||
TeacherInfo getTeacherInfoByName(String name);
|
||||
|
||||
int addTeacherInfo(TeacherInfo teacherInfo);
|
||||
|
||||
int updateTeacherInfo(TeacherInfo teacherInfo);
|
||||
|
||||
int deleteTeacherInfo(int id);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package top.awin_x.learn.dao;
|
||||
|
||||
|
||||
import top.awin_x.learn.pojo.UserInfo;
|
||||
|
||||
public interface UserDB {
|
||||
UserInfo getUserByName(String username);
|
||||
|
||||
UserInfo getUserById(int id);
|
||||
|
||||
int addUser(UserInfo user);
|
||||
|
||||
int updateUser(UserInfo user);
|
||||
|
||||
int deleteUser(int id);
|
||||
}
|
||||
@ -0,0 +1,180 @@
|
||||
package top.awin_x.learn.dao.impl;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import top.awin_x.learn.common.DBTool;
|
||||
import top.awin_x.learn.dao.CourseDB;
|
||||
import top.awin_x.learn.pojo.CourseInfo;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Repository
|
||||
public class CourseDBImpl implements CourseDB {
|
||||
|
||||
private CourseInfo fillCourseInfo(ResultSet rs) throws SQLException {
|
||||
CourseInfo courseInfo = new CourseInfo();
|
||||
courseInfo.setId(rs.getInt("N_COURSE_ID"));
|
||||
courseInfo.setName(rs.getString("VC_COURSE_NAME"));
|
||||
courseInfo.setType(rs.getInt("N_TYPE"));
|
||||
courseInfo.setCredit(rs.getFloat("F_CREDIT"));
|
||||
courseInfo.setGrade(rs.getInt("N_GRADE"));
|
||||
courseInfo.setMajor(rs.getInt("N_MAJOR"));
|
||||
courseInfo.setDetail(rs.getString("VC_DETAIL"));
|
||||
return courseInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<CourseInfo> getAllCourseInfo() {
|
||||
ArrayList<CourseInfo> courseList = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DBTool.getPreparedStatement("SELECT * FROM t_course");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
courseList.add(fillCourseInfo(rs));
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return courseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<CourseInfo> getCourseInfos(int page, int pageSize, String keyword, int type) {
|
||||
ArrayList<CourseInfo> courseList = new ArrayList<>();
|
||||
String sql = "SELECT * FROM t_course WHERE UPPER(VC_COURSE_NAME) LIKE ? AND ? IN (N_TYPE, 0) ORDER BY N_COURSE_ID LIMIT ?, ?";
|
||||
try {
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setString(1, "%"+keyword.toUpperCase()+"%");
|
||||
ps.setInt(2, type);
|
||||
ps.setInt(3, (page - 1) * pageSize);
|
||||
ps.setInt(4, pageSize);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
courseList.add(fillCourseInfo(rs));
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return courseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CourseInfo getCourseInfoByID(int id) {
|
||||
CourseInfo courseInfo = null;
|
||||
try {
|
||||
PreparedStatement ps = DBTool.getPreparedStatement("select * from t_course WHERE N_COURSE_ID = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("VC_COURSE_NAME");
|
||||
int type = rs.getInt("N_TYPE");
|
||||
float credits = rs.getFloat("F_CREDIT");
|
||||
int grade = rs.getInt("N_GRADE");
|
||||
int major = rs.getInt("N_MAJOR");
|
||||
String detail = rs.getString("VC_DETAIL");
|
||||
courseInfo = new CourseInfo(id, name, type, credits, grade, major, detail);
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return courseInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAllCourseInfoCount() {
|
||||
int count = 0;
|
||||
String sql = "SELECT COUNT(*) FROM t_course";
|
||||
try {
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
count = rs.getInt(1);
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
return -1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAllCourseInfoCount(String keyword, int type) {
|
||||
int count = 0;
|
||||
String sql = "SELECT COUNT(*) FROM t_course WHERE UPPER(VC_COURSE_NAME) LIKE ? AND ? IN (N_TYPE, 0)";
|
||||
try {
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setString(1, "%"+keyword.toUpperCase()+"%");
|
||||
ps.setInt(2, type);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
count = rs.getInt(1);
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
return -1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addCourseInfo(CourseInfo courseInfo) {
|
||||
int lines;
|
||||
try {
|
||||
String sql = "INSERT INTO t_course (VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL) VALUES(?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setString(1, courseInfo.getName());
|
||||
ps.setInt(2, courseInfo.getType());
|
||||
ps.setFloat(3, courseInfo.getCredit());
|
||||
ps.setInt(4, courseInfo.getGrade());
|
||||
ps.setInt(5, courseInfo.getMajor());
|
||||
ps.setString(6, courseInfo.getDetail());
|
||||
lines = ps.executeUpdate();
|
||||
DBTool.close(ps);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateCourseInfo(CourseInfo courseInfo) {
|
||||
int lines;
|
||||
try {
|
||||
PreparedStatement ps = DBTool.getPreparedStatement("UPDATE t_course SET VC_COURSE_NAME = ?," +
|
||||
" N_TYPE = ?, F_CREDIT = ?, N_GRADE = ?, N_MAJOR = ?, VC_DETAIL = ? WHERE N_COURSE_ID = ?");
|
||||
ps.setString(1, courseInfo.getName());
|
||||
ps.setInt(2, courseInfo.getType());
|
||||
ps.setFloat(3, courseInfo.getCredit());
|
||||
ps.setInt(4, courseInfo.getGrade());
|
||||
ps.setInt(5, courseInfo.getMajor());
|
||||
ps.setString(6, courseInfo.getDetail());
|
||||
ps.setInt(7, courseInfo.getId());
|
||||
lines = ps.executeUpdate();
|
||||
DBTool.close(ps);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteCourseInfo(int id) {
|
||||
int lines;
|
||||
try {
|
||||
String sql = "DELETE FROM t_course WHERE N_COURSE_ID = ?";
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setInt(1, id);
|
||||
lines = ps.executeUpdate();
|
||||
DBTool.close(ps);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package top.awin_x.learn.dao.impl;
|
||||
|
||||
|
||||
|
||||
import top.awin_x.learn.common.DBTool;
|
||||
import top.awin_x.learn.dao.TeacherDB;
|
||||
import top.awin_x.learn.pojo.TeacherInfo;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TeacherDBImpl implements TeacherDB {
|
||||
@Override
|
||||
public ArrayList<TeacherInfo> getAllTeacherInfo() {
|
||||
ArrayList<TeacherInfo> teacherInfos = new ArrayList<>();
|
||||
String sql = "select * from t_teacher";
|
||||
try{
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
TeacherInfo teacherInfo = new TeacherInfo();
|
||||
teacherInfo.setId(rs.getInt("N_TEACHER_ID"));
|
||||
teacherInfo.setName(rs.getString("VC_TEACHER_NAME"));
|
||||
teacherInfo.setSex(rs.getInt("N_SEX"));
|
||||
teacherInfo.setBrith(rs.getString("VC_BIRTH"));
|
||||
teacherInfo.setEduc(rs.getInt("N_EDUC"));
|
||||
teacherInfo.setTitle(rs.getInt("N_TITLE"));
|
||||
teacherInfos.add(teacherInfo);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return teacherInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeacherInfo getTeacherInfoByID(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeacherInfo getTeacherInfoByName(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addTeacherInfo(TeacherInfo teacherInfo) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateTeacherInfo(TeacherInfo teacherInfo) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteTeacherInfo(int id) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package top.awin_x.learn.dao.impl;
|
||||
|
||||
|
||||
import top.awin_x.learn.common.DBTool;
|
||||
import top.awin_x.learn.dao.UserDB;
|
||||
import top.awin_x.learn.pojo.UserInfo;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UserDBImpl implements UserDB {
|
||||
|
||||
@Override
|
||||
public UserInfo getUserByName(String username) {
|
||||
UserInfo u = new UserInfo();
|
||||
ResultSet rs = null;
|
||||
try{
|
||||
String sql = "select * from t_user where VC_LOGIN_NAME = ?";
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setString(1, username);
|
||||
rs = ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
u.setId(rs.getInt("N_USER_ID"));
|
||||
u.setName(rs.getString("VC_LOGIN_NAME"));
|
||||
u.setPass(rs.getString("VC_PASSWORD"));
|
||||
}else{
|
||||
u = null;
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo getUserById(int id) {
|
||||
UserInfo u = new UserInfo();
|
||||
ResultSet rs = null;
|
||||
try{
|
||||
String sql = "select * from t_user where N_USER_ID = ?";
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
u.setId(rs.getInt("N_USER_ID"));
|
||||
u.setName(rs.getString("VC_LOGIN_NAME"));
|
||||
u.setPass(rs.getString("VC_PASSWORD"));
|
||||
}else{
|
||||
u = null;
|
||||
}
|
||||
DBTool.close(ps, rs);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addUser(UserInfo user) {
|
||||
int lines = 0;
|
||||
String sql = "INSERT INTO t_user (VC_LOGIN_NAME, VC_PASSWORD) VALUES (?, ?)";
|
||||
try{
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setString(1, user.getName());
|
||||
ps.setString(2, user.getPass());
|
||||
lines = ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateUser(UserInfo user) {
|
||||
int lines = 0;
|
||||
String sql = "UPDATE t_user SET VC_PASSWORD = ?,VC_LOGIN_NAME = ? WHERE N_USER_ID = ?";
|
||||
try{
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setString(1, user.getPass());
|
||||
ps.setString(2, user.getName());
|
||||
ps.setInt(3, user.getId());
|
||||
lines = ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteUser(int id) {
|
||||
int lines = 0;
|
||||
String sql = "DELETE FROM t_user WHERE N_USER_ID = ?";
|
||||
try{
|
||||
PreparedStatement ps = DBTool.getPreparedStatement(sql);
|
||||
ps.setInt(1, id);
|
||||
lines = ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package top.awin_x.learn.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import top.awin_x.learn.pojo.Course;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Mapper
|
||||
public interface CourseMapper {
|
||||
@Select("SELECT * FROM t_course")
|
||||
public ArrayList<Course> selectAll();
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "N_COURSE_ID")
|
||||
@Insert("INSERT INTO t_course(VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL) VALUES " +
|
||||
"(#{VC_COURSE_NAME}, #{N_TYPE},#{F_CREDIT},#{N_GRADE},#{N_MAJOR},#{VC_DETAIL})")
|
||||
public int insert(Course course);
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Course {
|
||||
private Integer N_COURSE_ID;
|
||||
private String VC_COURSE_NAME;
|
||||
private Integer N_TYPE;
|
||||
private Float F_CREDIT;
|
||||
private Integer N_GRADE;
|
||||
private Integer N_MAJOR;
|
||||
private String VC_DETAIL;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 这是课程信息的封装类
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class CourseInfo {
|
||||
private int id; //id为-1时表示当前内容尚未进入数据库,没有id
|
||||
private String name;
|
||||
private int type;
|
||||
private float credit;
|
||||
private int grade;
|
||||
private int major;
|
||||
private String detail;
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 这是统一的响应格式类,所有的响应都应该是这个类
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Result {
|
||||
private boolean success = true;
|
||||
private String msg = "success";
|
||||
private int count = 0;
|
||||
private Object data = "";
|
||||
|
||||
public static Result success(Object data, String msg) {
|
||||
Result result = success(data);
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result success(Object data) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result success() {
|
||||
return success("");
|
||||
}
|
||||
|
||||
public static Result success(boolean isSuccess) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(isSuccess);
|
||||
if (isSuccess){
|
||||
result.setMsg("success");
|
||||
}else{
|
||||
result.setMsg("fail");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(Object data, String msg) {
|
||||
Result result = error(msg);
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ScoreInfo {
|
||||
private int studentId;
|
||||
private int courseId;
|
||||
private float score;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class StudentInfo {
|
||||
private int id;
|
||||
private String code;
|
||||
private String name;
|
||||
private int sex;
|
||||
private int grade;
|
||||
private String major;
|
||||
private String detail;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TeacherInfo {
|
||||
private int id;
|
||||
private String name;
|
||||
private int sex;
|
||||
private String brith;
|
||||
private int educ;
|
||||
private int title;
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package top.awin_x.learn.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class UserInfo {
|
||||
private int id;
|
||||
private String name;
|
||||
private String pass;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package top.awin_x.learn.service;
|
||||
|
||||
import top.awin_x.learn.pojo.CourseInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface CourseService {
|
||||
public ArrayList<CourseInfo> listCourses(int page, int pageSize, String keyword, int type);
|
||||
public boolean editCourse(CourseInfo course);
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package top.awin_x.learn.service;
|
||||
|
||||
public interface ScoreService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package top.awin_x.learn.service;
|
||||
|
||||
public interface StudentService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package top.awin_x.learn.service;
|
||||
|
||||
public interface TeacherService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package top.awin_x.learn.service;
|
||||
|
||||
public interface UserService {
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package top.awin_x.learn.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.awin_x.learn.dao.impl.CourseDBImpl;
|
||||
import top.awin_x.learn.pojo.CourseInfo;
|
||||
import top.awin_x.learn.service.CourseService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service
|
||||
public class CourseServiceImpl implements CourseService {
|
||||
@Autowired
|
||||
private CourseDBImpl courseDB;
|
||||
|
||||
@Override
|
||||
public ArrayList<CourseInfo> listCourses(int page, int pageSize, String keyword, int type) {
|
||||
return new CourseDBImpl().getCourseInfos(page, pageSize, keyword, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editCourse(CourseInfo course) {
|
||||
CourseDBImpl courseDBImpl = new CourseDBImpl();
|
||||
CourseInfo courseInfo = courseDBImpl.getCourseInfoByID(course.getId());
|
||||
if (courseInfo != null) {
|
||||
courseDBImpl.updateCourseInfo(course);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1 +1,6 @@
|
||||
spring.application.name=learn03-springboot
|
||||
|
||||
spring.datasource.driver-class-name=org.sqlite.JDBC
|
||||
spring.datasource.url=jdbc:sqlite:F:\\Work_Area\\desk\\database\\\u5B66\u4E60\\java\u6D4B\u8BD5\u6570\u636E\u5E93\\db_student.db
|
||||
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
41
learn03-springboot/src/main/resources/database.properties
Normal file
41
learn03-springboot/src/main/resources/database.properties
Normal file
@ -0,0 +1,41 @@
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
#DriverClassName=com.mysql.cj.jdbc.Driver
|
||||
#url=jdbc:mysql://10.19.38.253:3306/chat?useUnicode=true&characterEncoding=utf-8&useSSL=true
|
||||
#username=admin
|
||||
#password=1227496003131313xY
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
driverClassName=org.sqlite.JDBC
|
||||
url=jdbc:sqlite:F:\\Work_Area\\desk\\database\\ѧϰ\\java²âÊÔÊý¾Ý¿â\\db_student.db
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
|
||||
defaultAutoCommit=true
|
||||
|
||||
defaultReadOnly=false
|
||||
|
||||
initialSize=10
|
||||
|
||||
maxActive=20
|
||||
|
||||
maxIdle=20
|
||||
|
||||
minIdle=5
|
||||
|
||||
maxWait=10000
|
||||
|
||||
testOnBorrow=true
|
||||
|
||||
testOnReturn=false
|
||||
|
||||
validationQuery=select 1
|
||||
|
||||
validationQueryTimeout=1
|
||||
|
||||
testWhileIdle=false
|
||||
|
||||
timeBetweenEvictionRunsMillis=1
|
||||
|
||||
numTestsPerEvictionRun=3
|
||||
|
||||
poolPreparedStatements=true
|
||||
|
||||
maxOpenPreparedStatements=3
|
||||
15
learn03-springboot/src/main/resources/static/test.html
Normal file
15
learn03-springboot/src/main/resources/static/test.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>测试</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/hello">
|
||||
<label>
|
||||
<input type="text" name="a">
|
||||
</label>
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,13 +1,38 @@
|
||||
package top.awin_x.learn;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import top.awin_x.learn.mapper.CourseMapper;
|
||||
import top.awin_x.learn.pojo.Course;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SpringBootTest
|
||||
class Learn03SpringbootApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private CourseMapper courseMapper;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
public void testSelectAllCourse(){
|
||||
ArrayList<Course> courses = courseMapper.selectAll();
|
||||
for (Course course : courses) {
|
||||
System.out.println(course);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertCourse(){
|
||||
Course course = new Course();
|
||||
course.setVC_COURSE_NAME("测试数据");
|
||||
course.setF_CREDIT(2.5F);
|
||||
course.setN_GRADE(2024);
|
||||
course.setN_MAJOR(2);
|
||||
course.setVC_DETAIL("test");
|
||||
course.setN_TYPE(2);
|
||||
System.out.println(courseMapper.insert(course));
|
||||
System.out.println(course.getN_COURSE_ID());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,12 +19,12 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
<orderEntry type="library" name="mysql-connector" level="project" />
|
||||
<orderEntry type="library" name="sqlite-jdbc-3.47.0.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Tomcat 10.1.31" level="application_server_libraries" />
|
||||
<orderEntry type="library" name="commons-dbcp2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="commons-logging-1.3.4" level="project" />
|
||||
<orderEntry type="library" name="commons-pool2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@ -16,8 +16,10 @@
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<table id="course-list">
|
||||
</table>
|
||||
|
||||
<div class="course-editor"></div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" exported="" name="Tomcat 10.1.31" level="application_server_libraries" />
|
||||
<orderEntry type="library" exported="" name="lombok" level="project" />
|
||||
<orderEntry type="library" exported="" name="sqlite-jdbc-3.47.0.0" level="project" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@ -19,12 +19,12 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
<orderEntry type="library" name="sqlite-jdbc-3.47.0.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Tomcat 10.1.31" level="application_server_libraries" />
|
||||
<orderEntry type="library" name="commons-dbcp2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="commons-logging-1.3.4" level="project" />
|
||||
<orderEntry type="library" name="commons-pool2-2.9.0" level="project" />
|
||||
<orderEntry type="library" name="mysql-connector" level="project" />
|
||||
<orderEntry type="library" name="lombok" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
33
test05/.gitignore
vendored
Normal file
33
test05/.gitignore
vendored
Normal file
@ -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/
|
||||
91
test05/pom.xml
Normal file
91
test05/pom.xml
Normal file
@ -0,0 +1,91 @@
|
||||
<?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>3.4.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>top.awin-x</groupId>
|
||||
<artifactId>test05</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>test05</name>
|
||||
<description>test05</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter-test</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
<version>1.2.24</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.47.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
13
test05/src/main/java/test05/Test05Application.java
Normal file
13
test05/src/main/java/test05/Test05Application.java
Normal file
@ -0,0 +1,13 @@
|
||||
package test05;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Test05Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Test05Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
55
test05/src/main/java/test05/controller/CourseController.java
Normal file
55
test05/src/main/java/test05/controller/CourseController.java
Normal file
@ -0,0 +1,55 @@
|
||||
package test05.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import test05.pojo.Course;
|
||||
import test05.pojo.Result;
|
||||
import test05.service.CourseService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/courseAction")
|
||||
@CrossOrigin
|
||||
public class CourseController {
|
||||
private final CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
public CourseController(CourseService courseService) {
|
||||
this.courseService = courseService;
|
||||
}
|
||||
|
||||
@RequestMapping("/get")
|
||||
public Result getCourse(String keyword, Integer type, Integer grade, Float credit, Integer page, Integer pageSize) {
|
||||
Course course = new Course();
|
||||
course.setName(keyword==null?"":keyword);
|
||||
course.setDetail(keyword==null?"":keyword);
|
||||
course.setType((type==null?-1:type));
|
||||
course.setGrade((grade==null?-1:grade));
|
||||
course.setCredit(credit==null?-1:credit);
|
||||
if (page == null || page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
if (pageSize == null || pageSize < 0) {
|
||||
pageSize = 10;
|
||||
}
|
||||
return courseService.getCourse(course, page, pageSize);
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
public Result editCourse(Course course) {
|
||||
return courseService.updateCourse(course);
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
public Result addCourse(Course course) {
|
||||
return courseService.addCourse(course);
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
public Result deleteCourse(Integer id) {
|
||||
Course course = new Course();
|
||||
course.setId(id);
|
||||
return courseService.deleteCourse(course);
|
||||
}
|
||||
}
|
||||
13
test05/src/main/java/test05/controller/Hello.java
Normal file
13
test05/src/main/java/test05/controller/Hello.java
Normal file
@ -0,0 +1,13 @@
|
||||
package test05.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class Hello {
|
||||
@RequestMapping("/hello")
|
||||
public String hello() {
|
||||
return "Hello World";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package test05.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/userAction")
|
||||
public class UserController {
|
||||
}
|
||||
39
test05/src/main/java/test05/mapper/CourseMapper.java
Normal file
39
test05/src/main/java/test05/mapper/CourseMapper.java
Normal file
@ -0,0 +1,39 @@
|
||||
package test05.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import test05.pojo.Course;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CourseMapper {
|
||||
/**
|
||||
* 查询课程
|
||||
* @param course 作为查询条件,该对象中的默认值表示不对该项筛选。
|
||||
* @return 查询结果集
|
||||
*/
|
||||
public List<Course> selectCourse(Course course, int page, int pageSize);
|
||||
|
||||
/**
|
||||
* 插入课程
|
||||
* @param course 要插入的课程
|
||||
* @return 影响的行数,大于0时表示插入成功
|
||||
*/
|
||||
public int insertCourse(Course course);
|
||||
|
||||
/**
|
||||
* 更新课程
|
||||
* @param course 更新的课程,id作为更新条件,所有其他字段都将会被更新
|
||||
* @return 影响的行数,行数大于0时表示根性成功
|
||||
*/
|
||||
public int updateCourse(Course course);
|
||||
|
||||
/**
|
||||
* 删除课程
|
||||
* @param course 删除的课程,id作为删除条件
|
||||
* @return 影响的行数,行数大于0时表示删除成功
|
||||
*/
|
||||
public int deleteCourse(Course course);
|
||||
|
||||
public int selectCourseCount(Course course);
|
||||
}
|
||||
14
test05/src/main/java/test05/mapper/ScoreMapper.java
Normal file
14
test05/src/main/java/test05/mapper/ScoreMapper.java
Normal file
@ -0,0 +1,14 @@
|
||||
package test05.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import test05.pojo.Score;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ScoreMapper {
|
||||
public List<Score> selectScore(Score score);
|
||||
public int insertScore(Score score);
|
||||
public int deleteScore(Score score);
|
||||
public int updateScore(Score score);
|
||||
}
|
||||
15
test05/src/main/java/test05/mapper/StudentMapper.java
Normal file
15
test05/src/main/java/test05/mapper/StudentMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package test05.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import test05.pojo.Student;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface StudentMapper {
|
||||
public List<Student> selectStudent(Student student, int page, int pageSize);
|
||||
public int selectStudentCount(Student student);
|
||||
public int insertStudent(Student student);
|
||||
public int updateStudent(Student student);
|
||||
public int deleteStudent(Student student);
|
||||
}
|
||||
14
test05/src/main/java/test05/mapper/TeacherMapper.java
Normal file
14
test05/src/main/java/test05/mapper/TeacherMapper.java
Normal file
@ -0,0 +1,14 @@
|
||||
package test05.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import test05.pojo.Teacher;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface TeacherMapper {
|
||||
List<Teacher> selectTeacher(Teacher teacher);
|
||||
int insertTeacher(Teacher teacher);
|
||||
int updateTeacher(Teacher teacher);
|
||||
int deleteTeacher(Teacher teacher);
|
||||
}
|
||||
15
test05/src/main/java/test05/mapper/UserMapper.java
Normal file
15
test05/src/main/java/test05/mapper/UserMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package test05.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import test05.pojo.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
List<User> selectUser(User user);
|
||||
User selectUserByName(String username);
|
||||
int insertUser(User user);
|
||||
int deleteUser(User user);
|
||||
int updateUser(User user);
|
||||
}
|
||||
34
test05/src/main/java/test05/pojo/Course.java
Normal file
34
test05/src/main/java/test05/pojo/Course.java
Normal file
@ -0,0 +1,34 @@
|
||||
package test05.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Course {
|
||||
@NonNull
|
||||
private Integer id = -1;
|
||||
@NonNull
|
||||
private String name = "";
|
||||
@NonNull
|
||||
private Integer type = -1;
|
||||
@NonNull
|
||||
private Float credit = -1.0F;
|
||||
@NonNull
|
||||
private Integer grade = -1;
|
||||
@NonNull
|
||||
private Integer major = -1;
|
||||
@NonNull
|
||||
private String detail = "";
|
||||
|
||||
public Course(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return id != -1 && type != -1 && !name.isEmpty() && grade != -1 && major != -1 && credit != -1;
|
||||
}
|
||||
}
|
||||
10
test05/src/main/java/test05/pojo/CourseFront.java
Normal file
10
test05/src/main/java/test05/pojo/CourseFront.java
Normal file
@ -0,0 +1,10 @@
|
||||
package test05.pojo;
|
||||
|
||||
public class CourseFront {
|
||||
private int id;
|
||||
private String name;
|
||||
private int type;
|
||||
private float credit;
|
||||
private int grade;
|
||||
private String detail;
|
||||
}
|
||||
66
test05/src/main/java/test05/pojo/Result.java
Normal file
66
test05/src/main/java/test05/pojo/Result.java
Normal file
@ -0,0 +1,66 @@
|
||||
package test05.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Result {
|
||||
private boolean success=true;
|
||||
private int count=-1;
|
||||
@NonNull
|
||||
private String msg="success";
|
||||
@NonNull
|
||||
private Object data="";
|
||||
|
||||
public static Result success(Object data, String msg) {
|
||||
return success(data, msg, -1);
|
||||
}
|
||||
|
||||
public static Result success(Object data, int count){
|
||||
return success(data, "success", count);
|
||||
}
|
||||
|
||||
public static Result success(Object data, String msg, int count) {
|
||||
Result result = success(data);
|
||||
result.setMsg(msg);
|
||||
result.setCount(count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result success(Object data) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result success() {
|
||||
return success("");
|
||||
}
|
||||
|
||||
public static Result success(boolean isSuccess) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(isSuccess);
|
||||
if(!isSuccess){
|
||||
result.setMsg("fail");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg, Object data) {
|
||||
Result result = error(msg);
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
22
test05/src/main/java/test05/pojo/Score.java
Normal file
22
test05/src/main/java/test05/pojo/Score.java
Normal file
@ -0,0 +1,22 @@
|
||||
package test05.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Score {
|
||||
@NonNull
|
||||
private Integer N_STUDENT_ID = -1;
|
||||
@NonNull
|
||||
private Integer N_COURSE_ID = -1;
|
||||
@NonNull
|
||||
private Float F_SCORE = -1.0F;
|
||||
public Score(int stu_id, int course_id){
|
||||
this.N_STUDENT_ID = stu_id;
|
||||
this.N_COURSE_ID = course_id;
|
||||
}
|
||||
}
|
||||
29
test05/src/main/java/test05/pojo/Student.java
Normal file
29
test05/src/main/java/test05/pojo/Student.java
Normal file
@ -0,0 +1,29 @@
|
||||
package test05.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Student {
|
||||
@NonNull
|
||||
private Integer N_STUDENT_ID=-1;
|
||||
@NonNull
|
||||
private String VC_STUDENT_CODE="";
|
||||
@NonNull
|
||||
private String VC_STUDENT_NAME="";
|
||||
@NonNull
|
||||
private Integer N_SEX=-1;
|
||||
@NonNull
|
||||
private Integer N_GRADE=-1;
|
||||
@NonNull
|
||||
private Integer N_MAJOR=-1;
|
||||
@NonNull
|
||||
private String VC_DETAIL="";
|
||||
public Student(int id){
|
||||
N_STUDENT_ID=id;
|
||||
}
|
||||
}
|
||||
27
test05/src/main/java/test05/pojo/Teacher.java
Normal file
27
test05/src/main/java/test05/pojo/Teacher.java
Normal file
@ -0,0 +1,27 @@
|
||||
package test05.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Teacher {
|
||||
@NonNull
|
||||
Integer N_TEACHER_ID=-1;
|
||||
@NonNull
|
||||
String VC_TEACHER_NAME="";
|
||||
@NonNull
|
||||
Integer N_SEX=-1;
|
||||
@NonNull
|
||||
String VC_BIRTH="";
|
||||
@NonNull
|
||||
Integer N_EDUC=-1;
|
||||
@NonNull
|
||||
Integer N_TITLE=-1;
|
||||
public Teacher(int id){
|
||||
N_TEACHER_ID = id;
|
||||
}
|
||||
}
|
||||
21
test05/src/main/java/test05/pojo/User.java
Normal file
21
test05/src/main/java/test05/pojo/User.java
Normal file
@ -0,0 +1,21 @@
|
||||
package test05.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class User {
|
||||
@NonNull
|
||||
private Integer N_USER_ID=-1;
|
||||
@NonNull
|
||||
private String VC_LOGIN_NAME ="";
|
||||
@NonNull
|
||||
private String VC_PASSWORD="";
|
||||
public User(int id){
|
||||
N_USER_ID = id;
|
||||
}
|
||||
}
|
||||
11
test05/src/main/java/test05/service/CourseService.java
Normal file
11
test05/src/main/java/test05/service/CourseService.java
Normal file
@ -0,0 +1,11 @@
|
||||
package test05.service;
|
||||
|
||||
import test05.pojo.Course;
|
||||
import test05.pojo.Result;
|
||||
|
||||
public interface CourseService {
|
||||
public Result addCourse(Course course);
|
||||
public Result deleteCourse(Course course);
|
||||
public Result updateCourse(Course course);
|
||||
Result getCourse(Course course, int page, int pageSize);
|
||||
}
|
||||
4
test05/src/main/java/test05/service/UserService.java
Normal file
4
test05/src/main/java/test05/service/UserService.java
Normal file
@ -0,0 +1,4 @@
|
||||
package test05.service;
|
||||
|
||||
public interface UserService {
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
package test05.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import test05.mapper.CourseMapper;
|
||||
import test05.pojo.Course;
|
||||
import test05.pojo.Result;
|
||||
import test05.service.CourseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CourseServiceImpl implements CourseService {
|
||||
|
||||
|
||||
private final CourseMapper courseMapper;
|
||||
|
||||
private String courseCheck(Course course) {
|
||||
if (course.getId()!=-1){
|
||||
return "do not set N_COURSE_ID";
|
||||
}
|
||||
if (course.getName().length()<4||course.getName().length()>25){
|
||||
return "name too long";
|
||||
}
|
||||
if (course.getGrade()>3000||course.getGrade()<2000){
|
||||
return "grade invalid";
|
||||
}
|
||||
if (course.getMajor()<1||course.getMajor()>6){
|
||||
return "major invalid";
|
||||
}
|
||||
if (course.getType()<1||course.getType()>6){
|
||||
return "type invalid";
|
||||
}
|
||||
if (course.getDetail().length()>200){
|
||||
return "detail too long";
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public CourseServiceImpl(CourseMapper courseMapper) {
|
||||
this.courseMapper = courseMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result addCourse(Course course) {
|
||||
String check = courseCheck(course);
|
||||
if (!check.equals("ok")){
|
||||
return Result.error(check);
|
||||
}
|
||||
if (courseMapper.insertCourse(course) > 0 && course.getId()!=-1){
|
||||
return Result.success(course);
|
||||
}else{
|
||||
return Result.error("add course error");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deleteCourse(Course course) {
|
||||
if (courseMapper.deleteCourse(course)>=1){
|
||||
return Result.success(course);
|
||||
}else{
|
||||
return Result.error("delete course error");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateCourse(Course course) {
|
||||
String check = courseCheck(course);
|
||||
if (!course.isComplete()&&check.equals("ok")){
|
||||
return Result.error("please complete the course:"+check);
|
||||
}else if(courseMapper.updateCourse(course)>=1){
|
||||
return Result.success(course);
|
||||
}else{
|
||||
return Result.error("update course error");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getCourse(Course course, int page, int pageSize) {
|
||||
List<Course> courseList = courseMapper.selectCourse(course, page, pageSize);
|
||||
int total = courseMapper.selectCourseCount(course);
|
||||
return Result.success(courseList, total);
|
||||
}
|
||||
}
|
||||
15
test05/src/main/resources/application.properties
Normal file
15
test05/src/main/resources/application.properties
Normal file
@ -0,0 +1,15 @@
|
||||
spring.application.name=test05
|
||||
|
||||
#\u4F7F\u7528\u672C\u5730\u6D4B\u8BD5\u6570\u636E\u5E93
|
||||
spring.datasource.driver-class-name=org.sqlite.JDBC
|
||||
spring.datasource.url=jdbc:sqlite:F:\\Work_Area\\desk\\database\\\u5B66\u4E60\\java\u6D4B\u8BD5\u6570\u636E\u5E93\\db_student.db
|
||||
|
||||
##\u4F7F\u7528mysql\u6570\u636E\u5E93
|
||||
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.url=jdbc:mysql://localhost:3306/db_student.db
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=123456
|
||||
|
||||
spring.datasource.druid.validation-query=SELECT 1
|
||||
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
50
test05/src/main/resources/test05/mapper/CourseMapper.xml
Normal file
50
test05/src/main/resources/test05/mapper/CourseMapper.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?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="test05.mapper.CourseMapper">
|
||||
<select id="selectCourse" resultType="test05.pojo.Course">
|
||||
SELECT N_COURSE_ID AS id,
|
||||
VC_COURSE_NAME AS name,
|
||||
N_TYPE AS type,
|
||||
F_CREDIT AS credit,
|
||||
N_MAJOR AS major,
|
||||
VC_DETAIL AS detail
|
||||
FROM t_course
|
||||
WHERE #{course.id} in (N_COURSE_ID, -1)
|
||||
AND #{course.type} in (N_TYPE, -1)
|
||||
AND #{course.credit} in (F_CREDIT, -1)
|
||||
AND #{course.major} in (N_MAJOR, -1)
|
||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{course.name}), '%')
|
||||
ORDER BY N_COURSE_ID
|
||||
LIMIT #{page}*#{pageSize},#{pageSize}
|
||||
</select>
|
||||
<select id="selectCourseCount" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM t_course
|
||||
WHERE #{N_COURSE_ID} in (N_COURSE_ID, -1)
|
||||
AND #{N_TYPE} in (N_TYPE, -1)
|
||||
AND #{F_CREDIT} in (F_CREDIT, -1)
|
||||
AND #{N_MAJOR} in (N_MAJOR, -1)
|
||||
AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{VC_COURSE_NAME}), '%')
|
||||
</select>
|
||||
<insert id="insertCourse" keyProperty="N_COURSE_ID" useGeneratedKeys="true">
|
||||
INSERT INTO t_course
|
||||
(VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL)
|
||||
VALUES (#{name}, #{type}, #{credit}, #{grade}, #{major}, #{detail})
|
||||
</insert>
|
||||
<update id="updateCourse">
|
||||
UPDATE t_course
|
||||
SET VC_COURSE_NAME=#{name},
|
||||
N_TYPE=#{type},
|
||||
F_CREDIT=#{credit},
|
||||
N_GRADE=#{grade},
|
||||
N_MAJOR=#{major},
|
||||
VC_DETAIL=#{detail}
|
||||
WHERE N_COURSE_ID=#{id};
|
||||
</update>
|
||||
<delete id="deleteCourse">
|
||||
DELETE FROM t_course
|
||||
WHERE N_COURSE_ID=#{id};
|
||||
</delete>
|
||||
</mapper>
|
||||
30
test05/src/main/resources/test05/mapper/ScoreMapper.xml
Normal file
30
test05/src/main/resources/test05/mapper/ScoreMapper.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?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="test05.mapper.ScoreMapper">
|
||||
<select id="selectScore" resultType="test05.pojo.Score">
|
||||
SELECT *
|
||||
FROM t_score
|
||||
WHERE #{N_STUDENT_ID} in (N_STUDENT_ID, -1)
|
||||
AND #{N_COURSE_ID} in (N_COURSE_ID, -1)
|
||||
AND #{F_SCORE} in (F_SCORE, -1);
|
||||
</select>
|
||||
<update id="updateScore">
|
||||
UPDATE t_score
|
||||
SET F_SCORE = #{F_SCORE}
|
||||
WHERE N_COURSE_ID = #{N_COURSE_ID}
|
||||
AND N_STUDENT_ID = #{N_STUDENT_ID}
|
||||
</update>
|
||||
<delete id="deleteScore">
|
||||
DELETE
|
||||
FROM t_score
|
||||
WHERE N_STUDENT_ID = #{N_STUDENT_ID}
|
||||
AND N_COURSE_ID = #{N_COURSE_ID}
|
||||
</delete>
|
||||
<insert id="insertScore">
|
||||
INSERT INTO t_score
|
||||
(N_STUDENT_ID, N_COURSE_ID, F_SCORE)
|
||||
VALUES (#{N_STUDENT_ID}, #{N_COURSE_ID}, #{F_SCORE});
|
||||
</insert>
|
||||
</mapper>
|
||||
40
test05/src/main/resources/test05/mapper/StudentMapper.xml
Normal file
40
test05/src/main/resources/test05/mapper/StudentMapper.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?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="test05.mapper.StudentMapper">
|
||||
<select id="selectStudent" resultType="test05.pojo.Student">
|
||||
SELECT *
|
||||
FROM t_student
|
||||
WHERE #{student.N_STUDENT_ID} in (N_STUDENT_ID, -1)
|
||||
AND VC_STUDENT_CODE LIKE CONCAT('%', #{student.VC_STUDENT_CODE}, '%')
|
||||
AND VC_STUDENT_NAME LIKE CONCAT('%', #{student.VC_STUDENT_NAME}, '%')
|
||||
AND #{student.N_SEX} in (N_SEX, -1)
|
||||
AND #{student.N_GRADE} in (N_GRADE, -1)
|
||||
AND #{student.N_MAJOR} in (N_MAJOR, -1)
|
||||
AND VC_DETAIL LIKE CONCAT('%', #{student.VC_DETAIL}, '%')
|
||||
ORDER BY N_STUDENT_ID
|
||||
LIMIT #{page}*#{pageSize},#{pageSize}
|
||||
</select>
|
||||
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="N_STUDENT_ID">
|
||||
INSERT INTO t_student
|
||||
(VC_STUDENT_CODE, VC_STUDENT_NAME, N_SEX, N_GRADE, N_MAJOR, VC_DETAIL)
|
||||
VALUES
|
||||
(#{VC_STUDENT_CODE},#{VC_STUDENT_NAME},#{N_SEX},#{N_GRADE},#{N_MAJOR},#{VC_DETAIL});
|
||||
</insert>
|
||||
<delete id="deleteStudent">
|
||||
DELETE
|
||||
FROM t_student
|
||||
WHERE N_STUDENT_ID = #{N_STUDENT_ID};
|
||||
</delete>
|
||||
<update id="updateStudent">
|
||||
UPDATE t_student
|
||||
SET VC_STUDENT_CODE=#{VC_STUDENT_CODE},
|
||||
VC_STUDENT_NAME=#{VC_STUDENT_NAME},
|
||||
N_SEX=#{N_SEX},
|
||||
N_GRADE=#{N_GRADE},
|
||||
N_MAJOR=#{N_MAJOR},
|
||||
VC_DETAIL=#{VC_DETAIL}
|
||||
WHERE N_STUDENT_ID=#{N_STUDENT_ID};
|
||||
</update>
|
||||
</mapper>
|
||||
34
test05/src/main/resources/test05/mapper/TeacherMapper.xml
Normal file
34
test05/src/main/resources/test05/mapper/TeacherMapper.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?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="test05.mapper.TeacherMapper">
|
||||
<select id="selectTeacher" resultType="test05.pojo.Teacher">
|
||||
SELECT *
|
||||
FROM t_teacher
|
||||
WHERE #{N_TEACHER_ID} IN (N_TEACHER_ID, -1)
|
||||
AND VC_TEACHER_NAME LIKE CONCAT('%', #{VC_TEACHER_NAME}, '%')
|
||||
AND #{N_SEX} IN (N_SEX, -1)
|
||||
AND VC_BIRTH LIKE CONCAT('%', #{VC_BIRTH}, '%')
|
||||
AND #{N_EDUC} IN (N_EDUC, -1)
|
||||
AND #{N_TITLE} IN (N_TITLE, -1)
|
||||
</select>
|
||||
<insert id="insertTeacher" keyProperty="N_TEACHER_ID" useGeneratedKeys="true">
|
||||
INSERT INTO t_teacher
|
||||
(VC_TEACHER_NAME, N_SEX, VC_BIRTH, N_EDUC, N_TITLE)
|
||||
VALUES (#{VC_TEACHER_NAME},#{N_SEX},#{VC_BIRTH},#{N_EDUC},#{N_TITLE})
|
||||
</insert>
|
||||
<update id="updateTeacher">
|
||||
UPDATE t_teacher
|
||||
SET VC_TEACHER_NAME=#{VC_TEACHER_NAME},
|
||||
N_SEX=#{N_SEX},
|
||||
VC_BIRTH=#{VC_BIRTH},
|
||||
N_EDUC=#{N_EDUC},
|
||||
N_TITLE=#{N_TITLE}
|
||||
WHERE N_TEACHER_ID = #{N_TEACHER_ID}
|
||||
</update>
|
||||
<delete id="deleteTeacher">
|
||||
DELETE FROM t_teacher
|
||||
WHERE N_TEACHER_ID = #{N_TEACHER_ID}
|
||||
</delete>
|
||||
</mapper>
|
||||
36
test05/src/main/resources/test05/mapper/UserMapper.xml
Normal file
36
test05/src/main/resources/test05/mapper/UserMapper.xml
Normal file
@ -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="test05.mapper.UserMapper">
|
||||
<select id="selectUser" resultType="test05.pojo.User">
|
||||
SELECT *
|
||||
FROM t_user
|
||||
WHERE
|
||||
#{N_USER_ID} IN (N_USER_ID, -1)
|
||||
AND VC_LOGIN_NAME LIKE CONCAT('%',#{VC_LOGIN_NAME},'%')
|
||||
AND VC_PASSWORD LIKE CONCAT('%',#{VC_PASSWORD},'%')
|
||||
</select>
|
||||
<insert id="insertUser" useGeneratedKeys="true" keyProperty="N_USER_ID">
|
||||
INSERT INTO t_user
|
||||
(VC_LOGIN_NAME, VC_PASSWORD)
|
||||
VALUES
|
||||
(#{VC_LOGIN_NAME}, #{VC_PASSWORD})
|
||||
</insert>
|
||||
<update id="updateUser">
|
||||
UPDATE t_user
|
||||
SET VC_PASSWORD=#{VC_PASSWORD},
|
||||
VC_LOGIN_NAME=#{VC_LOGIN_NAME}
|
||||
WHERE N_USER_ID = #{N_USER_ID};
|
||||
</update>
|
||||
<delete id="deleteUser">
|
||||
DELETE
|
||||
FROM t_user
|
||||
WHERE N_USER_ID = #{N_USER_ID}
|
||||
</delete>
|
||||
<select id="selectUserByName" resultType="test05.pojo.User">
|
||||
SELECT *
|
||||
FROM t_user
|
||||
WHERE VC_LOGIN_NAME = #{username};
|
||||
</select>
|
||||
</mapper>
|
||||
222
test05/src/test/java/test05/Test05ApplicationTests.java
Normal file
222
test05/src/test/java/test05/Test05ApplicationTests.java
Normal file
@ -0,0 +1,222 @@
|
||||
package test05;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.TestAbortedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import test05.mapper.*;
|
||||
import test05.pojo.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class Test05ApplicationTests {
|
||||
@Autowired
|
||||
CourseMapper courseMapper;
|
||||
@Autowired
|
||||
ScoreMapper scoreMapper;
|
||||
@Autowired
|
||||
StudentMapper studentMapper;
|
||||
@Autowired
|
||||
TeacherMapper teacherMapper;
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
@Test
|
||||
public void courseMapperTest(){
|
||||
|
||||
Course course = new Course();
|
||||
course.setName("测试课程");
|
||||
course.setCredit(1.0F);
|
||||
course.setMajor(2);
|
||||
course.setType(2);
|
||||
course.setGrade(2022);
|
||||
List<Course> selectCourse = courseMapper.selectCourse(course, 0, 10);
|
||||
if (!selectCourse.isEmpty()) {
|
||||
courseMapper.deleteCourse(course);
|
||||
}
|
||||
courseMapper.insertCourse(course);
|
||||
if (course.getId()==-1){
|
||||
System.out.println("课程添加出阿信错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
selectCourse = courseMapper.selectCourse(new Course(), 0, 10);
|
||||
if (!selectCourse.isEmpty()) {
|
||||
System.out.println("课程查询出现错误");
|
||||
}
|
||||
course.setDetail("hello");
|
||||
courseMapper.updateCourse(course);
|
||||
selectCourse = courseMapper.selectCourse(course, 0, 10);
|
||||
if (selectCourse.isEmpty()) {
|
||||
System.out.println("课程修改出现错误");
|
||||
}
|
||||
courseMapper.deleteCourse(course);
|
||||
selectCourse = courseMapper.selectCourse(course, 0, 10);
|
||||
if (!selectCourse.isEmpty()) {
|
||||
System.out.println("课程删除出现错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreSelectTest(){
|
||||
Score score = new Score();
|
||||
List<Score> result = scoreMapper.selectScore(score);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreInsertTest(){
|
||||
Score score = new Score();
|
||||
score.setN_COURSE_ID(22);
|
||||
score.setN_STUDENT_ID(22);
|
||||
score.setF_SCORE(1.0F);
|
||||
scoreMapper.insertScore(score);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreUpdateTest(){
|
||||
Score score = new Score();
|
||||
score.setN_COURSE_ID(22);
|
||||
score.setN_STUDENT_ID(22);
|
||||
score.setF_SCORE(2.0F);
|
||||
scoreMapper.updateScore(score);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scoreDeleteTest(){
|
||||
Score score = new Score();
|
||||
score.setN_COURSE_ID(22);
|
||||
score.setN_STUDENT_ID(22);
|
||||
scoreMapper.deleteScore(score);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studentMapperTest(){
|
||||
Student student = new Student();
|
||||
student.setVC_STUDENT_CODE("2020202");
|
||||
student.setN_MAJOR(2);
|
||||
student.setVC_STUDENT_NAME("测试学生");
|
||||
student.setN_SEX(1);
|
||||
student.setN_GRADE(2022);
|
||||
//添加学生
|
||||
studentMapper.insertStudent(student);
|
||||
System.out.println(student.getN_STUDENT_ID());
|
||||
if (student.getN_STUDENT_ID()==-1) {
|
||||
System.out.println("学生信息添加出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
//查询学生
|
||||
List<Student> selectResult = studentMapper.selectStudent(new Student(), 0, 10);
|
||||
if (selectResult.isEmpty()) {
|
||||
System.out.println("学生信息查询出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
System.out.println(selectResult);
|
||||
//修改学生
|
||||
student.setN_GRADE(2023);
|
||||
studentMapper.updateStudent(student);
|
||||
selectResult = studentMapper.selectStudent(student, 0, 10);
|
||||
if (selectResult.size() != 1) {
|
||||
System.out.println("学生信息查询出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
if (selectResult.getFirst().getN_GRADE() != 2023) {
|
||||
System.out.println("学生信息修改出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
//删除学生
|
||||
studentMapper.deleteStudent(student);
|
||||
selectResult = studentMapper.selectStudent(student, 0, 10);
|
||||
if (!selectResult.isEmpty()) {
|
||||
System.out.println("学生信息删除出现错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void teacherMapperTest(){
|
||||
Teacher teacher = new Teacher();
|
||||
teacher.setVC_TEACHER_NAME("测试老师");
|
||||
teacher.setN_EDUC(2);
|
||||
teacher.setN_TITLE(2);
|
||||
teacher.setVC_BIRTH("20230810");
|
||||
teacher.setN_SEX(1);
|
||||
//添加老师
|
||||
teacherMapper.insertTeacher(teacher);
|
||||
System.out.println(teacher.getN_TEACHER_ID());
|
||||
if (teacher.getN_TEACHER_ID() == -1) {
|
||||
System.out.println("老师信息添加错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
//查询老师
|
||||
List<Teacher> selectResult = teacherMapper.selectTeacher(new Teacher());
|
||||
if (selectResult.isEmpty()){
|
||||
System.out.println("查询老师信息出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
System.out.println(selectResult);
|
||||
teacher.setN_SEX(0);
|
||||
//修改老师
|
||||
teacherMapper.updateTeacher(teacher);
|
||||
selectResult = teacherMapper.selectTeacher(teacher);
|
||||
if (selectResult.size() != 1){
|
||||
System.out.println("查询老师信息出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
if (selectResult.getFirst().getN_SEX()!=0) {
|
||||
System.out.println("老师信息修改出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
//删除老师
|
||||
teacherMapper.deleteTeacher(teacher);
|
||||
selectResult = teacherMapper.selectTeacher(teacher);
|
||||
if (!selectResult.isEmpty()){
|
||||
System.out.println("老师信息删除出现错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userMapperTest(){
|
||||
User user;
|
||||
user = userMapper.selectUserByName("测试用户");
|
||||
if (user == null) {
|
||||
user = new User();
|
||||
}else{
|
||||
userMapper.deleteUser(user);
|
||||
}
|
||||
user.setVC_PASSWORD("123456");
|
||||
user.setVC_LOGIN_NAME("测试用户");
|
||||
userMapper.insertUser(user);
|
||||
if (user.getN_USER_ID()==-1) {
|
||||
System.out.println("添加用户出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
List<User> selectResult = userMapper.selectUser(new User());
|
||||
if (selectResult.isEmpty()){
|
||||
System.out.println("查询用户出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
System.out.println(selectResult);
|
||||
user.setVC_PASSWORD("654321");
|
||||
userMapper.updateUser(user);
|
||||
selectResult = userMapper.selectUser(user);
|
||||
if (selectResult.size()!=1){
|
||||
System.out.println("查询用户失败");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
if (!selectResult.getFirst().getVC_PASSWORD().equals(user.getVC_PASSWORD())) {
|
||||
System.out.println("修改用户出现错误");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
User selectUser = userMapper.selectUserByName(user.getVC_LOGIN_NAME());
|
||||
if (selectUser==null){
|
||||
System.out.println("用户定位失败");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
userMapper.deleteUser(user);
|
||||
selectResult = userMapper.selectUser(user);
|
||||
if (!selectResult.isEmpty()){
|
||||
System.out.println("删除用户失败");
|
||||
throw new TestAbortedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user