完成框架
This commit is contained in:
parent
6a95bbf583
commit
cc50454c0d
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$APPLICATION_HOME_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$APPLICATION_HOME_DIR$/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
|
||||
84
pom.xml
84
pom.xml
@ -1,28 +1,37 @@
|
||||
<?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">
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.campus</groupId>
|
||||
<artifactId>campus-attendance</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring.version>5.3.30</spring.version>
|
||||
<mybatis.version>3.5.13</mybatis.version>
|
||||
<mysql.version>8.0.33</mysql.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<spring.version>5.3.23</spring.version>
|
||||
<mybatis.version>3.5.11</mybatis.version>
|
||||
<mybatis.spring.version>2.0.7</mybatis.spring.version> <!-- 修正后的行 -->
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring MVC -->
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring JDBC & Transaction -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
@ -37,27 +46,20 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.2</version>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>${mybatis.spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL & Druid 数据库连接池 -->
|
||||
<!-- 数据库 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.16</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON 处理 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.0</version>
|
||||
<version>1.2.15</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Servlet API -->
|
||||
@ -67,18 +69,54 @@
|
||||
<version>4.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<version>2.3.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jstl</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.14.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>campus-attendance</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<!-- 新增 JDK 17 编译参数 -->
|
||||
<compilerArgs>
|
||||
<arg>--enable-preview</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
18
src/main/java/com/campus/controller/PageController.java
Normal file
18
src/main/java/com/campus/controller/PageController.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.campus.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class PageController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping("/students")
|
||||
public String studentList() {
|
||||
return "student_list";
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
<!-- StudentMapper.xml -->
|
||||
<mapper namespace="com.campus.mapper.StudentMapper">
|
||||
<select id="selectAll" resultType="com.campus.entity.Student">
|
||||
SELECT * FROM student
|
||||
</select>
|
||||
<insert id="insert" parameterType="com.campus.entity.Student">
|
||||
INSERT INTO student(name, student_id, class, major)
|
||||
VALUES(#{name}, #{studentId}, #{class_}, #{major})
|
||||
</insert>
|
||||
</mapper>
|
||||
@ -19,17 +19,24 @@
|
||||
<property name="url" value="${jdbc.url}"/>
|
||||
<property name="username" value="${jdbc.username}"/>
|
||||
<property name="password" value="${jdbc.password}"/>
|
||||
<!-- 添加连接池基本配置 -->
|
||||
<property name="initialSize" value="5"/>
|
||||
<property name="minIdle" value="5"/>
|
||||
<property name="maxActive" value="20"/>
|
||||
</bean>
|
||||
|
||||
<!-- MyBatis 会话工厂 -->
|
||||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="configLocation" value="classpath:mybatis-config.xml"/>
|
||||
<!-- 添加映射文件配置 -->
|
||||
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
|
||||
</bean>
|
||||
|
||||
<!-- Mapper 扫描 -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||
<property name="basePackage" value="com.campus.mapper"/>
|
||||
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
|
||||
</bean>
|
||||
|
||||
<!-- 事务管理 -->
|
||||
|
||||
22
src/main/resources/mapper/StudentMapper.xml
Normal file
22
src/main/resources/mapper/StudentMapper.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.campus.mapper.StudentMapper">
|
||||
<select id="selectAll" resultType="com.campus.entity.Student">
|
||||
SELECT * FROM student
|
||||
</select>
|
||||
<!-- 修改 insert 和 update 语句中的 class 字段 -->
|
||||
<insert id="insert" parameterType="com.campus.entity.Student">
|
||||
INSERT INTO student(name, student_id, `class`, major) <!-- 新增反引号 -->
|
||||
VALUES(#{name}, #{studentId}, #{class_}, #{major})
|
||||
</insert>
|
||||
<update id="update" parameterType="com.campus.entity.Student">
|
||||
UPDATE student
|
||||
SET name = #{name}, student_id = #{studentId}, `class` = #{class_}, major = #{major} <!-- 新增反引号 -->
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
<delete id="delete" parameterType="java.lang.Integer">
|
||||
DELETE FROM student WHERE id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
||||
@ -13,8 +13,6 @@
|
||||
<!-- 扫描 Controller -->
|
||||
<context:component-scan base-package="com.campus.controller"/>
|
||||
|
||||
<!-- 开启 MVC 注解支持 -->
|
||||
<mvc:annotation-driven/>
|
||||
|
||||
<!-- 视图解析器 -->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
@ -24,4 +22,9 @@
|
||||
|
||||
<!-- 静态资源处理 -->
|
||||
<mvc:default-servlet-handler/>
|
||||
<mvc:annotation-driven>
|
||||
<mvc:message-converters>
|
||||
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
|
||||
</mvc:message-converters>
|
||||
</mvc:annotation-driven>
|
||||
</beans>
|
||||
17
src/main/webapp/WEB-INF/jsp/index.jsp
Normal file
17
src/main/webapp/WEB-INF/jsp/index.jsp
Normal file
@ -0,0 +1,17 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: LY
|
||||
Date: 2025/12/3
|
||||
Time: 14:40
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>首页</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>学生考勤系统</h1>
|
||||
<a href="/students">学生列表</a>
|
||||
</body>
|
||||
</html>
|
||||
@ -6,6 +6,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>学生列表</h2>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>姓名</th>
|
||||
@ -23,7 +24,7 @@
|
||||
html += `<tr>
|
||||
<td>${s.name}</td>
|
||||
<td>${s.studentId}</td>
|
||||
<td>${s.class}</td>
|
||||
<td>${s.class_}</td> <!-- 注意这里是class_ -->
|
||||
<td>${s.major}</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user