This commit is contained in:
Chenx221 2023-06-05 19:49:07 +08:00
parent 465e2bb536
commit e80af33075
32 changed files with 557 additions and 363 deletions

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WebContextManager">
<option name="state">
<map>
<entry key="file://$PROJECT_DIR$/web/login.jsp" value="file://$PROJECT_DIR$/web" />
</map>
</option>
</component>
</project>

View File

@ -30,7 +30,21 @@
<artifactId>spring-webmvc</artifactId> <artifactId>spring-webmvc</artifactId>
<version>5.3.27</version> <version>5.3.27</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.3.27</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.27</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.27</version>
</dependency>
<!-- MyBatis --> <!-- MyBatis -->
<dependency> <dependency>
<groupId>org.mybatis</groupId> <groupId>org.mybatis</groupId>
@ -77,9 +91,63 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-dbcp</groupId> <groupId>com.alibaba</groupId>
<artifactId>commons-dbcp</artifactId> <artifactId>druid</artifactId>
<version>1.4</version> <version>1.1.20</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.3</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!--jackson坐标-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<!-- 日志工具包 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.10.0</version>
</dependency>
<!--日志核心包-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.10.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,19 @@
package cyou.chenx221.config;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
@WebFilter(filterName = "encodingFilter",urlPatterns = "/*")
public class EncodingFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) {}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletRequest.setCharacterEncoding("UTF-8");
servletResponse.setCharacterEncoding("UTF-8");
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void destroy() {}
}

View File

@ -0,0 +1,46 @@
package cyou.chenx221.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import javax.sql.DataSource;
/*
等同于
<context:property-placeholder location="classpath*:jdbc.properties"/>
*/
@PropertySource("classpath:jdbc.properties")
public class JdbcConfig {
/*
使用注入的形式读取properties文件中的属性值
等同于<property name="*******" value="${jdbc.driver}"/>
*/
@Value("${jdbc.driverClassName}")
private String driver;
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String userName;
@Value("${jdbc.password}")
private String password;
/*定义dataSource的bean
等同于<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
*/
@Bean("dataSource")
public DataSource getDataSource(){
//创建对象
DruidDataSource ds = new DruidDataSource();
/*
等同于set属性注入<property name="driverClassName" value="driver"/>
*/
ds.setDriverClassName(driver);
ds.setUrl(url);
ds.setUsername(userName);
ds.setPassword(password);
return ds;
}
}

View File

@ -0,0 +1,36 @@
package cyou.chenx221.config;
import com.github.pagehelper.PageInterceptor;
import org.apache.ibatis.plugin.Interceptor;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import javax.sql.DataSource;
import java.util.Properties;
public class MyBatisConfig {
@Bean
public PageInterceptor getPageInterceptor() {
PageInterceptor pageIntercptor = new PageInterceptor();
Properties properties = new Properties();
properties.setProperty("value", "true");
pageIntercptor.setProperties(properties);
return pageIntercptor;
}
@Bean
public SqlSessionFactoryBean getSqlSessionFactoryBean(@Autowired DataSource dataSource,@Autowired PageInterceptor pageIntercptor){
SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
ssfb.setDataSource(dataSource);
Interceptor[] plugins={pageIntercptor};
ssfb.setPlugins(plugins);
return ssfb;
}
@Bean
public MapperScannerConfigurer getMapperScannerConfigurer(){
MapperScannerConfigurer msc = new MapperScannerConfigurer();
msc.setBasePackage("cyou.chenx221.mapper");
return msc;
}
}

View File

@ -0,0 +1,23 @@
package cyou.chenx221.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServletContainersInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
/*
加载Spring配置类中的信息
初始化Spring容器
*/
protected Class<?>[] getRootConfigClasses() {
return new Class[]{SpringConfig.class};
}
/*
加载Spring MVC配置类中的信息
初始化Spring MVC容器
*/
protected Class<?>[] getServletConfigClasses() {
return new Class[]{SpringMvcConfig.class};
}
//配置DispatcherServlet的映射路径
protected String[] getServletMappings() {
return new String[]{"/"};
}
}

View File

@ -0,0 +1,34 @@
package cyou.chenx221.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
@Configuration
@Import({MyBatisConfig.class,JdbcConfig.class})
@ComponentScan( "cyou.chenx221.service")
@EnableTransactionManagement
public class SpringConfig {
@Bean("transactionManager")
public DataSourceTransactionManager getDataSourceTxManager(@Autowired DataSource dataSource){
DataSourceTransactionManager dtm = new DataSourceTransactionManager();
dtm.setDataSource(dataSource);
return dtm;
}
}

View File

@ -0,0 +1,43 @@
package cyou.chenx221.config;
import cyou.chenx221.interceptor.ResourcesInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import java.util.List;
@Configuration
@PropertySource("classpath:ignoreUrl.properties")
@ComponentScan({"cyou.chenx221.controller"})
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {
@Value("#{'${ignoreUrl}'.split(',')}")
private List<String> ignoreUrl;
@Bean
public ResourcesInterceptor resourcesInterceptor(){
return new ResourcesInterceptor(ignoreUrl);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor( resourcesInterceptor()).addPathPatterns("/**").excludePathPatterns("/css/**","/js/**","/img/**");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/admin/",".jsp");
}
}

View File

@ -9,13 +9,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@Controller @Controller
@RequestMapping("/admin")
public class AdminController { public class AdminController {
@Autowired @Autowired
private AdminService adminService; private AdminService adminService;
@PostMapping("/login") @RequestMapping("/login")
public String login(@RequestParam("username") String username, public String login(@RequestParam("username") String username,
@RequestParam("password") String password) { @RequestParam("password") String password) {

View File

@ -1,26 +0,0 @@
package cyou.chenx221.dao;
import cyou.chenx221.modal.Admin;
import java.util.List;
public interface AdminDao {
//将给定的管理员对象添加到数据库中
void addAdmin(Admin admin);
//更新数据库中与给定管理员对象对应的记录
void updateAdmin(Admin admin);
//根据管理员ID从数据库中删除对应的记录
void deleteAdmin(int adminId);
//根据管理员ID从数据库中获取对应的管理员对象
Admin getAdminById(int adminId);
//根据管理员用户名从数据库中获取对应的管理员对象
Admin getAdminByUsername(String username);
//获取数据库中所有的管理员对象并以列表形式返回
List<Admin> getAllAdmins();
}

View File

@ -1,48 +0,0 @@
package cyou.chenx221.dao.impl;
import cyou.chenx221.dao.AdminDao;
import cyou.chenx221.modal.Admin;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class AdminDaoImpl implements AdminDao {
private final SqlSession sqlSession;
public AdminDaoImpl(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}
@Override
public void addAdmin(Admin admin) {
sqlSession.insert("AdminMapper.addAdmin", admin);
}
@Override
public void updateAdmin(Admin admin) {
sqlSession.update("AdminMapper.updateAdmin", admin);
}
@Override
public void deleteAdmin(int adminId) {
sqlSession.delete("AdminMapper.deleteAdmin", adminId);
}
@Override
public Admin getAdminById(int adminId) {
return sqlSession.selectOne("AdminMapper.getAdminById", adminId);
}
@Override
public Admin getAdminByUsername(String username) {
return sqlSession.selectOne("AdminMapper.getAdminByUsername", username);
}
@Override
public List<Admin> getAllAdmins() {
return sqlSession.selectList("AdminMapper.getAllAdmins");
}
}

View File

@ -1,52 +0,0 @@
package cyou.chenx221.dao.impl;
import cyou.chenx221.dao.ScoreDao;
import cyou.chenx221.modal.Score;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class ScoreDaoImpl implements ScoreDao {
private final SqlSession sqlSession;
public ScoreDaoImpl(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}
@Override
public void addScore(Score score) {
sqlSession.insert("ScoreMapper.addScore", score);
}
@Override
public void updateScore(Score score) {
sqlSession.update("ScoreMapper.updateScore", score);
}
@Override
public void deleteScore(int scoreId) {
sqlSession.delete("ScoreMapper.deleteScore", scoreId);
}
@Override
public Score getScoreById(int scoreId) {
return sqlSession.selectOne("ScoreMapper.getScoreById", scoreId);
}
@Override
public List<Score> getScoresByStudentId(int studentId) {
return sqlSession.selectList("ScoreMapper.getScoresByStudentId", studentId);
}
@Override
public List<Score> getScoresByCourse(String course) {
return sqlSession.selectList("ScoreMapper.getScoresByCourse", course);
}
@Override
public List<Score> getAllScores() {
return sqlSession.selectList("ScoreMapper.getAllScores");
}
}

View File

@ -1,42 +0,0 @@
package cyou.chenx221.dao.impl;
import cyou.chenx221.dao.StudentDao;
import cyou.chenx221.modal.Student;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class StudentDaoImpl implements StudentDao {
private final SqlSession sqlSession;
public StudentDaoImpl(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}
@Override
public void addStudent(Student student) {
sqlSession.insert("StudentMapper.addStudent", student);
}
@Override
public void updateStudent(Student student) {
sqlSession.update("StudentMapper.updateStudent", student);
}
@Override
public void deleteStudent(int studentId) {
sqlSession.delete("StudentMapper.deleteStudent", studentId);
}
@Override
public Student getStudentById(int studentId) {
return sqlSession.selectOne("StudentMapper.getStudentById", studentId);
}
@Override
public List<Student> getAllStudents() {
return sqlSession.selectList("StudentMapper.getAllStudents");
}
}

View File

@ -0,0 +1,49 @@
package cyou.chenx221.interceptor;
import cyou.chenx221.modal.Admin;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 资源拦截器
*/
public class ResourcesInterceptor extends HandlerInterceptorAdapter {
//任意角色都能访问的路径
private List<String> ignoreUrl;
public ResourcesInterceptor(List<String> ignoreUrl) {
this.ignoreUrl = ignoreUrl;
}
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws
Exception {
Admin admin = (Admin) request.getSession().getAttribute("USER_SESSION");
//获取请求的路径
String uri = request.getRequestURI();
//如果用户是已登录状态判断访问的资源是否有权限
// if (admin != null) {
// //如果是管理员放行
// if ("ADMIN".equals(admin.getRole())) {
// return true;
// }
// //如果是普通用户
// else if (!"ADMIN".equals(user.getRole())) {
// for (String url : ignoreUrl) {
// //访问的资源不是管理员权限的资源放行
// if (uri.indexOf(url) >= 0) {
// return true;
// }
// }
// }
// }
//对用户登录的相关请求放行
if (uri.indexOf("login") >= 0) {
return true;
}
//其他情况都直接跳转到登录页面
request.setAttribute("msg", "您还没有登录,请先登录!");
request.getRequestDispatcher("/admin/login.jsp").forward(request, response);
return false;
}
}

View File

@ -0,0 +1,17 @@
package cyou.chenx221.mapper;
import cyou.chenx221.modal.Admin;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
public interface AdminMapper {
@Select("select * from user where username=#{username} AND password=#{password}")
@Results(id = "userMap",value = {
@Result(id = true,column = "user_id",property = "id"),
@Result(column = "username",property = "name"),
@Result(column = "password",property = "password"),
@Result(column = "name",property = "name"),
})
Admin login(Admin admin);
}

View File

@ -1,6 +1,8 @@
package cyou.chenx221.modal; package cyou.chenx221.modal;
public class Admin { import java.io.Serializable;
public class Admin implements Serializable {
// 管理员id 管理员姓名 管理员用户名 管理员密码 // 管理员id 管理员姓名 管理员用户名 管理员密码
private int id; private int id;
private String name; private String name;

View File

@ -1,6 +1,8 @@
package cyou.chenx221.modal; package cyou.chenx221.modal;
public class Score { import java.io.Serializable;
public class Score implements Serializable {
// 成绩id 学生id 课程 成绩 // 成绩id 学生id 课程 成绩
private int id; private int id;
private int studentId; private int studentId;

View File

@ -1,6 +1,8 @@
package cyou.chenx221.modal; package cyou.chenx221.modal;
public class Student { import java.io.Serializable;
public class Student implements Serializable {
// 学号 姓名 年龄 性别 // 学号 姓名 年龄 性别
private String id; private String id;
private String name; private String name;

View File

@ -2,20 +2,6 @@ package cyou.chenx221.service;
import cyou.chenx221.modal.Admin; import cyou.chenx221.modal.Admin;
import java.util.List;
public interface AdminService { public interface AdminService {
void addAdmin(Admin admin); Admin login(Admin admin);
void updateAdmin(Admin admin);
void deleteAdmin(int adminId);
Admin getAdminById(int adminId);
Admin getAdminByUsername(String username);
List<Admin> getAllAdmins();
boolean validateCredentials(String username, String password);
} }

View File

@ -1,57 +1,6 @@
package cyou.chenx221.service.impl; package cyou.chenx221.service.impl;
import cyou.chenx221.dao.AdminDao;
import cyou.chenx221.modal.Admin;
import cyou.chenx221.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class AdminServiceImpl implements AdminService { public class AdminServiceImpl implements AdminService {
private final AdminDao adminDao;
@Autowired
public AdminServiceImpl(AdminDao adminDao) {
this.adminDao = adminDao;
}
@Override
public void addAdmin(Admin admin) {
adminDao.addAdmin(admin);
}
@Override
public void updateAdmin(Admin admin) {
adminDao.updateAdmin(admin);
}
@Override
public void deleteAdmin(int adminId) {
adminDao.deleteAdmin(adminId);
}
@Override
public Admin getAdminById(int adminId) {
return adminDao.getAdminById(adminId);
}
@Override
public Admin getAdminByUsername(String username) {
return adminDao.getAdminByUsername(username);
}
@Override
public List<Admin> getAllAdmins() {
return adminDao.getAllAdmins();
}
@Override
public boolean validateCredentials(String username, String password) {
Admin admin = adminDao.getAdminByUsername(username);
return admin != null && admin.getPassword().equals(password);
}
} }

View File

@ -23,21 +23,21 @@ public class AdminServlet extends HttpServlet {
throws ServletException, IOException { throws ServletException, IOException {
String username = request.getParameter("username"); String username = request.getParameter("username");
String password = request.getParameter("password"); String password = request.getParameter("password");
System.out.println(username+password);
// 调用 AdminService 的验证凭证方法进行验证 // // 调用 AdminService 的验证凭证方法进行验证
boolean isValidCredentials = adminService.validateCredentials(username, password); // boolean isValidCredentials = adminService.validateCredentials(username, password);
//
if (isValidCredentials) { // if (isValidCredentials) {
// 登录成功设置会话状态 // // 登录成功设置会话状态
request.getSession().setAttribute("isLoggedIn", true); // request.getSession().setAttribute("isLoggedIn", true);
response.sendRedirect("dashboard.jsp"); // 重定向到仪表盘页面 // response.sendRedirect("dashboard.jsp"); // 重定向到仪表盘页面
} else { // } else {
// 登录失败返回错误消息 // // 登录失败返回错误消息
response.setContentType("text/html"); // response.setContentType("text/html");
PrintWriter out = response.getWriter(); // PrintWriter out = response.getWriter();
out.println("<html><body>"); // out.println("<html><body>");
out.println("<h3>登录失败,用户名或密码不正确。</h3>"); // out.println("<h3>登录失败,用户名或密码不正确。</h3>");
out.println("</body></html>"); // out.println("</body></html>");
} // }
} }
} }

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<!-- 配置其他 Bean -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<!-- 配置 AdminDao Bean -->
<bean id="adminDao" class="cyou.chenx221.dao.impl.AdminDaoImpl">
<constructor-arg ref="sqlSession" />
</bean>
<!-- 配置 AdminService Bean -->
<bean id="adminService" class="cyou.chenx221.service.impl.AdminServiceImpl">
<constructor-arg ref="adminDao" />
</bean>
</beans>

View File

@ -0,0 +1 @@
ignoreUrl=/logout,/selectNewbooks,/findById,/borrowBook,/search,/searchBorrowed,/returnBook,/searchRecords

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.BookMapper">
<!--新增图书-->
<insert id="addBook" parameterType="com.itheima.domain.Book">
insert into book(book_id,book_name,book_isbn,book_press,book_author,book_pagination,book_price,book_uploadtime,book_status,book_borrower,book_borrowtime,book_returntime)
values (#{id},#{name},#{isbn},#{press},#{author},#{pagination},#{price},#{uploadTime},#{status},#{borrower},#{borrowTime},#{returnTime})
</insert>
<!--修改book信息-->
<update id="editBook" >
update book
<trim prefix="set" suffixOverrides=",">
<if test="name != null" >
book_name = #{name},
</if>
<if test="isbn != null" >
book_isbn = #{isbn},
</if>
<if test="press != null" >
book_press = #{press},
</if>
<if test="author != null" >
book_author = #{author},
</if>
<if test="pagination != null" >
book_pagination = #{pagination},
</if>
<if test="price != null" >
book_price = #{price},
</if>
<if test="uploadTime != null" >
book_uploadtime = #{uploadTime},
</if>
<if test="status != null" >
book_status = #{status},
</if>
<if test="borrower!= null" >
book_borrower= #{borrower },
</if>
<if test="borrowTime != null" >
book_borrowtime = #{borrowTime},
</if>
<if test="returnTime != null" >
book_returntime = #{returnTime}
</if>
</trim>
where book_id = #{id}
</update>
</mapper>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.RecordMapper">
<insert id="addRecord">
insert into record(record_id,record_bookname,record_bookisbn,record_borrower,record_borrowtime,record_remandtime)
values (#{id},#{bookname},#{bookisbn},#{borrower},#{borrowTime},#{remandTime})
</insert>
</mapper>

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<!-- 配置其他 Bean -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<!-- 配置 AdminDao Bean -->
<bean id="adminDao" class="cyou.chenx221.dao.impl.AdminDaoImpl">
<constructor-arg ref="sqlSession" />
</bean>
<!-- 配置 AdminService Bean -->
<bean id="adminService" class="cyou.chenx221.service.impl.AdminServiceImpl">
<constructor-arg ref="adminDao" />
</bean>
</beans>

View File

@ -3,20 +3,4 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"> version="4.0">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app> </web-app>

View File

@ -6,11 +6,4 @@
To change this template use File | Settings | File Templates. To change this template use File | Settings | File Templates.
--%> --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html> <jsp:forward page="login.jsp"/>
<head>
<title>$Title$</title>
</head>
<body>
$END$
</body>
</html>

122
project/web/login.jsp Normal file
View File

@ -0,0 +1,122 @@
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<title>登录</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="css/mdb.min.css"/>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light" style="z-index: 1;min-height: 58.59px">
<div class="container">
<button class="navbar-toggler" type="button" data-mdb-toggle="collapse"
data-mdb-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation">
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<a class="navbar-brand mt-2 mt-lg-0" href="#">
<i class="fas fa-chalkboard-user me-2"></i>
教务管理系统
</a>
</div>
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar"
role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>
<a class="dropdown-item" href="login.jsp">登录</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main>
<div class="bg-image shadow-2-strong vh-100"
style="background-image: url('img/jason-blackeye-nyL-rzwP-Mk-unsplash.jpg');margin-top: -58.59px;">
<div class="mask d-flex align-items-center h-100" style="background-color: hsl(0deg 0% 100% / 13%);">
<div class="container-fluid px-0">
<div class="container d-flex align-items-center justify-content-center h-100">
<div style="background-color: rgba(255,255,255,0.7);backdrop-filter: blur(30px)"
class="rounded-5 shadow-5-strong p-5">
<form action="${pageContext.request.contextPath}/admin/login" method="POST">
<h1 class="text-center mb-4" style="font-family: 'Noto Sans SC Light',serif">用户登录</h1>
<div class="form-outline mb-4">
<input type="text" id="form1Example1" class="form-control" name="username"/>
<label class="form-label" for="form1Example1">用户名</label>
</div>
<div class="form-outline mb-4">
<input type="password" id="form1Example2" class="form-control" name="password"/>
<label class="form-label" for="form1Example2">密码</label>
</div>
<div class="row">
<div class="col d-flex justify-content-center">
<div class="form-check">
<input class="form-check-input" type="checkbox" value=""
id="form1Example3"
checked/>
<label class="form-check-label" for="form1Example3">记住密码</label>
</div>
</div>
<div class="col">
<a href="#!">忘记密码?</a>
</div>
</div>
<button type="button" class="btn btn-tertiary btn-block mx-auto"
data-mdb-ripple-color="light">没有账户? 注册账户
</button>
<button type="submit" class="btn btn-primary btn-block">登录</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</main>
<footer>
</footer>
<script type="text/javascript" src="js/mdb.min.js"></script>
</body>
</html>