learn02
This commit is contained in:
parent
5425534b38
commit
63b67ae57f
@ -2,12 +2,19 @@
|
||||
<artifact type="exploded-war" name="learn02:war exploded">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/learn02_war_exploded</output-path>
|
||||
<root id="root">
|
||||
<element id="javaee-facet-resources" facet="learn02/web/Web" />
|
||||
<element id="directory" name="WEB-INF">
|
||||
<element id="directory" name="classes">
|
||||
<element id="module-output" name="learn02" />
|
||||
</element>
|
||||
<element id="directory" name="lib">
|
||||
<element id="library" level="project" name="mysql-connector" />
|
||||
<element id="library" level="project" name="sqlite-jdbc-3.47.0.0" />
|
||||
<element id="library" level="project" name="commons-pool2-2.9.0" />
|
||||
<element id="library" level="project" name="commons-logging-1.3.4" />
|
||||
<element id="library" level="project" name="commons-dbcp2-2.9.0" />
|
||||
</element>
|
||||
</element>
|
||||
<element id="javaee-facet-resources" facet="learn02/web/Web" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
@ -1,20 +0,0 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="exploded-war" name="learn02:war exploded2">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/learn02_war_exploded2</output-path>
|
||||
<root id="root">
|
||||
<element id="directory" name="WEB-INF">
|
||||
<element id="directory" name="classes">
|
||||
<element id="module-output" name="learn02" />
|
||||
</element>
|
||||
<element id="directory" name="lib">
|
||||
<element id="library" level="project" name="mysql-connector" />
|
||||
<element id="library" level="project" name="sqlite-jdbc-3.47.0.0" />
|
||||
<element id="library" level="project" name="commons-pool2-2.9.0" />
|
||||
<element id="library" level="project" name="commons-logging-1.3.4" />
|
||||
<element id="library" level="project" name="commons-dbcp2-2.9.0" />
|
||||
</element>
|
||||
</element>
|
||||
<element id="javaee-facet-resources" facet="learn02/web/Web" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
@ -3,6 +3,14 @@
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<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" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel target="21">
|
||||
<module name="learn03" target="21" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
||||
@ -2,6 +2,10 @@
|
||||
<project version="4">
|
||||
<component name="Encoding" 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$/learn1/web/js/course-edit.js" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/learn1/web/js/index.js" charset="UTF-8" />
|
||||
<file url="PROJECT" charset="GBK" />
|
||||
|
||||
@ -4,6 +4,16 @@
|
||||
<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="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myValues">
|
||||
<value>
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="v-model" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myCustomValuesEnabled" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ThrowablePrintStackTrace" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
||||
20
.idea/jarRepositories.xml
Normal file
20
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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="http://maven.aliyun.com/nexus/content/groups/public/" />
|
||||
</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>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,5 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/learn03/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/learn03-springboot/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" />
|
||||
</component>
|
||||
|
||||
@ -19,5 +19,12 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<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="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" />
|
||||
</component>
|
||||
</module>
|
||||
84
learn02/src/common/DBTool.java
Normal file
84
learn02/src/common/DBTool.java
Normal file
@ -0,0 +1,84 @@
|
||||
package 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);
|
||||
}
|
||||
}
|
||||
25
learn02/src/controller/BaseController.java
Normal file
25
learn02/src/controller/BaseController.java
Normal file
@ -0,0 +1,25 @@
|
||||
package controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class BaseController extends HttpServlet {
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp){
|
||||
resp.addHeader( "Access-Control-Allow-Origin","*");
|
||||
String uri = req.getRequestURI();
|
||||
|
||||
uri = uri.substring(uri.lastIndexOf("/")+1);
|
||||
//使用反射获取方法来执行
|
||||
try {
|
||||
Method method = this.getClass().getDeclaredMethod(uri, HttpServletRequest.class, HttpServletResponse.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(this, req, resp);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
106
learn02/src/controller/CourseController.java
Normal file
106
learn02/src/controller/CourseController.java
Normal file
@ -0,0 +1,106 @@
|
||||
package controller;
|
||||
|
||||
import dao.impl.CourseDBImpl;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import pojo.CourseInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@WebServlet("/courseAction/*")
|
||||
public class CourseController extends BaseController {
|
||||
private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
int page = req.getParameter("page") == null ? 1 : Integer.parseInt(req.getParameter("page"));
|
||||
int pageSize = req.getParameter("pageSize") == null ? 10 : Integer.parseInt(req.getParameter("pageSize"));
|
||||
String keyword = req.getParameter("keyword");
|
||||
int courseType = req.getParameter("courseType").isEmpty() ? 0 : Integer.parseInt(req.getParameter("courseType"));
|
||||
ArrayList<CourseInfo> course_list = new CourseDBImpl().getCourseInfos(page, pageSize, keyword, courseType);
|
||||
StringBuilder data = new StringBuilder();
|
||||
for (CourseInfo course : course_list) {
|
||||
data.append(course.toJSON()).append(",");
|
||||
}
|
||||
if (!data.isEmpty()) {
|
||||
data.setLength(data.length() - 1);
|
||||
}
|
||||
String json = "{\"total\":" + new CourseDBImpl().getAllCourseInfoCount(keyword, courseType) +
|
||||
",\"data\":[" +
|
||||
data +
|
||||
"],\"page\":" +
|
||||
page +
|
||||
",\"pageSize\":" +
|
||||
pageSize +
|
||||
",\"success\":true}";
|
||||
out.print(json);
|
||||
}
|
||||
|
||||
private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
if (req.getParameter("id") == null) {
|
||||
out.println("{\"success\":false}\"}");
|
||||
return;
|
||||
}
|
||||
int id = Integer.parseInt(req.getParameter("id"));
|
||||
CourseInfo course = new CourseDBImpl().getCourseInfoByID(id);
|
||||
if (course == null) {
|
||||
out.println("{\"success\":false}\"}");
|
||||
return;
|
||||
}
|
||||
String name = req.getParameter("name");
|
||||
int type = Integer.parseInt(req.getParameter("type"));
|
||||
float credit = Float.parseFloat(req.getParameter("credit"));
|
||||
int grade = Integer.parseInt(req.getParameter("grade"));
|
||||
int major = Integer.parseInt(req.getParameter("major"));
|
||||
String detail = req.getParameter("detail");
|
||||
course.setName(name);
|
||||
course.setType(type);
|
||||
course.setCredit(credit);
|
||||
course.setGrade(grade);
|
||||
course.setMajor(major);
|
||||
course.setDetail(detail);
|
||||
|
||||
if (new CourseDBImpl().updateCourseInfo(course) >= 1) {
|
||||
out.println("{\"success\":true}");
|
||||
} else {
|
||||
out.println("{\"success\":false}");
|
||||
}
|
||||
}
|
||||
|
||||
private void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
int id = Integer.parseInt(req.getParameter("id"));
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
if (new CourseDBImpl().deleteCourseInfo(id) >= 1) {
|
||||
out.print("{\"success\": true}");
|
||||
} else {
|
||||
out.print("{\"success\": false}");
|
||||
}
|
||||
}
|
||||
|
||||
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
if (req.getParameter("id") == null) {
|
||||
out.println("{\"success\":false}\"}");
|
||||
return;
|
||||
}
|
||||
int id = Integer.parseInt(req.getParameter("id"));
|
||||
CourseInfo course = new CourseInfo();
|
||||
course.setName(req.getParameter("name"));
|
||||
course.setType(Integer.parseInt(req.getParameter("type")));
|
||||
course.setCredit(Float.parseFloat(req.getParameter("credit")));
|
||||
course.setGrade(Integer.parseInt(req.getParameter("grade")));
|
||||
course.setMajor(Integer.parseInt(req.getParameter("major")));
|
||||
course.setDetail(req.getParameter("detail"));
|
||||
if (new CourseDBImpl().addCourseInfo(course) >= 1) {
|
||||
out.println("{\"success\": true}");
|
||||
}else{
|
||||
out.println("{\"success\": false}");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
learn02/src/controller/ScoreController.java
Normal file
13
learn02/src/controller/ScoreController.java
Normal file
@ -0,0 +1,13 @@
|
||||
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 {
|
||||
}
|
||||
22
learn02/src/controller/StudentController.java
Normal file
22
learn02/src/controller/StudentController.java
Normal file
@ -0,0 +1,22 @@
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@WebServlet("/studentAction/*")
|
||||
public class StudentController extends BaseController {
|
||||
private void list(HttpServletRequest req, HttpServletResponse resp) {
|
||||
String path = req.getContextPath();
|
||||
if (req.getSession().getAttribute("user") == null){
|
||||
resp.setStatus(403);
|
||||
return;
|
||||
}
|
||||
ArrayList<TeacherInfo> teachers;
|
||||
}
|
||||
}
|
||||
12
learn02/src/controller/TeacherController.java
Normal file
12
learn02/src/controller/TeacherController.java
Normal file
@ -0,0 +1,12 @@
|
||||
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 {
|
||||
}
|
||||
43
learn02/src/controller/UserController.java
Normal file
43
learn02/src/controller/UserController.java
Normal file
@ -0,0 +1,43 @@
|
||||
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 {
|
||||
protected void login(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
System.out.println("怬");
|
||||
String path = req.getContextPath();
|
||||
if (req.getSession().getAttribute("user") != null){
|
||||
resp.sendRedirect(path+"/home.jsp");
|
||||
}
|
||||
String username = req.getParameter("username");
|
||||
String password = req.getParameter("password");
|
||||
UserInfo user = new UserDBImpl().getUserByName(username);
|
||||
if(user == null) {
|
||||
resp.sendRedirect(path+"/login/login.jsp&loginflag=1");
|
||||
}else if (user.getPass().equals(password)) {
|
||||
req.getSession().setAttribute("user", user);
|
||||
resp.sendRedirect(path+"/home.jsp");
|
||||
}else{
|
||||
resp.sendRedirect(path+"/login/login.jsp&loginflag=2");
|
||||
}
|
||||
}
|
||||
protected void logout(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
System.out.println("×¢Ïú");
|
||||
String username = req.getParameter("username");
|
||||
UserInfo user = (UserInfo)req.getSession().getAttribute("user");
|
||||
if(user != null) {
|
||||
req.getSession().removeAttribute("user");
|
||||
}
|
||||
String path = req.getContextPath();
|
||||
resp.sendRedirect(path+"/login/login.jsp");
|
||||
}
|
||||
}
|
||||
65
learn02/src/dao/CourseDB.java
Normal file
65
learn02/src/dao/CourseDB.java
Normal file
@ -0,0 +1,65 @@
|
||||
package dao;
|
||||
|
||||
import 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);
|
||||
}
|
||||
15
learn02/src/dao/ScoreDB.java
Normal file
15
learn02/src/dao/ScoreDB.java
Normal file
@ -0,0 +1,15 @@
|
||||
package dao;
|
||||
|
||||
import 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);
|
||||
}
|
||||
15
learn02/src/dao/StudentDB.java
Normal file
15
learn02/src/dao/StudentDB.java
Normal file
@ -0,0 +1,15 @@
|
||||
package dao;
|
||||
|
||||
import 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);
|
||||
}
|
||||
14
learn02/src/dao/TeacherDB.java
Normal file
14
learn02/src/dao/TeacherDB.java
Normal file
@ -0,0 +1,14 @@
|
||||
package dao;
|
||||
|
||||
import 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);
|
||||
}
|
||||
11
learn02/src/dao/UserDB.java
Normal file
11
learn02/src/dao/UserDB.java
Normal file
@ -0,0 +1,11 @@
|
||||
package dao;
|
||||
|
||||
import 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);
|
||||
}
|
||||
177
learn02/src/dao/impl/CourseDBImpl.java
Normal file
177
learn02/src/dao/impl/CourseDBImpl.java
Normal file
@ -0,0 +1,177 @@
|
||||
package dao.impl;
|
||||
|
||||
import common.DBTool;
|
||||
import dao.CourseDB;
|
||||
import pojo.CourseInfo;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
60
learn02/src/dao/impl/TeacherDBImpl.java
Normal file
60
learn02/src/dao/impl/TeacherDBImpl.java
Normal file
@ -0,0 +1,60 @@
|
||||
package dao.impl;
|
||||
|
||||
import common.DBTool;
|
||||
import dao.TeacherDB;
|
||||
import 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;
|
||||
}
|
||||
}
|
||||
103
learn02/src/dao/impl/UserDBImpl.java
Normal file
103
learn02/src/dao/impl/UserDBImpl.java
Normal file
@ -0,0 +1,103 @@
|
||||
package dao.impl;
|
||||
|
||||
import common.DBTool;
|
||||
import dao.UserDB;
|
||||
import 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;
|
||||
}
|
||||
}
|
||||
41
learn02/src/database.properties
Normal file
41
learn02/src/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
|
||||
17
learn02/src/filters/GlobalFilter.java
Normal file
17
learn02/src/filters/GlobalFilter.java
Normal file
@ -0,0 +1,17 @@
|
||||
package filters;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebFilter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class GlobalFilter implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
}
|
||||
33
learn02/src/pojo/CourseInfo.java
Normal file
33
learn02/src/pojo/CourseInfo.java
Normal file
@ -0,0 +1,33 @@
|
||||
package pojo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class CourseInfo {
|
||||
private int id;
|
||||
private String name;
|
||||
private int type;
|
||||
private float credit;
|
||||
private int grade;
|
||||
private int major;
|
||||
private String detail;
|
||||
|
||||
public String toJSON(){
|
||||
String json="{";
|
||||
json += "\"id\":"+id+",";
|
||||
json += "\"name\":\""+name+"\",";
|
||||
json += "\"type\":"+type+",";
|
||||
json += "\"credit\":"+credit+",";
|
||||
json += "\"grade\":"+grade+",";
|
||||
json += "\"major\":"+major+",";
|
||||
json += "\"detail\":\""+detail+"\"";
|
||||
json += "}";
|
||||
return json;
|
||||
}
|
||||
}
|
||||
25
learn02/src/pojo/ScoreInfo.java
Normal file
25
learn02/src/pojo/ScoreInfo.java
Normal file
@ -0,0 +1,25 @@
|
||||
package pojo;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class ScoreInfo {
|
||||
private int studentId;
|
||||
private int courseId;
|
||||
private float score;
|
||||
|
||||
public String toJSON(){
|
||||
String json = "{";
|
||||
json += "\"studentId\":" + studentId + ",";
|
||||
json += "\"courseId\":" + courseId + ",";
|
||||
json += "\"score\":" + score + ",";
|
||||
return json + "}";
|
||||
}
|
||||
}
|
||||
32
learn02/src/pojo/StudentInfo.java
Normal file
32
learn02/src/pojo/StudentInfo.java
Normal file
@ -0,0 +1,32 @@
|
||||
package pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class StudentInfo {
|
||||
private int id;
|
||||
private String code;
|
||||
private String name;
|
||||
private int sex;
|
||||
private int grade;
|
||||
private String major;
|
||||
private String detail;
|
||||
|
||||
public String toJSON(){
|
||||
String json = "{";
|
||||
json += "\"id\":" + id + ",";
|
||||
json += "\"code\":" + code + ",";
|
||||
json += "\"name\":" + name + ",";
|
||||
json += "\"sex\":" + sex + ",";
|
||||
json += "\"grade\":" + grade + ",";
|
||||
json += "\"major\":" + major + ",";
|
||||
json += "\"detail\":" + detail + ",";
|
||||
return json + "}";
|
||||
}
|
||||
}
|
||||
30
learn02/src/pojo/TeacherInfo.java
Normal file
30
learn02/src/pojo/TeacherInfo.java
Normal file
@ -0,0 +1,30 @@
|
||||
package pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class TeacherInfo {
|
||||
private int id;
|
||||
private String name;
|
||||
private int sex;
|
||||
private String brith;
|
||||
private int educ;
|
||||
private int title;
|
||||
|
||||
public String toJSON(){
|
||||
String json = "{";
|
||||
json += "\"id\":" + id + ",";
|
||||
json += "\"name\":\"" + name + "\",";
|
||||
json += "\"sex\":" + sex + ",";
|
||||
json += "\"brith\":\"" + brith + "\",";
|
||||
json += "\"educ\":" + educ + ",";
|
||||
json += "\"title\":" + title + ",";
|
||||
return json;
|
||||
}
|
||||
}
|
||||
25
learn02/src/pojo/UserInfo.java
Normal file
25
learn02/src/pojo/UserInfo.java
Normal file
@ -0,0 +1,25 @@
|
||||
package pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@ToString
|
||||
public class UserInfo {
|
||||
private int id;
|
||||
private String name;
|
||||
private String pass;
|
||||
|
||||
public String toJSON(){
|
||||
String json = "{";
|
||||
json += "\"id\":" + id + ",";
|
||||
json += "\"name\":\"" + name + "\",";
|
||||
json += "\"pass\":\"" + pass;
|
||||
json += "}";
|
||||
return json;
|
||||
}
|
||||
}
|
||||
4
learn02/src/service/CourseService.java
Normal file
4
learn02/src/service/CourseService.java
Normal file
@ -0,0 +1,4 @@
|
||||
package service;
|
||||
|
||||
public interface CourseService {
|
||||
}
|
||||
4
learn02/src/service/UserService.java
Normal file
4
learn02/src/service/UserService.java
Normal file
@ -0,0 +1,4 @@
|
||||
package service;
|
||||
|
||||
public interface UserService {
|
||||
}
|
||||
15
learn02/src/test/TestDao.java
Normal file
15
learn02/src/test/TestDao.java
Normal file
@ -0,0 +1,15 @@
|
||||
package test;
|
||||
|
||||
import dao.CourseDB;
|
||||
import dao.impl.CourseDBImpl;
|
||||
import pojo.CourseInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TestDao {
|
||||
public static void main(String[] args) {
|
||||
CourseDB courseDB = new CourseDBImpl();
|
||||
ArrayList<CourseInfo> courseInfos = courseDB.getAllCourseInfo();
|
||||
System.out.println(courseInfos);
|
||||
}
|
||||
}
|
||||
63
learn02/web/course/course.jsp
Normal file
63
learn02/web/course/course.jsp
Normal file
@ -0,0 +1,63 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: 25589
|
||||
Date: 2024/11/21
|
||||
Time: 下午5:00
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>课程信息列表</title>
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/course.css">
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/common.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<table id="course-list">
|
||||
</table>
|
||||
<div class="course-editor"></div>
|
||||
<br><br><br><br><br>
|
||||
<table id="course-list-vue">
|
||||
<tr class="tr-head">
|
||||
<td class="tr-head" colspan="6">课程信息列表</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>名称</td>
|
||||
<td>性质</td>
|
||||
<td>学分</td>
|
||||
<td>开设年级</td>
|
||||
<td>开设专业</td>
|
||||
</tr>
|
||||
<tr v-for="course in courses">
|
||||
<td>{{course.name}}</td>
|
||||
<td>{{types[course.type]}}</td>
|
||||
<td>{{course.credit}}</td>
|
||||
<td>{{course.grade}}</td>
|
||||
<td>{{majors[course.major]}}</td>
|
||||
<td>
|
||||
<a class="blue" @click="edit()">编辑</a>
|
||||
<a class="red" :href="path+'/courseAction/delete?id='+course.id">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<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>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<script src="${pageContext.request.contextPath}/js/vue.min.js"></script>
|
||||
<script>
|
||||
let path = "${pageContext.request.contextPath}";
|
||||
</script>
|
||||
<script src="${pageContext.request.contextPath}/js/jquery-3.7.1.min.js"></script>
|
||||
<script src="${pageContext.request.contextPath}/js/course-edit.js"></script>
|
||||
</html>
|
||||
87
learn02/web/course/course_edit.jsp
Normal file
87
learn02/web/course/course_edit.jsp
Normal file
@ -0,0 +1,87 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<div class="container">
|
||||
<form class="course-edit">
|
||||
<input type="hidden" name="id" id="id-input" value="-1">
|
||||
<table class="input-form">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="td_header" colspan="3">课程信息录入,<span class="star">*</span>代表必填</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr>
|
||||
<td><label for="name-input">名称</label></td>
|
||||
<td>
|
||||
<input name="name" type="text" id="name-input">
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>5~20位字符
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="type-input">性质</label></td>
|
||||
<td>
|
||||
<select name="type" id="type-input">
|
||||
<option value="1">公共基础必修课</option>
|
||||
<option value="2">公共选修课</option>
|
||||
<option value="3">学科基础课</option>
|
||||
<option value="4">专业必修课</option>
|
||||
<option value="5">专业选修课</option>
|
||||
<option value="6">集中性实践教学环节</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="credit-input">学分</label></td>
|
||||
<td>
|
||||
<input name="credit" type="number" id="credit-input">
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>数值
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="grade-input">年份</label></td>
|
||||
<td>
|
||||
<input name="grade" type="text" id="grade-input">
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>4位数年份
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>开设专业</td>
|
||||
<td>
|
||||
<input name="major" value="1" type="radio" id="major-input-1">
|
||||
<label for="major-input-1">软件工程</label>
|
||||
<input name="major" value="2" type="radio" id="major-input-2">
|
||||
<label for="major-input-2">空间信息</label>
|
||||
<input name="major" value="3" type="radio" id="major-input-3">
|
||||
<label for="major-input-3">大数据</label>
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="detail-input">备注</label></td>
|
||||
<td>
|
||||
<textarea rows="5" name="detail" id="detail-input"></textarea>
|
||||
</td>
|
||||
<td>
|
||||
200个字符以内
|
||||
</td>
|
||||
</tr>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<input type="submit" class="button">
|
||||
<button onclick="closeEdit()">关闭编辑</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
82
learn02/web/course/tmp
Normal file
82
learn02/web/course/tmp
Normal file
@ -0,0 +1,82 @@
|
||||
<form action="" method="post" class="course-edit">
|
||||
<table class="input-form ">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="td_header" colspan="3">课程信息录入,<span class="star">*</span></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr>
|
||||
<td><label for="name-input">名称</label></td>
|
||||
<td>
|
||||
<input name="name" type="text" id="name-input">
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>5~20位字符
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="type-input">性质</label></td>
|
||||
<td>
|
||||
<select name="type" id="type-input">
|
||||
<option value="1">公共基础必修课</option>
|
||||
<option value="2">公共选修课</option>
|
||||
<option value="3">学科基础课</option>
|
||||
<option value="4">专业必修课</option>
|
||||
<option value="5">专业选修课</option>
|
||||
<option value="6">集中性实践教学环节</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="score-input">学分</label></td>
|
||||
<td>
|
||||
<input name="credit" type="number" id="score-input">
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>数值
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="year-input">年份</label></td>
|
||||
<td>
|
||||
<input name="grade" type="text" id="year-input">
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>4位数年份
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>开设专业</td>
|
||||
<td>
|
||||
<input name="major" value="1" type="radio" id="major-input-1">
|
||||
<label for="major-input-1">软件工程</label>
|
||||
<input name="major" value="2" type="radio" id="major-input-2">
|
||||
<label for="major-input-2">空间信息</label>
|
||||
<input name="major" value="3" type="radio" id="major-input-3">
|
||||
<label for="major-input-3">大数据</label>
|
||||
</td>
|
||||
<td>
|
||||
<span class="star">*</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="note-input">备注</label></td>
|
||||
<td>
|
||||
<textarea rows="5" name="detail" id="note-input"></textarea>
|
||||
</td>
|
||||
<td>
|
||||
200个字符以内
|
||||
</td>
|
||||
</tr>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<input type="submit">
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</form>
|
||||
62
learn02/web/css/common.css
Normal file
62
learn02/web/css/common.css
Normal file
@ -0,0 +1,62 @@
|
||||
.container{
|
||||
background-color: white;
|
||||
position: relative;
|
||||
margin: auto;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
body{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
a{
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
table{
|
||||
width:100%;
|
||||
border-spacing: 0;
|
||||
background-color: #c4c4c4;
|
||||
}
|
||||
|
||||
tr{
|
||||
height: 25px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.tr-head{
|
||||
background-color: #2bf;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
tr:nth-child(odd){
|
||||
background:#F4F4F4;
|
||||
}
|
||||
|
||||
button,.button{
|
||||
background-color: #39f;
|
||||
border: #39f solid 1px;
|
||||
border-radius: 5px;
|
||||
color: white;
|
||||
padding: 5px;
|
||||
line-height: 100%;
|
||||
text-align: center;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.red {
|
||||
COLOR: red
|
||||
}
|
||||
|
||||
.blue {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.underline {
|
||||
BORDER-BOTTOM: #c4c4c4 1pt solid;
|
||||
BORDER-LEFT: #c4c4c4;
|
||||
BORDER-RIGHT: #c4c4c4;
|
||||
BORDER-TOP: #c4c4c4;
|
||||
}
|
||||
8
learn02/web/css/course.css
Normal file
8
learn02/web/css/course.css
Normal file
@ -0,0 +1,8 @@
|
||||
.input-form{
|
||||
border: black solid 1px;
|
||||
margin: auto;
|
||||
td{
|
||||
border: black solid 1px;
|
||||
}
|
||||
}
|
||||
|
||||
41
learn02/web/css/index.css
Normal file
41
learn02/web/css/index.css
Normal file
@ -0,0 +1,41 @@
|
||||
.nav-area{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background-color: #2bf;
|
||||
height: 95%;
|
||||
width: 20%;
|
||||
margin: 0;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.nav-list{
|
||||
padding-left: 0;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.nav-item{
|
||||
list-style: none;
|
||||
line-height: 100%;
|
||||
text-align: center;
|
||||
font-size: 19px;
|
||||
margin: 5px 0;
|
||||
padding: 3px 0;
|
||||
color: white;
|
||||
a{
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.content{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
background-color: #eee;
|
||||
height: 95%;
|
||||
width: 79%;
|
||||
margin: 0;
|
||||
padding: 5px;
|
||||
}
|
||||
15
learn02/web/css/login.css
Normal file
15
learn02/web/css/login.css
Normal file
@ -0,0 +1,15 @@
|
||||
.login-card{
|
||||
width: 80%;
|
||||
border: #eee solid 2px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
input{
|
||||
width: 75%;
|
||||
height: 35px;
|
||||
border: grey solid 2px;
|
||||
border-radius: 5px;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
line-height: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
16
learn02/web/error.jsp
Normal file
16
learn02/web/error.jsp
Normal file
@ -0,0 +1,16 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>学生星系管理系统</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>错误!</h1>
|
||||
<h2>错误代码:<%=(request.getParameter("err-code") == null?"未知错误":request.getParameter("err-code"))%></h2>
|
||||
<hr>
|
||||
<p><%=(request.getParameter("msg") == null?"":request.getParameter("msg"))%></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
44
learn02/web/home.jsp
Normal file
44
learn02/web/home.jsp
Normal file
@ -0,0 +1,44 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: 25589
|
||||
Date: 2024/12/3
|
||||
Time: 上午12:17
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>主页</title>
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/common.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>学生信息管理系统</h1>
|
||||
|
||||
<%
|
||||
if(session.getAttribute("user")==null){
|
||||
out.println("<a href=\""+request.getContextPath()+"/login/login.jsp\"><button>登录</button></a>");
|
||||
}else{
|
||||
out.println("<a href=\""+request.getContextPath()+"/userAction/logout\"><button>注销</button></a>");
|
||||
}
|
||||
%>
|
||||
<div id="app">
|
||||
<label>
|
||||
<input type="text" v-model="message">
|
||||
</label>
|
||||
{{ message }}
|
||||
<h3 v-if="message === 'Hello vue'">这是Hello vue</h3>
|
||||
<h3 v-else>这不是Hello vue</h3>
|
||||
</div>
|
||||
</div>
|
||||
<script src="${pageContext.request.contextPath}/js/vue.min.js"></script>
|
||||
<script>
|
||||
new Vue({
|
||||
el: "#app",
|
||||
data: {
|
||||
message: "Hello vue"
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,16 +1,25 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: awinx
|
||||
Date: 2024/12/5
|
||||
Time: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>1:31
|
||||
User: 25589
|
||||
Date: 2024/11/28
|
||||
Time: 下午1:20
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8"%>
|
||||
<html>
|
||||
<head>
|
||||
<title>$Title$</title>
|
||||
<title>学生信息管理系统</title>
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/index.css">
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/common.css">
|
||||
</head>
|
||||
<body>
|
||||
$END$
|
||||
<div class="nav-area">
|
||||
<ul class="nav-list">
|
||||
<li class="nav-item"><a href="${pageContext.request.contextPath}/home.jsp" target="content">欢迎页</a></li>
|
||||
<li class="nav-item"><a href="${pageContext.request.contextPath}/course/course.jsp" target="content">课程列表</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<iframe src="${pageContext.request.contextPath}/home.jsp" class="content" name="content" height="100%" width="100%"></iframe>
|
||||
</body>
|
||||
<script src="${pageContext.request.contextPath}/js/index.js"></script>
|
||||
</html>
|
||||
|
||||
145
learn02/web/js/course-edit.js
Normal file
145
learn02/web/js/course-edit.js
Normal file
@ -0,0 +1,145 @@
|
||||
const types = ['', '公共基础必修课', '公共选修课', '学科基础课', '专业必修课', '专业选修课', '集中性实践教学环节']
|
||||
const majors = ['', '软件工程', '空间信息', '大数据'];
|
||||
let courses;
|
||||
|
||||
new Vue({
|
||||
el: "#course-list-vue",
|
||||
data: {
|
||||
courses: [],
|
||||
types: types,
|
||||
majors: majors,
|
||||
path: path
|
||||
},
|
||||
mounted(){
|
||||
$.ajax({
|
||||
url: path+"/courseAction/list",
|
||||
method: "GET",
|
||||
success: (data, status, xhr) =>{
|
||||
this.courses = data;
|
||||
}
|
||||
});
|
||||
},
|
||||
method: {
|
||||
edit: ()=>{}
|
||||
}
|
||||
});
|
||||
|
||||
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";
|
||||
// }
|
||||
// });
|
||||
}
|
||||
$(document).ready(getCourses);
|
||||
|
||||
function editCourse(i){
|
||||
$(".course-editor").load(path+"/course/course_edit.jsp", ()=>{
|
||||
const form = document.querySelector('.course-edit');
|
||||
form.action = path+"/courseAction/update";
|
||||
form.method = "POST";
|
||||
const idInput = document.getElementById('id-input');
|
||||
idInput.value = courses[i].id;
|
||||
const nameInput = document.getElementById('name-input');
|
||||
nameInput.value = courses[i].name;
|
||||
const typeInput = document.getElementById('type-input');
|
||||
typeInput.value = courses[i].type;
|
||||
const creditInput = document.getElementById('credit-input');
|
||||
creditInput.value = courses[i].credit;
|
||||
const yearInput = document.getElementById('grade-input');
|
||||
yearInput.value = courses[i].grade;
|
||||
const majorInputs = form.querySelectorAll('input[name="major"]');
|
||||
majorInputs.forEach((input) => {
|
||||
if (parseInt(input.value) === courses[i].major) {
|
||||
input.checked = true;
|
||||
}
|
||||
});
|
||||
|
||||
const noteInput = form.querySelector('#detail-input');
|
||||
noteInput.value = courses[i].detail;
|
||||
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
const gradeInput = document.getElementById('grade-input');
|
||||
if (!/^20\d{2}$/.test(gradeInput.value)) {
|
||||
alert('请输入合法的四位年份');
|
||||
return;
|
||||
}
|
||||
|
||||
const nameInput = document.getElementById('name-input');
|
||||
console.log(nameInput.value.length)
|
||||
console.log(nameInput.value)
|
||||
if (nameInput.value.length < 5 || nameInput.value.length > 20){
|
||||
alert('请输入5~20位字符');
|
||||
return;
|
||||
}
|
||||
const detailInput = document.getElementById('detail-input');
|
||||
if (detailInput.value.length > 200){
|
||||
alert('备注超长');
|
||||
return;
|
||||
}
|
||||
$(".course-edit").submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function addCourse(){
|
||||
$(".course-editor").load(path+"/courseAction/course_edit.jsp", ()=>{
|
||||
const form = document.querySelector('.course-edit');
|
||||
form.action = path+"/course/add";
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
const gradeInput = document.getElementById('grade-input');
|
||||
if (!/^20\d{2}$/.test(gradeInput.value)) {
|
||||
alert('请输入合法的四位年份');
|
||||
return;
|
||||
}
|
||||
|
||||
const nameInput = document.getElementById('name-input');
|
||||
console.log(nameInput.value.length)
|
||||
console.log(nameInput.value)
|
||||
if (nameInput.value.length < 5 || nameInput.value.length > 20){
|
||||
alert('请输入5~20位字符');
|
||||
return;
|
||||
}
|
||||
const detailInput = document.getElementById('detail-input');
|
||||
if (detailInput.value.length > 200){
|
||||
alert('备注超长');
|
||||
return;
|
||||
}
|
||||
$(".course-edit").submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeEdit(){
|
||||
const editor = document.querySelector('.course-editor');
|
||||
editor.innerHTML = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
0
learn02/web/js/index.js
Normal file
0
learn02/web/js/index.js
Normal file
2
learn02/web/js/jquery-3.7.1.min.js
vendored
Normal file
2
learn02/web/js/jquery-3.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
11
learn02/web/js/vue.min.js
vendored
Normal file
11
learn02/web/js/vue.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
41
learn02/web/login/login.jsp
Normal file
41
learn02/web/login/login.jsp
Normal file
@ -0,0 +1,41 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: 25589
|
||||
Date: 2024/12/1
|
||||
Time: 下午11:58
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8"%>
|
||||
<html>
|
||||
<head>
|
||||
<title>登录</title>
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/login.css">
|
||||
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/common.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-card">
|
||||
<h1>登录</h1>
|
||||
<form action="${pageContext.request.contextPath}/userAction/login" method="POST">
|
||||
<label for="username-input">用户名</label><br>
|
||||
<input type="text" name="username" id="username-input"><br>
|
||||
<label for="password-input">密码</label><br>
|
||||
<input type="password" name="password" id="password-input">
|
||||
<input type="submit" class="button" value="登录">
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
<%
|
||||
String loginFlag=request.getParameter("loginflag");
|
||||
String username=request.getParameter("username");
|
||||
if(loginFlag==null){ //无登录失败标识,是正常访问登录页面
|
||||
loginFlag="";
|
||||
}
|
||||
if(loginFlag.equals("1")){
|
||||
out.println("alert('用户【"+username+"】不存在!')");
|
||||
}else if(loginFlag.equals("2")){
|
||||
out.println("alert('密码错误!')");
|
||||
}
|
||||
%>
|
||||
</script>
|
||||
</html>
|
||||
2
learn03-springboot/.gitattributes
vendored
Normal file
2
learn03-springboot/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
33
learn03-springboot/.gitignore
vendored
Normal file
33
learn03-springboot/.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/
|
||||
19
learn03-springboot/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
learn03-springboot/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# 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
Normal file
259
learn03-springboot/mvnw
vendored
Normal file
@ -0,0 +1,259 @@
|
||||
#!/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
Normal file
149
learn03-springboot/mvnw.cmd
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
<# : 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"
|
||||
85
learn03-springboot/pom.xml
Normal file
85
learn03-springboot/pom.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<?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>learn03-springboot</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>learn03-springboot</name>
|
||||
<description>learn03-springboot</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.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,13 @@
|
||||
package top.awin_x.learn;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Learn03SpringbootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Learn03SpringbootApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package top.awin_x.learn;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(Learn03SpringbootApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
spring.application.name=learn03-springboot
|
||||
@ -0,0 +1,13 @@
|
||||
package top.awin_x.learn;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Learn03SpringbootApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class CourseDB {
|
||||
}
|
||||
|
||||
public static void insertCourse(CourseInfo course){
|
||||
try{
|
||||
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, course.getName());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user