31 changed files with 960 additions and 61 deletions
@ -1,8 +1,8 @@ |
|||
<component name="ArtifactManager"> |
|||
<artifact name="unnamed"> |
|||
<output-path>$PROJECT_DIR$/out/artifacts/unnamed</output-path> |
|||
<artifact build-on-make="true" name="unnamed"> |
|||
<output-path>$PROJECT_DIR$/src/main/webapp/WEB-INF/classes</output-path> |
|||
<root id="root"> |
|||
<element id="dir-copy" path="$PROJECT_DIR$/src/main/webapp" /> |
|||
<element id="module-output" name="Web" /> |
|||
</root> |
|||
</artifact> |
|||
</component> |
|||
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="CompilerConfiguration"> |
|||
<annotationProcessing> |
|||
<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="Web-project" /> |
|||
</profile> |
|||
</annotationProcessing> |
|||
<bytecodeTargetLevel target="17" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="AgentMigrationStateService"> |
|||
<option name="migrationStatus" value="COMPLETED" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="AskMigrationStateService"> |
|||
<option name="migrationStatus" value="COMPLETED" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="Ask2AgentMigrationStateService"> |
|||
<option name="migrationStatus" value="COMPLETED" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="EditMigrationStateService"> |
|||
<option name="migrationStatus" value="COMPLETED" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,25 @@ |
|||
<?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="Maven Central repository" /> |
|||
<option name="url" value="https://repo1.maven.org/maven2" /> |
|||
</remote-repository> |
|||
<remote-repository> |
|||
<option name="id" value="jboss.community" /> |
|||
<option name="name" value="JBoss Community repository" /> |
|||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> |
|||
</remote-repository> |
|||
<remote-repository> |
|||
<option name="id" value="central" /> |
|||
<option name="name" value="Central Repository" /> |
|||
<option name="url" value="http://maven.aliyun.com/nexus/content/repositories/central" /> |
|||
</remote-repository> |
|||
</component> |
|||
</project> |
|||
@ -1,9 +0,0 @@ |
|||
<component name="libraryTable"> |
|||
<library name="javax.servlet-api-4.0.1-javadoc"> |
|||
<CLASSES /> |
|||
<JAVADOC> |
|||
<root url="jar://$PROJECT_DIR$/../../Servlet/javax.servlet-api-4.0.1-javadoc.jar!/" /> |
|||
</JAVADOC> |
|||
<SOURCES /> |
|||
</library> |
|||
</component> |
|||
@ -0,0 +1,9 @@ |
|||
<component name="libraryTable"> |
|||
<library name="mysql-connector-j-9.4.0"> |
|||
<CLASSES> |
|||
<root url="jar://$PROJECT_DIR$/src/main/webapp/lib/mysql-connector-j-9.4.0.jar!/" /> |
|||
</CLASSES> |
|||
<JAVADOC /> |
|||
<SOURCES /> |
|||
</library> |
|||
</component> |
|||
@ -0,0 +1,9 @@ |
|||
<component name="libraryTable"> |
|||
<library name="servlet-api"> |
|||
<CLASSES> |
|||
<root url="jar://$PROJECT_DIR$/src/main/webapp/lib/servlet-api.jar!/" /> |
|||
</CLASSES> |
|||
<JAVADOC /> |
|||
<SOURCES /> |
|||
</library> |
|||
</component> |
|||
@ -1,6 +1,14 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-24" project-jdk-type="JavaSDK"> |
|||
<output url="file://$PROJECT_DIR$/out" /> |
|||
<component name="ExternalStorageConfigurationManager" enabled="true" /> |
|||
<component name="MavenProjectsManager"> |
|||
<option name="originalFiles"> |
|||
<list> |
|||
<option value="$PROJECT_DIR$/pom.xml" /> |
|||
</list> |
|||
</option> |
|||
</component> |
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="graalvm-jdk-17" project-jdk-type="JavaSDK"> |
|||
<output url="file://$PROJECT_DIR$/src/main/webapp/WEB-INF/classes" /> |
|||
</component> |
|||
</project> |
|||
@ -1,8 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ProjectModuleManager"> |
|||
<modules> |
|||
<module fileurl="file://$PROJECT_DIR$/Web.iml" filepath="$PROJECT_DIR$/Web.iml" /> |
|||
</modules> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,124 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="Palette2"> |
|||
<group name="Swing"> |
|||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> |
|||
</item> |
|||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> |
|||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> |
|||
<initial-values> |
|||
<property name="text" value="Button" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="RadioButton" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="CheckBox" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="Label" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
|||
<preferred-size width="200" height="200" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
|||
<preferred-size width="200" height="200" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> |
|||
<preferred-size width="-1" height="20" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> |
|||
</item> |
|||
</group> |
|||
</component> |
|||
</project> |
|||
@ -1,4 +1,4 @@ |
|||
FROM tomcat:9-jdk24-openjdk |
|||
FROM tomcat:9-jdk8-openjdk |
|||
|
|||
# 第二步:将本地webapp目录复制到容器内的Tomcat默认应用目录 |
|||
# 注意:`src/main/webapp` 是你项目中Web资源的路径(需与实际一致) |
|||
@ -1,18 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="JAVA_MODULE" version="4"> |
|||
<component name="NewModuleRootManager"> |
|||
<output url="file://$MODULE_DIR$/out/production/Web" /> |
|||
<output-test url="file://$MODULE_DIR$/out/test/Web" /> |
|||
<exclude-output /> |
|||
<content url="file://$MODULE_DIR$"> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> |
|||
<component name="AdditionalModuleElements"> |
|||
<content url="file://$MODULE_DIR$" dumb="true"> |
|||
<excludeFolder url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/classes" /> |
|||
</content> |
|||
<orderEntry type="inheritedJdk" /> |
|||
<orderEntry type="sourceFolder" forTests="false" /> |
|||
<orderEntry type="library" exported="" name="javax.servlet-api-4.0.1-javadoc" level="project" /> |
|||
</component> |
|||
</module> |
|||
@ -0,0 +1,123 @@ |
|||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<!-- 项目基本信息(匹配项目名Web) --> |
|||
<groupId>com.Web</groupId> |
|||
<artifactId>Web-project</artifactId> <!-- 项目标识 --> |
|||
<version>1.0-SNAPSHOT</version> |
|||
<packaging>war</packaging> <!-- Web项目打包为war --> |
|||
<name>Web</name> <!-- 项目名 --> |
|||
<description>基于Spring的Web项目(Java 24.0.2)</description> |
|||
|
|||
<!-- 依赖管理 --> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.google.protobuf</groupId> |
|||
<artifactId>protobuf-java</artifactId> |
|||
<version>4.28.2</version> |
|||
</dependency> |
|||
<!-- 1. Spring核心模块 --> |
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-context</artifactId> |
|||
<version>6.1.0</version> <!-- 稳定版本,兼容Java 17+ --> |
|||
</dependency> |
|||
<!-- Spring WebMVC(Web开发核心) --> |
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-webmvc</artifactId> |
|||
<version>6.1.0</version> |
|||
</dependency> |
|||
<!-- Spring JDBC(数据库操作) --> |
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-jdbc</artifactId> |
|||
<version>6.1.0</version> <!-- 替换为你项目中使用的 Spring 版本 --> |
|||
</dependency> |
|||
<!-- 视图解析器:Thymeleaf --> |
|||
<dependency> |
|||
<groupId>org.thymeleaf</groupId> |
|||
<artifactId>thymeleaf</artifactId> |
|||
<version>3.1.3.RELEASE</version> <!-- 版本可根据需求调整 --> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.thymeleaf</groupId> |
|||
<artifactId>thymeleaf-spring6</artifactId> |
|||
<version>3.1.3.RELEASE</version> <!-- 需与核心版本一致 --> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.fasterxml.jackson.core</groupId> |
|||
<artifactId>jackson-databind</artifactId> |
|||
<version>2.15.2</version> <!-- 版本可根据需求调整 --> |
|||
</dependency> |
|||
<!-- 2. Controller API(容器提供,避免打包冲突) --> |
|||
<dependency> |
|||
<groupId>jakarta.servlet</groupId> |
|||
<artifactId>jakarta.servlet-api</artifactId> |
|||
<version>6.1.0</version> <!-- 适配Java EE 10,兼容高版本Java --> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<!-- 3. MySQL驱动 --> |
|||
<dependency> |
|||
<groupId>com.mysql</groupId> |
|||
<artifactId>mysql-connector-j</artifactId> |
|||
<version>8.4.0</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.zaxxer</groupId> |
|||
<artifactId>HikariCP</artifactId> |
|||
<version>5.0.1</version> <!-- 版本号请用最新稳定版 --> |
|||
</dependency> |
|||
|
|||
<!-- 4. 日志依赖(Spring必需) --> |
|||
<dependency> |
|||
<groupId>commons-logging</groupId> |
|||
<artifactId>commons-logging</artifactId> |
|||
<version>1.2</version> |
|||
</dependency> |
|||
<!-- SLF4J API + Logback 实现,供项目使用 org.slf4j Logger --> |
|||
<dependency> |
|||
<groupId>org.slf4j</groupId> |
|||
<artifactId>slf4j-api</artifactId> |
|||
<version>2.0.9</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>ch.qos.logback</groupId> |
|||
<artifactId>logback-classic</artifactId> |
|||
<version>1.4.11</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<!-- 构建配置(将编译目标设置为 Java 17,以避免 Spring ASM 无法解析 Java 24 class 文件) --> |
|||
<build> |
|||
<finalName>Web</finalName> <!-- 打包后的war包名 --> |
|||
<plugins> |
|||
<!-- 编译插件:使用 release 17,保证生成 class 文件兼容性 --> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-compiler-plugin</artifactId> |
|||
<version>3.13.0</version> |
|||
<configuration> |
|||
<release>17</release> |
|||
<encoding>UTF-8</encoding> |
|||
</configuration> |
|||
</plugin> |
|||
|
|||
<!-- Web项目打包插件 --> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-war-plugin</artifactId> |
|||
<version>3.4.0</version> |
|||
<configuration> |
|||
<failOnMissingWebXml>false</failOnMissingWebXml> <!-- 允许无web.xml --> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
</project> |
|||
@ -0,0 +1,35 @@ |
|||
package houduan.Config; |
|||
|
|||
import com.zaxxer.hikari.HikariDataSource; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
@Configuration |
|||
public class DataSourceConfig { |
|||
|
|||
@Bean(destroyMethod = "close") |
|||
public DataSource dataSource() { |
|||
HikariDataSource dataSource = new HikariDataSource(); |
|||
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); |
|||
// 数据库连接信息
|
|||
dataSource.setJdbcUrl("jdbc:mysql://172.23.72.17:3306/DBMAIN?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC"); |
|||
dataSource.setUsername("Me"); |
|||
dataSource.setPassword("@Leiwei88"); |
|||
|
|||
// 连接池参数
|
|||
dataSource.setMaximumPoolSize(10); |
|||
dataSource.setMinimumIdle(5); |
|||
dataSource.setConnectionTimeout(30000); |
|||
dataSource.setIdleTimeout(600000); |
|||
|
|||
return dataSource; |
|||
} |
|||
|
|||
@Bean |
|||
public JdbcTemplate jdbcTemplate(DataSource dataSource) { |
|||
return new JdbcTemplate(dataSource); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package houduan.Controller; |
|||
|
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.ui.Model; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
|
|||
@Controller |
|||
public class PrieviousController { |
|||
|
|||
// 访问路径:http://localhost:8080/test
|
|||
@GetMapping("/test") |
|||
public String test(Model model) { |
|||
// 向模型中添加数据(key为"message",value为"Hello Thymeleaf!")
|
|||
model.addAttribute("message", "Hello Thymeleaf!"); |
|||
// 返回视图名:对应 /WEB-INF/templates/index.html
|
|||
return "index"; |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
package houduan.Controller; |
|||
|
|||
|
|||
import houduan.Object.User; |
|||
import houduan.Service.UserService; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
import org.springframework.web.bind.annotation.RequestMethod; // 修正导入
|
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import java.sql.SQLException; |
|||
|
|||
@Controller |
|||
public class RegisterController{ |
|||
private static final Logger logger = LoggerFactory.getLogger(RegisterController.class); |
|||
|
|||
// 使用构造器注入,避免 IDE 报警并更利于测试
|
|||
private final UserService userService; |
|||
|
|||
@Autowired |
|||
public RegisterController(UserService userService) { |
|||
this.userService = userService; |
|||
} |
|||
@RequestMapping(value = "/RegisterServlet", method = RequestMethod.POST) // 修正引用
|
|||
@ResponseBody //响应体
|
|||
public String register(@RequestParam(value = "username", required = false) String username, |
|||
@RequestParam(value = "realName", required = false) String realName, |
|||
@RequestParam(value="password", required = false) String password, // 密码参数接收
|
|||
@RequestParam(value = "age", required = false) String ageStr) { |
|||
|
|||
// 2. 还是原来的参数校验
|
|||
if (username == null || username.trim().isEmpty()) { |
|||
return "username_empty"; |
|||
} |
|||
if (realName == null || realName.trim().isEmpty()) { |
|||
return "realname_empty"; |
|||
} |
|||
int age; |
|||
try { |
|||
age = ageStr != null && !ageStr.isEmpty() ? Integer.parseInt(ageStr) : 0; |
|||
if (age < 0 || age > 150) { |
|||
return "age_invalid_range"; |
|||
} |
|||
} catch (NumberFormatException e) { |
|||
return "age_invalid_format"; |
|||
} |
|||
|
|||
// 3. 调用 UserService 处理业务(原来的逻辑移到 service 里了)
|
|||
User user = new User(username, realName, password, age); // 创建用户对象
|
|||
try { |
|||
if(userService.register(user)) { |
|||
return "success"; |
|||
} else { |
|||
return "username_exists"; |
|||
} |
|||
/*TODO: 要返回success和fail*/ |
|||
} catch (SQLException e) { |
|||
logger.error("Database error when registering user {}", username, e); |
|||
return "db_error"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
package houduan.Controller; |
|||
|
|||
import houduan.Object.User; |
|||
import houduan.Service.UserService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
|
|||
import java.sql.SQLException; |
|||
|
|||
@Controller |
|||
public class SignInController { |
|||
private final UserService userService; |
|||
|
|||
@Autowired |
|||
public SignInController(UserService userService) { |
|||
this.userService = userService; |
|||
} |
|||
|
|||
@RequestMapping(value = "/SignServlet", method = RequestMethod.POST) // 修正引用
|
|||
@ResponseBody //响应体
|
|||
public Object SignIn(@RequestParam(value = "username", required = true) String username, |
|||
@RequestParam(value = "password", required = true) String password) throws SQLException { |
|||
|
|||
try{ |
|||
|
|||
if(userService.login(username,password)!=null){ |
|||
User user=userService.login(username,password); |
|||
return user; |
|||
} else { |
|||
return "invalid_credentials"; |
|||
} |
|||
|
|||
}catch(Exception e){ |
|||
e.printStackTrace(); |
|||
return "error"; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
@ -0,0 +1,75 @@ |
|||
package houduan.DAO; |
|||
|
|||
|
|||
|
|||
import houduan.Object.User; |
|||
import houduan.DAO.UserDAO; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
import javax.sql.DataSource; |
|||
import java.sql.SQLException; |
|||
@Repository |
|||
// DAO 实现类:用 JdbcTemplate 实现数据库操作
|
|||
public class JdbcUserDao implements UserDAO { |
|||
|
|||
// 注入 Spring 管理的 JdbcTemplate(后续在 XML 中配置)
|
|||
@Autowired |
|||
private JdbcTemplate jdbcTemplate; |
|||
private DataSource dataSource; |
|||
|
|||
private User temp; |
|||
|
|||
public User getTemp() { |
|||
return temp; |
|||
} |
|||
// 实现“用户名是否存在”查询
|
|||
@Override |
|||
public boolean existsByUsername(String username) throws SQLException { |
|||
String sql = "SELECT COUNT(1) FROM User_table WHERE username = ?"; |
|||
// 用 JdbcTemplate 执行查询,返回结果(1 表示存在,0 表示不存在)
|
|||
Integer count = jdbcTemplate.queryForObject(sql, Integer.class, username); |
|||
return count != null && count > 0; |
|||
} |
|||
|
|||
// 实现“插入用户”操作
|
|||
@Override |
|||
public boolean insert(User user) throws SQLException { |
|||
String sql = "INSERT INTO User_table (username, real_name, age) VALUES (?, ?, ?,?)"; |
|||
// 用 JdbcTemplate 执行更新,返回影响行数
|
|||
int rows = jdbcTemplate.update(sql, |
|||
user.getUsername(), |
|||
user.getRealName(), |
|||
user.getPassword(), |
|||
user.getAge()); |
|||
return rows > 0; |
|||
} |
|||
|
|||
@Override |
|||
public boolean SelectDatabaseUser(String username, String password) throws SQLException { |
|||
try{ |
|||
String sqlg = "SELECT * FROM User_table WHERE username = ? AND password = ?"; |
|||
String sqlc= "SELECT COUNT(1) FROM User_table WHERE username = ? AND password = ?"; |
|||
Integer count = jdbcTemplate.queryForObject(sqlc, Integer.class, username, password); |
|||
if(count != null && count > 0){ |
|||
jdbcTemplate.queryForObject(sqlg, (rs, rowNum) -> { |
|||
temp=new User( |
|||
rs.getString("username"), |
|||
rs.getString("real_name"), |
|||
rs.getString("password"), |
|||
rs.getInt("age") |
|||
); |
|||
return temp; |
|||
}, username, password); |
|||
return true; |
|||
} |
|||
temp=null; |
|||
return false; |
|||
}catch (Exception e){ |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package houduan.DAO; |
|||
|
|||
|
|||
import houduan.Object.User; |
|||
import java.sql.SQLException; |
|||
|
|||
// DAO 接口:定义用户相关的数据库操作(只声明方法,不写实现)
|
|||
public interface UserDAO { |
|||
// 1. 查:用户名是否存在
|
|||
boolean existsByUsername(String username) throws SQLException; |
|||
|
|||
// 2. 增:插入新用户
|
|||
boolean insert(User user) throws SQLException; |
|||
|
|||
boolean SelectDatabaseUser(String username, String password) throws SQLException; |
|||
// 后续可添加其他操作(如查用户、更新用户等)
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package houduan; |
|||
|
|||
import java.io.InputStream; |
|||
import java.sql.*; |
|||
import java.util.Properties; |
|||
|
|||
public class DatabaseUtil { |
|||
private static String driver; |
|||
private static String url; |
|||
private static String username; |
|||
private static String password; |
|||
|
|||
// 静态代码块:加载配置 + 注册驱动
|
|||
static { |
|||
try (InputStream is = DatabaseUtil.class.getClassLoader().getResourceAsStream("database.properties")) { |
|||
if (is == null) { |
|||
throw new RuntimeException("找不到 database.properties 配置文件"); |
|||
} |
|||
Properties prop = new Properties(); |
|||
prop.load(is); |
|||
driver = prop.getProperty("jdbc.driver"); |
|||
url = prop.getProperty("jdbc.url"); |
|||
username = prop.getProperty("jdbc.username"); |
|||
password = prop.getProperty("jdbc.password"); |
|||
Class.forName(driver); // 注册 JDBC 驱动
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
// 获取数据库连接
|
|||
public static Connection getConnection() throws SQLException { |
|||
return DriverManager.getConnection(url, username, password); |
|||
} |
|||
|
|||
// 关闭资源
|
|||
public static void close(Connection conn, PreparedStatement pstmt, ResultSet rs) { |
|||
try { |
|||
if (rs != null) rs.close(); |
|||
if (pstmt != null) pstmt.close(); |
|||
if (conn != null) conn.close(); |
|||
} catch (SQLException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
package houduan.Object; |
|||
|
|||
public class User { |
|||
private String username; |
|||
private String realName; |
|||
private String password; |
|||
private int age; |
|||
|
|||
public User(String username, String realName, String password,int age) { |
|||
this.username = username; |
|||
this.realName = realName; |
|||
this.password=password; |
|||
this.age = age; |
|||
} |
|||
|
|||
// Getter + Setter
|
|||
public String getUsername() { return username; } |
|||
public void setUsername(String username) { this.username = username; } |
|||
public String getRealName() { return realName; } |
|||
public void setRealName(String realName) { this.realName = realName; } |
|||
public int getAge() { return age; } |
|||
public void setAge(int age) { this.age = age; } |
|||
|
|||
public String getPassword() { |
|||
return password; |
|||
} |
|||
|
|||
public void setPassword(String password) { |
|||
this.password = password; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
package houduan.Service; |
|||
|
|||
import houduan.DAO.JdbcUserDao; |
|||
import houduan.DatabaseUtil; |
|||
import houduan.Object.User; |
|||
import java.sql.Connection; |
|||
import java.sql.PreparedStatement; |
|||
import java.sql.ResultSet; |
|||
import java.sql.SQLException; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
@Service |
|||
// 业务类:专门处理用户相关业务(注册、登录等)
|
|||
public class UserService { |
|||
|
|||
@Autowired |
|||
private JdbcUserDao userDao; |
|||
|
|||
public boolean register(User user) throws SQLException { |
|||
if (userDao.existsByUsername(user.getUsername())) { |
|||
return false; |
|||
} |
|||
|
|||
return userDao.insert(user); |
|||
} |
|||
|
|||
public User login(String username, String password) throws SQLException { |
|||
if(userDao.SelectDatabaseUser(username, password)) { |
|||
return userDao.getTemp(); |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<beans xmlns="http://www.springframework.org/schema/beans" |
|||
xmlns:context="http://www.springframework.org/schema/context" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|||
http://www.springframework.org/schema/beans/spring-beans.xsd |
|||
http://www.springframework.org/schema/context |
|||
http://www.springframework.org/schema/context/spring-context.xsd"> |
|||
|
|||
<!-- 使用组件扫描,让带 @Service/@Repository/@Component/@Controller 的类自动注册 --> |
|||
<context:component-scan base-package="houduan"/> |
|||
|
|||
|
|||
</beans> |
|||
@ -0,0 +1,4 @@ |
|||
jdbc.driver=com.mysql.cj.jdbc.Driver |
|||
jdbc.url=jdbc:mysql://8.137.94.229:3306/DBMAIN?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC |
|||
jdbc.username=Me |
|||
jdbc.password=@Leiwei88 |
|||
@ -0,0 +1,52 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<beans xmlns="http://www.springframework.org/schema/beans" |
|||
xmlns:mvc="http://www.springframework.org/schema/mvc" |
|||
xmlns:context="http://www.springframework.org/schema/context" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|||
http://www.springframework.org/schema/beans/spring-beans.xsd |
|||
http://www.springframework.org/schema/mvc |
|||
http://www.springframework.org/schema/mvc/spring-mvc.xsd |
|||
http://www.springframework.org/schema/context |
|||
http://www.springframework.org/schema/context/spring-context.xsd"> |
|||
|
|||
<!-- 扫描整个 houduan 包,包含 Controller/Service/Object 等子包 --> |
|||
<context:component-scan base-package="houduan"/> |
|||
|
|||
<!-- 开启 Spring MVC 注解驱动(支持 @RequestMapping、@ResponseBody 等) --> |
|||
<mvc:annotation-driven/> |
|||
|
|||
<!-- 放行静态资源(如 CSS、JS,避免被控制器拦截) --> |
|||
<mvc:default-servlet-handler/> |
|||
|
|||
<bean id="templateResolver" class="org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver"> |
|||
<!-- 依赖Spring的上下文(必须设置) --> |
|||
<!-- 模板文件前缀(路径):通常放在WEB-INF/templates下(安全,避免直接访问) --> |
|||
<property name="prefix" value="/WEB-INF/templates/"/> |
|||
<!-- 模板文件后缀 --> |
|||
<property name="suffix" value=".html"/> |
|||
<!-- 模板类型(改为 Thymeleaf 3 支持的枚举值) --> |
|||
<property name="templateMode" value="HTML"/> |
|||
<!-- 编码格式(避免中文乱码) --> |
|||
<property name="characterEncoding" value="UTF-8"/> |
|||
<!-- 是否缓存模板(开发环境建议关闭,生产环境开启) --> |
|||
<property name="cacheable" value="false"/> |
|||
</bean> |
|||
|
|||
<bean id="templateEngine" class="org.thymeleaf.spring6.SpringTemplateEngine"> |
|||
<!-- 注入模板解析器 --> |
|||
<property name="templateResolver" ref="templateResolver"/> |
|||
<!-- 启用Spring EL表达式支持(默认已开启,可省略) --> |
|||
<property name="enableSpringELCompiler" value="true"/> |
|||
</bean> |
|||
|
|||
<bean class="org.thymeleaf.spring6.view.ThymeleafViewResolver"> |
|||
<!-- 注入模板引擎 --> |
|||
<property name="templateEngine" ref="templateEngine"/> |
|||
<!-- 编码格式(与模板解析器一致) --> |
|||
<property name="characterEncoding" value="UTF-8"/> |
|||
<!-- 视图优先级(数值越小优先级越高,避免与其他视图解析器冲突) --> |
|||
<property name="order" value="1"/> |
|||
</bean> |
|||
|
|||
</beans> |
|||
@ -0,0 +1,12 @@ |
|||
<!DOCTYPE html> |
|||
<!-- 声明Thymeleaf命名空间(关键,否则表达式不生效) --> |
|||
<html xmlns:th="http://www.thymeleaf.org"> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<title>Thymeleaf Test</title> |
|||
</head> |
|||
<body> |
|||
<!-- 使用th:text表达式获取模型中的message --> |
|||
<h1 th:text="${message}">默认文本(当模板未被解析时显示)</h1> |
|||
</body> |
|||
</html> |
|||
@ -1,15 +1,25 @@ |
|||
<web-app id="WebApp_ID" version="4.0" |
|||
xmlns="http://xmlns.jcp.org/xml/ns/javaee" |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<web-app xmlns="http://jakarta.ee/xml/ns/jakartaee" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee |
|||
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"> |
|||
<display-name>xss</display-name> |
|||
<welcome-file-list> |
|||
<welcome-file>index.html</welcome-file> |
|||
<welcome-file>index.htm</welcome-file> |
|||
<welcome-file>index.jsp</welcome-file> |
|||
<welcome-file>default.html</welcome-file> |
|||
<welcome-file>default.htm</welcome-file> |
|||
<welcome-file>default.jsp</welcome-file> |
|||
</welcome-file-list> |
|||
xsi:schemaLocation="http://jakarta.ee/xml/ns/jakartaee |
|||
http://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" |
|||
version="6.0"> |
|||
|
|||
<!-- DispatcherServlet(Spring MVC) --> |
|||
<servlet> |
|||
<servlet-name>dispatcher</servlet-name> |
|||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> |
|||
<init-param> |
|||
<param-name>contextConfigLocation</param-name> |
|||
<param-value>/WEB-INF/springmvc.xml</param-value> |
|||
</init-param> |
|||
<load-on-startup>1</load-on-startup> |
|||
</servlet> |
|||
|
|||
<servlet-mapping> |
|||
<servlet-name>dispatcher</servlet-name> |
|||
<url-pattern>/</url-pattern> |
|||
</servlet-mapping> |
|||
|
|||
<!-- 可选:字符编码过滤器等(如需要再添加) --> |
|||
</web-app> |
|||
Loading…
Reference in new issue