This commit is contained in:
awin-x 2024-12-26 14:53:20 +08:00
parent addf9b30f6
commit 7b582071cc
91 changed files with 431 additions and 197 deletions

View File

@ -25,5 +25,20 @@
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="db_student" uuid="e52053d6-7a76-429a-af2f-d7d197f5a15d">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:F:\Work_Area\desk\java\web实验\test05\src\main\resources\db\db_student.db</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.47.0.0.jar</url>
</library>
</libraries>
</data-source>
</component>
</project>

View File

@ -1,31 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<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-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" />

View File

@ -4,6 +4,9 @@
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.sql.Connection,prepareStatement,java.lang.ClassLoader,getResourceAsStream,org.apache.commons.dbcp2.BasicDataSourceFactory,createDataSource" />
</inspection_tool>
<inspection_tool class="CommentedOutCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="minLines" value="10" />
</inspection_tool>
<inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
<option name="myValues">
<value>

View File

@ -5,15 +5,9 @@
<option name="originalFiles">
<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-springboot/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" />

View File

@ -7,7 +7,6 @@
<module fileurl="file://$PROJECT_DIR$/learn1/learn1.iml" filepath="$PROJECT_DIR$/learn1/learn1.iml" />
<module fileurl="file://$PROJECT_DIR$/test02/test02.iml" filepath="$PROJECT_DIR$/test02/test02.iml" />
<module fileurl="file://$PROJECT_DIR$/test04/test04.iml" filepath="$PROJECT_DIR$/test04/test04.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/web实验.iml" filepath="$PROJECT_DIR$/.idea/web实验.iml" />
</modules>
</component>
</project>

View File

@ -12,7 +12,11 @@
</head>
<body>
<% UserDB dbBean = new UserDB();
dbBean.ShowCommonUsers();
try {
dbBean.ShowCommonUsers();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
%>
</body>
</html>

View File

@ -20,7 +20,7 @@ import java.util.Properties;
* @author Awin-x
*/
public class DBTool {
static DataSource ds;
static final DataSource ds;
static{
Properties prop = new Properties();
try {

View File

@ -1,12 +1,6 @@
package controller;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/scoreAction/*")
public class ScoreController extends BaseController {

View File

@ -1,8 +1,6 @@
package controller;
import dao.TeacherDB;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import pojo.TeacherInfo;

View File

@ -1,11 +1,6 @@
package controller;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
@WebServlet("/teacherAction/*")
public class TeacherController extends BaseController {

View File

@ -2,13 +2,11 @@ package controller;
import dao.impl.UserDBImpl;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import pojo.UserInfo;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@WebServlet("/userAction/*")
public class UserController extends BaseController {

View File

@ -13,7 +13,7 @@ public class UserDBImpl implements UserDB {
@Override
public UserInfo getUserByName(String username) {
UserInfo u = new UserInfo();
ResultSet rs = null;
ResultSet rs;
try{
String sql = "select * from t_user where VC_LOGIN_NAME = ?";
PreparedStatement ps = DBTool.getPreparedStatement(sql);
@ -36,7 +36,7 @@ public class UserDBImpl implements UserDB {
@Override
public UserInfo getUserById(int id) {
UserInfo u = new UserInfo();
ResultSet rs = null;
ResultSet rs;
try{
String sql = "select * from t_user where N_USER_ID = ?";
PreparedStatement ps = DBTool.getPreparedStatement(sql);
@ -58,7 +58,7 @@ public class UserDBImpl implements UserDB {
@Override
public int addUser(UserInfo user) {
int lines = 0;
int lines;
String sql = "INSERT INTO t_user (VC_LOGIN_NAME, VC_PASSWORD) VALUES (?, ?)";
try{
PreparedStatement ps = DBTool.getPreparedStatement(sql);
@ -73,7 +73,7 @@ public class UserDBImpl implements UserDB {
@Override
public int updateUser(UserInfo user) {
int lines = 0;
int lines;
String sql = "UPDATE t_user SET VC_PASSWORD = ?,VC_LOGIN_NAME = ? WHERE N_USER_ID = ?";
try{
PreparedStatement ps = DBTool.getPreparedStatement(sql);
@ -94,7 +94,7 @@ public class UserDBImpl implements UserDB {
try{
PreparedStatement ps = DBTool.getPreparedStatement(sql);
ps.setInt(1, id);
lines = ps.executeUpdate();
ps.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}

View File

@ -1,9 +1,6 @@
package filters;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

View File

@ -1,3 +1,4 @@
<%--suppress HtmlUnknownAttribute --%>
<%--
Created by IntelliJ IDEA.
User: 25589
@ -31,6 +32,7 @@
<td>开设年级</td>
<td>开设专业</td>
</tr>
<%--suppress HtmlUnknownAttribute --%>
<tr v-for="course in courses">
<td>{{course.name}}</td>
<td>{{types[course.type]}}</td>
@ -38,7 +40,9 @@
<td>{{course.grade}}</td>
<td>{{majors[course.major]}}</td>
<td>
<%--suppress HtmlUnknownAttribute --%>
<a class="blue" @click="edit()">编辑</a>
<%--suppress HtmlUnknownAttribute --%>
<a class="red" :href="path+'/courseAction/delete?id='+course.id">删除</a>
</td>
</tr>

View File

@ -54,9 +54,3 @@ button,.button{
color: blue;
}
.underline {
BORDER-BOTTOM: #c4c4c4 1pt solid;
BORDER-LEFT: #c4c4c4;
BORDER-RIGHT: #c4c4c4;
BORDER-TOP: #c4c4c4;
}

View File

@ -27,7 +27,9 @@
<input type="text" v-model="message">
</label>
{{ message }}
<%--suppress HtmlUnknownAttribute --%>
<h3 v-if="message === 'Hello vue'">这是Hello vue</h3>
<%--suppress HtmlUnknownAttribute --%>
<h3 v-else>这不是Hello vue</h3>
</div>
</div>

View File

@ -14,7 +14,7 @@ import java.util.Properties;
* @author Awin-x
*/
public class DBTool {
static DataSource ds;
static final DataSource ds;
static{
Properties prop = new Properties();
try {

View File

@ -4,7 +4,6 @@ import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import login.UserInfo;
import java.io.IOException;

View File

@ -10,7 +10,7 @@ import java.io.IOException;
@WebServlet("/CourseDeleteAction")
public class CourseDeleteAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String path = req.getContextPath();
if (req.getSession().getAttribute("user") == null){
resp.sendRedirect(path+"/login/login.jsp");

View File

@ -10,7 +10,7 @@ import java.io.IOException;
@WebServlet("/CourseEditAction")
public class CourseEditAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String path = req.getContextPath();
if (req.getSession().getAttribute("user") == null){
resp.setStatus(403);

View File

@ -12,7 +12,7 @@ import java.util.ArrayList;
@WebServlet("/CourseListAction")
public class CourseListAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String path = req.getContextPath();
if (req.getSession().getAttribute("user") == null){
resp.setStatus(403);

View File

@ -9,7 +9,7 @@ import java.sql.SQLException;
public class UserDB {
public static UserInfo GetUserInfo(int id) {
UserInfo u = new UserInfo();
ResultSet rs = null;
ResultSet rs;
try{
String sql = "select * from t_user where N_USER_ID = ?";
PreparedStatement ps = DBTool.getPreparedStatement(sql);
@ -30,7 +30,7 @@ public class UserDB {
}
public static UserInfo GetUserInfoByName(String username) {
UserInfo u = new UserInfo();
ResultSet rs = null;
ResultSet rs;
try{
String sql = "select * from t_user where VC_LOGIN_NAME = ?";
PreparedStatement ps = DBTool.getPreparedStatement(sql);

View File

@ -10,7 +10,7 @@ import java.io.IOException;
@WebServlet("/UserLogoutAction")
public class UserLogoutAction extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
String username = request.getParameter("username");
UserInfo user = (UserInfo)request.getSession().getAttribute("user");
if(user != null) {

View File

@ -54,9 +54,3 @@ button,.button{
color: blue;
}
.underline {
BORDER-BOTTOM: #c4c4c4 1pt solid;
BORDER-LEFT: #c4c4c4;
BORDER-RIGHT: #c4c4c4;
BORDER-TOP: #c4c4c4;
}

View File

@ -17,24 +17,10 @@ table{
border-spacing: 0;
}
.td1 {
BACKGROUND-COLOR: #e6e6e6
}
.td_header {
BACKGROUND-COLOR: #e6e6e6; COLOR: #000000
}
.td_1 {
BACKGROUND-COLOR: #f8fbfb; COLOR: #000000
}
.td_2 {
BACKGROUND-COLOR: #deecec; COLOR: #000000
}
.td3 {
BACKGROUND-COLOR: #a3d1d2; COLOR: black
}
.underline {
BORDER-BOTTOM: #c4c4c4 1pt solid; BORDER-LEFT: #c4c4c4; BORDER-RIGHT: #c4c4c4; BORDER-TOP: #c4c4c4
}
.button {
border:1px solid black;
background-color:white;
@ -43,12 +29,7 @@ table{
.star {
COLOR: red
}
.tb_showall
{
background:#0078B7;
font-size: 18px;
font-weight: bold;
}
.container{
margin: auto;
width: 80%;

View File

@ -1,3 +1,4 @@
<%--suppress HtmlUnknownTarget --%>
<%--
Created by IntelliJ IDEA.
User: 25589

View File

@ -21,20 +21,11 @@ public class DBTool {
conn = DriverManager.getConnection(url, username, password);
}
// public ResultSet doQuery(String sql) throws SQLException {
// rs = stmt.executeQuery(sql);
// return rs;
// }
public ResultSet runSQL(PreparedStatement ps) throws SQLException {
rs = ps.executeQuery();
return rs;
}
// public int doUpdate(String sql) throws SQLException {
// return stmt.executeUpdate(sql);
// }
public void close() throws SQLException {
if(rs!=null){
rs.close();

View File

@ -10,7 +10,7 @@ import java.io.IOException;
@WebServlet("/courseAddAction")
public class courseAddAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
courseDB coursedb = new courseDB();
int id = Integer.parseInt(req.getParameter("id"));
courseInfo course = new courseInfo();

View File

@ -10,7 +10,7 @@ import java.io.IOException;
@WebServlet("/courseDeleteAction")
public class courseDeleteAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
int id = Integer.parseInt(req.getParameter("id"));
courseDB coursedb = new courseDB();
coursedb.deleteCourse(id);

View File

@ -10,7 +10,7 @@ import java.io.IOException;
@WebServlet("/courseEditAction")
public class courseEditAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
courseDB coursedb = new courseDB();
int id = Integer.parseInt(req.getParameter("id"));
courseInfo course = coursedb.getCourseInfo(id);

View File

@ -12,7 +12,7 @@ import java.util.ArrayList;
@WebServlet("/courseListAction")
public class courseListAction extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
protected void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
courseDB coursedb = new courseDB();
ArrayList<courseInfo> course_list = coursedb.getAllCourses();
StringBuilder json= new StringBuilder("[");

View File

@ -13,24 +13,10 @@ table{
border-spacing: 0;
}
.td1 {
BACKGROUND-COLOR: #e6e6e6
}
.td_header {
BACKGROUND-COLOR: #e6e6e6; COLOR: #000000
}
.td_1 {
BACKGROUND-COLOR: #f8fbfb; COLOR: #000000
}
.td_2 {
BACKGROUND-COLOR: #deecec; COLOR: #000000
}
.td3 {
BACKGROUND-COLOR: #a3d1d2; COLOR: black
}
.underline {
BORDER-BOTTOM: #c4c4c4 1pt solid; BORDER-LEFT: #c4c4c4; BORDER-RIGHT: #c4c4c4; BORDER-TOP: #c4c4c4
}
.button {
border:1px solid black;
background-color:white;
@ -39,12 +25,7 @@ table{
.star {
COLOR: red
}
.tb_showall
{
background:#0078B7;
font-size: 18px;
font-weight: bold;
}
.container{
margin: auto;
width: 80%;

View File

@ -83,12 +83,6 @@
<artifactId>jjwt</artifactId>
<version>0.12.3</version>
</dependency>
<dependency>
<groupId>top.awin-x</groupId>
<artifactId>learn03-springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
@ -99,6 +93,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.realityforge.org.jetbrains.annotations/org.jetbrains.annotations -->
<dependency>
<groupId>org.realityforge.org.jetbrains.annotations</groupId>
<artifactId>org.jetbrains.annotations</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
<build>

View File

@ -2,7 +2,6 @@ package test05;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
@SpringBootApplication
public class Test05Application {

View File

@ -15,7 +15,7 @@ public class TimeAspect {
long begin = System.currentTimeMillis();
Object result = joinPoint.proceed();
long end = System.currentTimeMillis();
log.info(joinPoint.getSignature()+"耗时:{}ms", end-begin);
log.info("{}耗时:{}ms", joinPoint.getSignature(), end - begin);
return result;
}
}

View File

@ -0,0 +1,69 @@
package test05.config;
import com.alibaba.druid.pool.DruidDataSource;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import test05.Test05Application;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
@Component
public class DatabaseConfig {
// @Autowired 可以注入bean
// ISysUserService userService;
DruidDataSource ds;
@Autowired
DatabaseConfig(DruidDataSource ds) {
this.ds = ds;
}
@PostConstruct
public void init() throws InterruptedException, IOException, SQLException {
//启动时输入数据库连接地址
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// System.out.println("请输入数据库连接地址");
// String buf = br.readLine();
// System.out.println(buf);
// ds.setUrl(buf);
// buf = br.readLine();
// ds.setUsername(buf);
// buf = br.readLine();
// ds.setPassword(buf);
System.out.println(System.getProperty("user.dir"));
String workingDir = System.getProperty("user.dir");
if (new File(workingDir+"\\db_student.db").exists()) {
ds.restart();
ds.setDriverClassName("org.sqlite.JDBC");
ds.setUrl("jdbc:sqlite:"+workingDir+"\\db_student.db");
System.out.println("使用外部数据库文件!");
}else{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请选择数据库1mysql2sqlite");
int type = Integer.parseInt(br.readLine());
switch (type) {
case 1:
ds.setDriverClassName("com.mysql.jdbc.Driver");
System.out.println("请输入数据库url仅地址,留空使用localhost:3306");
String url= br.readLine();
ds.setUrl("jdbc:mysql:"+(url.isEmpty()?"localhost:3306":url)+(url.endsWith("/")?"":"/")+"db_student");
System.out.println("请输入用户名:");
String username=br.readLine();
ds.setUsername(username);
System.out.println("请输入密码:");
String password=br.readLine();
ds.setPassword(password);
case 2:
System.out.println("使用内嵌测试数据,修改将不会被保存!");
ds.setDriverClassName("org.sqlite.JDBC");
ds.setUrl("jdbc:sqlite::resource:db/db_student.db");
}
}
}
}

View File

@ -3,7 +3,6 @@ package test05.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import test05.interceptor.LoginCheckInterceptor;
@ -18,6 +17,6 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**").excludePathPatterns("/userAction/login");
registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/*Action/**").excludePathPatterns("/userAction/login");
}
}

View File

@ -10,7 +10,6 @@ import test05.service.CourseService;
@RestController
@RequestMapping("/courseAction")
@CrossOrigin
public class CourseController {
private final CourseService courseService;

View File

@ -3,6 +3,7 @@ package test05.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SuppressWarnings("SameReturnValue")
@RestController
@RequestMapping("/test")
public class Hello {

View File

@ -1,6 +1,5 @@
package test05.controller;
import io.jsonwebtoken.Jwt;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
@ -15,7 +14,6 @@ import java.util.Map;
@RestController
@RequestMapping("/userAction")
@CrossOrigin
public class LoginController {
private final UserService userService;
@Autowired
@ -23,11 +21,10 @@ public class LoginController {
this.userService = userService;
}
@CrossOrigin
@RequestMapping("/login")
public Result login(String username, String password, HttpSession session) {
if (session.getAttribute("user") != null) {
String loginName = ((Map<String, String>)(JwtUtils.parseJwt((String)session.getAttribute("user")).get("data"))).get("name");
@SuppressWarnings("unchecked") String loginName = ((Map<String, String>)(JwtUtils.parseJwt((String)session.getAttribute("user")).get("data"))).get("name");
if (loginName.equals(username)) {
return Result.success(session.getAttribute("user"));
}
@ -42,7 +39,6 @@ public class LoginController {
return res;
}
@CrossOrigin
@RequestMapping("/logout")
public Result logout(HttpSession session) {
session.removeAttribute("user");

View File

@ -0,0 +1,34 @@
package test05.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import test05.pojo.Result;
import test05.pojo.Score;
import test05.service.ScoreService;
@RestController
@RequestMapping("/scoreAction")
public class ScoreController {
ScoreService scoreService;
@Autowired
public ScoreController(ScoreService scoreService) {
this.scoreService = scoreService;
}
@RequestMapping("/get")
public Result getScore(Score score) {
return scoreService.getScore(score);
}
@RequestMapping("/update")
public Result updateScore(Score score) {
return scoreService.updateScore(score);
}
@RequestMapping("add")
public Result addScore(Score score) {
return scoreService.addScore(score);
}
@RequestMapping("delete")
public Result deleteScore(Score score) {
return scoreService.deleteScore(score);
}
}

View File

@ -8,7 +8,6 @@ import test05.pojo.Result;
import test05.pojo.Student;
import test05.service.StudentService;
@CrossOrigin(maxAge = 3600)
@RestController
@RequestMapping("/studentAction")
public class studentController {

View File

@ -3,6 +3,7 @@ package test05.interceptor;
import com.alibaba.fastjson2.JSONObject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@ -12,22 +13,22 @@ import test05.utils.JwtUtils;
@Component
public class LoginCheckInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
String token = request.getHeader("token");
try{
JwtUtils.parseJwt(token);
}catch(Exception e){;
}catch(Exception e){
response.getWriter().print(JSONObject.toJSONString(Result.error("not login")));
return false;
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
public void postHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, ModelAndView modelAndView) {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
public void afterCompletion(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, Exception ex) {
}
}

View File

@ -12,28 +12,28 @@ public interface CourseMapper {
* @param course 作为查询条件该对象中的默认值表示不对该项筛选
* @return 查询结果集
*/
public List<Course> selectCourse(Course course, int page, int pageSize);
List<Course> selectCourse(Course course, int page, int pageSize);
/**
* 插入课程
* @param course 要插入的课程
* @return 影响的行数大于0时表示插入成功
*/
public int insertCourse(Course course);
int insertCourse(Course course);
/**
* 更新课程
* @param course 更新的课程id作为更新条件所有其他字段都将会被更新
* @return 影响的行数行数大于0时表示根性成功
*/
public int updateCourse(Course course);
int updateCourse(Course course);
/**
* 删除课程
* @param course 删除的课程id作为删除条件
* @return 影响的行数行数大于0时表示删除成功
*/
public int deleteCourse(Course course);
int deleteCourse(Course course);
public int selectCourseCount(Course course);
int selectCourseCount(Course course);
}

View File

@ -7,8 +7,9 @@ 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);
List<Score> selectScore(Score score);
int selectScoreCount(Score score);
int insertScore(Score score);
int deleteScore(Score score);
int updateScore(Score score);
}

View File

@ -7,9 +7,9 @@ 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);
List<Student> selectStudent(Student student, int page, int pageSize);
int selectStudentCount(Student student);
int insertStudent(Student student);
int updateStudent(Student student);
int deleteStudent(Student student);
}

View File

@ -10,13 +10,13 @@ import lombok.NonNull;
@NoArgsConstructor
public class Score {
@NonNull
private Integer N_STUDENT_ID = -1;
private Integer studentId = -1;
@NonNull
private Integer N_COURSE_ID = -1;
private Integer courseId = -1;
@NonNull
private Float F_SCORE = -1.0F;
private Float score = -1.0F;
public Score(int stu_id, int course_id){
this.N_STUDENT_ID = stu_id;
this.N_COURSE_ID = course_id;
this.studentId = stu_id;
this.courseId = course_id;
}
}

View File

@ -4,8 +4,8 @@ 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 addCourse(Course course);
Result deleteCourse(Course course);
Result updateCourse(Course course);
Result getCourse(Course course, int page, int pageSize);
}

View File

@ -0,0 +1,11 @@
package test05.service;
import test05.pojo.Result;
import test05.pojo.Score;
public interface ScoreService {
Result addScore(Score score);
Result getScore(Score score);
Result deleteScore(Score score);
Result updateScore(Score score);
}

View File

@ -4,8 +4,8 @@ import test05.pojo.Result;
import test05.pojo.Student;
public interface StudentService {
public Result getStudent(Student student, int page, int pageSize);
public Result addStudent(Student student);
public Result updateStudent(Student student);
public Result deleteStudent(Student student);
Result getStudent(Student student, int page, int pageSize);
Result addStudent(Student student);
Result updateStudent(Student student);
Result deleteStudent(Student student);
}

View File

@ -9,5 +9,5 @@ public interface UserService {
* @param user 包含用户名和密码用于比对
* @return 登录结果
*/
public Result login(User user);
Result login(User user);
}

View File

@ -0,0 +1,47 @@
package test05.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import test05.mapper.ScoreMapper;
import test05.pojo.Result;
import test05.pojo.Score;
import test05.service.ScoreService;
import java.util.List;
@Service
public class ScoreServiceImpl implements ScoreService {
ScoreMapper scoreMapper;
@Autowired
public ScoreServiceImpl(ScoreMapper scoreMapper) {
this.scoreMapper = scoreMapper;
}
@Override
public Result addScore(Score score) {
if(score.getScore()==-1||score.getStudentId()==-1||score.getCourseId()==-1){
return Result.error("incorrect score");
}
return Result.success(scoreMapper.insertScore(score));
}
@Override
public Result getScore(Score score) {
if(score.getStudentId()==-1||score.getCourseId()==-1){
return Result.error("incorrect score");
}
List<Score> result = scoreMapper.selectScore(score);
return Result.success(result, scoreMapper.selectScoreCount(score));
}
@Override
public Result deleteScore(Score score) {
return Result.success(scoreMapper.deleteScore(score)>0);
}
@Override
public Result updateScore(Score score) {
return Result.success(scoreMapper.updateScore(score)>0);
}
}

View File

@ -26,7 +26,7 @@ public class UserServiceImpl implements UserService {
return Result.error("user dose not exist");
}
if (selectUser.getPassword().equals(user.getPassword())) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("id", selectUser.getId());
map.put("name", selectUser.getName());
return Result.success(JwtUtils.getJwt(map));

View File

@ -5,7 +5,6 @@ import io.jsonwebtoken.security.Keys;
import javax.crypto.SecretKey;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class JwtUtils {

View File

@ -2,8 +2,8 @@ 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
#spring.datasource.url=jdbc:sqlite:F:\\Work_Area\\desk\\database\\\u5B66\u4E60\\java\u6D4B\u8BD5\u6570\u636E\u5E93\\db_student.db
spring.datasource.url=jdbc:sqlite::resource:db/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

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,47 @@
html{
margin: 0;
padding: 0;
background-color: #fff;
width: 100%;
height: 100%;
overflow: hidden;
}
body{
margin: 0;
padding: 0;
height: 100%;;
width: 100%;
}
a{
text-decoration: none;
}
darkblue{
color: darkblue;
}
.header{
background-color: #1cf;
line-height: 100%;
color: #fff;
}
.el-menu-item i{
color: white;
}
.el-menu-item.is-active{
font-size: larger;
}
.aside{
height: 100%;
}
.H-full{
height: 100%;
}
.W-full{
width: 100%;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1 @@
<!doctype html><html lang="zh-cn"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>student-information-sys</title><script defer="defer" src="/js/chunk-vendors.418e428c.js"></script><script defer="defer" src="/js/app.f724117d.js"></script><link href="/css/chunk-vendors.10dd4e95.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but student-information-sys doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body><link rel="stylesheet" href="css/main.css"></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
"use strict";(self["webpackChunkstudent_information_sys"]=self["webpackChunkstudent_information_sys"]||[]).push([[376],{8376:function(e,s,t){t.r(s),t.d(s,{default:function(){return d}});var r=function(){var e=this,s=e._self._c;return s("div",[s("div",{staticClass:"login-card"},[s("el-form",{ref:"form",attrs:{model:e.loginform,"label-width":"80px"}},[s("el-form-item",{attrs:{label:"用户名"}},[s("el-input",{model:{value:e.loginform.username,callback:function(s){e.$set(e.loginform,"username",s)},expression:"loginform.username"}})],1),s("el-form-item",{attrs:{label:"密码"}},[s("el-input",{attrs:{type:"password"},model:{value:e.loginform.password,callback:function(s){e.$set(e.loginform,"password",s)},expression:"loginform.password"}})],1),s("el-form-item",[s("el-button",{attrs:{type:"primary"},on:{click:e.login}},[e._v("登录")])],1)],1)],1)])},o=[],a=(t(6206),t(1728)),l=t.n(a),n={data(){return{loginform:{username:"",password:""}}},methods:{login(){l().ajax({url:this.$apiUrl+"/userAction/login",method:"POST",data:this.loginform,success:e=>{e.success?(localStorage.setItem("user",e.data),l().ajaxSetup({headers:{token:e.data}}),this.$route.query.redirect?this.$router.push({name:this.$route.query.redirect}):this.$router.push("student")):this.$message({type:"error",message:"登录失败,"+e.msg,showClose:!0})},error:e=>{this.$message({type:"error",message:"登录失败code="+e.status,showClose:!0})}})}},mounted(){}},i=n,u=t(8126),m=(0,u.A)(i,r,o,!1,null,null,null),d=m.exports}}]);
//# sourceMappingURL=376.23b9bc94.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
"use strict";(self["webpackChunkstudent_information_sys"]=self["webpackChunkstudent_information_sys"]||[]).push([[994],{6994:function(n,t,u){u.r(t),u.d(t,{default:function(){return _}});var s=function(){var n=this;n._self._c;return n._m(0)},e=[function(){var n=this,t=n._self._c;return t("div",[t("h1",[n._v("尚未完成")])])}],r={},i=r,f=u(8126),l=(0,f.A)(i,s,e,!1,null,null,null),_=l.exports}}]);
//# sourceMappingURL=994.55fb0c1b.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"js/994.55fb0c1b.js","mappings":"0LAAA,IAAIA,EAAS,WAAkB,IAAIC,EAAIC,KAAQD,EAAIE,MAAMC,GAAG,OAAOH,EAAII,GAAG,EAC1E,EACIC,EAAkB,CAAC,WAAY,IAAIL,EAAIC,KAAKE,EAAGH,EAAIE,MAAMC,GAAG,OAAOA,EAAG,MAAM,CAACA,EAAG,KAAK,CAACH,EAAIM,GAAG,WACjG,GCEA,GAEC,ECPmgB,I,UCOhgBC,GAAY,OACd,EACAR,EACAM,GACA,EACA,KACA,KACA,MAIF,EAAeE,EAAiB,O","sources":["webpack://student-information-sys/./src/views/teacher/teacherList.vue","webpack://student-information-sys/src/views/teacher/teacherList.vue","webpack://student-information-sys/./src/views/teacher/teacherList.vue?83bc","webpack://student-information-sys/./src/views/teacher/teacherList.vue?700e"],"sourcesContent":["var render = function render(){var _vm=this,_c=_vm._self._c;return _vm._m(0)\n}\nvar staticRenderFns = [function (){var _vm=this,_c=_vm._self._c;return _c('div',[_c('h1',[_vm._v(\"尚未完成\")])])\n}]\n\nexport { render, staticRenderFns }","<template>\r\n <div><h1>尚未完成</h1></div>\r\n</template>\r\n\r\n<script>\r\nexport default {\r\n\r\n}\r\n</script>\r\n\r\n<style>\r\n\r\n</style>","import mod from \"-!../../../node_modules/.pnpm/thread-loader@3.0.4_webpack@5.97.1/node_modules/thread-loader/dist/cjs.js!../../../node_modules/.pnpm/babel-loader@8.4.1_@babel+core@7.26.0_webpack@5.97.1/node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!../../../node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.13_css-loader@6.11.0_webpack@5.97.1__lodash@4.17.21__nkjjb5puplgtn2g67cuu4wxlfy/node_modules/vue-loader/lib/index.js??vue-loader-options!./teacherList.vue?vue&type=script&lang=js\"; export default mod; export * from \"-!../../../node_modules/.pnpm/thread-loader@3.0.4_webpack@5.97.1/node_modules/thread-loader/dist/cjs.js!../../../node_modules/.pnpm/babel-loader@8.4.1_@babel+core@7.26.0_webpack@5.97.1/node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!../../../node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.13_css-loader@6.11.0_webpack@5.97.1__lodash@4.17.21__nkjjb5puplgtn2g67cuu4wxlfy/node_modules/vue-loader/lib/index.js??vue-loader-options!./teacherList.vue?vue&type=script&lang=js\"","import { render, staticRenderFns } from \"./teacherList.vue?vue&type=template&id=29168d45\"\nimport script from \"./teacherList.vue?vue&type=script&lang=js\"\nexport * from \"./teacherList.vue?vue&type=script&lang=js\"\n\n\n/* normalize component */\nimport normalizer from \"!../../../node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.13_css-loader@6.11.0_webpack@5.97.1__lodash@4.17.21__nkjjb5puplgtn2g67cuu4wxlfy/node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports"],"names":["render","_vm","this","_self","_c","_m","staticRenderFns","_v","component"],"sourceRoot":""}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="test05.mapper.CourseMapper">
<!--suppress Annotator -->
<select id="selectCourse" resultType="test05.pojo.Course">
SELECT N_COURSE_ID AS id,
VC_COURSE_NAME AS name,

View File

@ -4,27 +4,36 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="test05.mapper.ScoreMapper">
<select id="selectScore" resultType="test05.pojo.Score">
SELECT *
SELECT N_STUDENT_ID AS studentId,
N_COURSE_ID AS courseId,
F_SCORE AS score
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);
WHERE #{studentId} in (N_STUDENT_ID, -1)
AND #{courseId} in (N_COURSE_ID, -1)
AND #{score} in (F_SCORE, -1);
</select>
<select id="selectScoreCount" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM t_score
WHERE #{studentId} in (N_STUDENT_ID, -1)
AND #{courseId} in (N_COURSE_ID, -1)
AND #{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}
SET F_SCORE = #{score}
WHERE N_COURSE_ID = #{courseId}
AND N_STUDENT_ID = #{studentId}
</update>
<delete id="deleteScore">
DELETE
FROM t_score
WHERE N_STUDENT_ID = #{N_STUDENT_ID}
AND N_COURSE_ID = #{N_COURSE_ID}
WHERE N_STUDENT_ID = #{studentId}
AND N_COURSE_ID = #{courseId}
</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});
VALUES (#{studentId}, #{courseId}, #{score});
</insert>
</mapper>

View File

@ -2,6 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--suppress ALL -->
<mapper namespace="test05.mapper.StudentMapper">
<select id="selectStudent" resultType="test05.pojo.Student">
SELECT N_STUDENT_ID AS id,

View File

@ -2,6 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--suppress Annotator -->
<mapper namespace="test05.mapper.UserMapper">
<select id="selectUser" resultType="test05.pojo.User">
SELECT N_USER_ID AS id,

View File

@ -1,9 +1,5 @@
package test05;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.junit.jupiter.api.Test;
import org.opentest4j.TestAbortedException;
import org.springframework.beans.factory.annotation.Autowired;
@ -195,7 +191,7 @@ class Test05ApplicationTests {
@Test
public void genJwtTest(){
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("id", "1");
map.put("name", "tom");
String jwt = JwtUtils.getJwt(map);