From e80af330750c9b42577e82e65aa377b8cb049ed5 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Mon, 5 Jun 2023 19:49:07 +0800 Subject: [PATCH] reset --- project/.idea/webContexts.xml | 10 ++ project/pom.xml | 76 ++++++++++- .../cyou/chenx221/config/EncodingFilter.java | 19 +++ .../java/cyou/chenx221/config/JdbcConfig.java | 46 +++++++ .../cyou/chenx221/config/MyBatisConfig.java | 36 ++++++ .../config/ServletContainersInitConfig.java | 23 ++++ .../cyou/chenx221/config/SpringConfig.java | 34 +++++ .../cyou/chenx221/config/SpringMvcConfig.java | 43 ++++++ .../chenx221/controller/AdminController.java | 3 +- .../main/java/cyou/chenx221/dao/AdminDao.java | 26 ---- .../cyou/chenx221/dao/impl/AdminDaoImpl.java | 48 ------- .../cyou/chenx221/dao/impl/ScoreDaoImpl.java | 52 -------- .../chenx221/dao/impl/StudentDaoImpl.java | 42 ------ .../interceptor/ResourcesInterceptor.java | 49 +++++++ .../cyou/chenx221/mapper/AdminMapper.java | 17 +++ .../chenx221/{dao => mapper}/ScoreDao.java | 0 .../chenx221/{dao => mapper}/StudentDao.java | 0 .../main/java/cyou/chenx221/modal/Admin.java | 4 +- .../main/java/cyou/chenx221/modal/Score.java | 4 +- .../java/cyou/chenx221/modal/Student.java | 4 +- .../cyou/chenx221/service/AdminService.java | 16 +-- .../service/impl/AdminServiceImpl.java | 51 -------- .../cyou/chenx221/servlet/AdminServlet.java | 32 ++--- .../src/main/resources/applicationContext.xml | 40 ------ .../src/main/resources/ignoreUrl.properties | 1 + .../src/main/resources/mapper/BookMapper.xml | 49 +++++++ .../main/resources/mapper/RecordMapper.xml | 8 ++ project/web/WEB-INF/applicationContext.xml | 40 ------ project/web/WEB-INF/web.xml | 16 --- project/web/index.jsp | 9 +- project/web/login.jsp | 122 ++++++++++++++++++ project/web/{login.html => login2.html} | 0 32 files changed, 557 insertions(+), 363 deletions(-) create mode 100644 project/.idea/webContexts.xml create mode 100644 project/src/main/java/cyou/chenx221/config/EncodingFilter.java create mode 100644 project/src/main/java/cyou/chenx221/config/JdbcConfig.java create mode 100644 project/src/main/java/cyou/chenx221/config/MyBatisConfig.java create mode 100644 project/src/main/java/cyou/chenx221/config/ServletContainersInitConfig.java create mode 100644 project/src/main/java/cyou/chenx221/config/SpringConfig.java create mode 100644 project/src/main/java/cyou/chenx221/config/SpringMvcConfig.java delete mode 100644 project/src/main/java/cyou/chenx221/dao/AdminDao.java delete mode 100644 project/src/main/java/cyou/chenx221/dao/impl/AdminDaoImpl.java delete mode 100644 project/src/main/java/cyou/chenx221/dao/impl/ScoreDaoImpl.java delete mode 100644 project/src/main/java/cyou/chenx221/dao/impl/StudentDaoImpl.java create mode 100644 project/src/main/java/cyou/chenx221/interceptor/ResourcesInterceptor.java create mode 100644 project/src/main/java/cyou/chenx221/mapper/AdminMapper.java rename project/src/main/java/cyou/chenx221/{dao => mapper}/ScoreDao.java (100%) rename project/src/main/java/cyou/chenx221/{dao => mapper}/StudentDao.java (100%) delete mode 100644 project/src/main/resources/applicationContext.xml create mode 100644 project/src/main/resources/ignoreUrl.properties create mode 100644 project/src/main/resources/mapper/BookMapper.xml create mode 100644 project/src/main/resources/mapper/RecordMapper.xml delete mode 100644 project/web/WEB-INF/applicationContext.xml create mode 100644 project/web/login.jsp rename project/web/{login.html => login2.html} (100%) diff --git a/project/.idea/webContexts.xml b/project/.idea/webContexts.xml new file mode 100644 index 0000000..7117c5a --- /dev/null +++ b/project/.idea/webContexts.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/project/pom.xml b/project/pom.xml index 91d67bb..1e50d4f 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -30,7 +30,21 @@ spring-webmvc 5.3.27 - + + org.springframework + spring-tx + 5.3.27 + + + org.springframework + spring-jdbc + 5.3.27 + + + org.springframework + spring-test + 5.3.27 + org.mybatis @@ -77,9 +91,63 @@ - commons-dbcp - commons-dbcp - 1.4 + com.alibaba + druid + 1.1.20 + + + junit + junit + 4.12 + compile + + + com.github.pagehelper + pagehelper + 5.3.3 + + + jstl + jstl + 1.2 + + + taglibs + standard + 1.1.2 + + + + com.fasterxml.jackson.core + jackson-core + 2.9.2 + + + com.fasterxml.jackson.core + jackson-databind + 2.9.2 + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.0 + + + org.slf4j + slf4j-log4j12 + 1.6.1 + + + + org.apache.logging.log4j + log4j-api + 2.10.0 + + + + org.apache.logging.log4j + log4j-core + 2.10.0 \ No newline at end of file diff --git a/project/src/main/java/cyou/chenx221/config/EncodingFilter.java b/project/src/main/java/cyou/chenx221/config/EncodingFilter.java new file mode 100644 index 0000000..1d625cb --- /dev/null +++ b/project/src/main/java/cyou/chenx221/config/EncodingFilter.java @@ -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() {} +} diff --git a/project/src/main/java/cyou/chenx221/config/JdbcConfig.java b/project/src/main/java/cyou/chenx221/config/JdbcConfig.java new file mode 100644 index 0000000..faf871f --- /dev/null +++ b/project/src/main/java/cyou/chenx221/config/JdbcConfig.java @@ -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; + +/* +等同于 + + */ +@PropertySource("classpath:jdbc.properties") +public class JdbcConfig { + /* + 使用注入的形式,读取properties文件中的属性值, + 等同于 + */ + @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("dataSource") + public DataSource getDataSource(){ + //创建对象 + DruidDataSource ds = new DruidDataSource(); + /* + 等同于set属性注入 + */ + ds.setDriverClassName(driver); + ds.setUrl(url); + ds.setUsername(userName); + ds.setPassword(password); + return ds; + } +} + diff --git a/project/src/main/java/cyou/chenx221/config/MyBatisConfig.java b/project/src/main/java/cyou/chenx221/config/MyBatisConfig.java new file mode 100644 index 0000000..95182e3 --- /dev/null +++ b/project/src/main/java/cyou/chenx221/config/MyBatisConfig.java @@ -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; + } +} \ No newline at end of file diff --git a/project/src/main/java/cyou/chenx221/config/ServletContainersInitConfig.java b/project/src/main/java/cyou/chenx221/config/ServletContainersInitConfig.java new file mode 100644 index 0000000..13c0398 --- /dev/null +++ b/project/src/main/java/cyou/chenx221/config/ServletContainersInitConfig.java @@ -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[]{"/"}; + } +} diff --git a/project/src/main/java/cyou/chenx221/config/SpringConfig.java b/project/src/main/java/cyou/chenx221/config/SpringConfig.java new file mode 100644 index 0000000..757911a --- /dev/null +++ b/project/src/main/java/cyou/chenx221/config/SpringConfig.java @@ -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; + } +} + + + + + + diff --git a/project/src/main/java/cyou/chenx221/config/SpringMvcConfig.java b/project/src/main/java/cyou/chenx221/config/SpringMvcConfig.java new file mode 100644 index 0000000..1de8ea5 --- /dev/null +++ b/project/src/main/java/cyou/chenx221/config/SpringMvcConfig.java @@ -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 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"); + } + +} + + + + diff --git a/project/src/main/java/cyou/chenx221/controller/AdminController.java b/project/src/main/java/cyou/chenx221/controller/AdminController.java index 6c837e0..bd75ff0 100644 --- a/project/src/main/java/cyou/chenx221/controller/AdminController.java +++ b/project/src/main/java/cyou/chenx221/controller/AdminController.java @@ -9,13 +9,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller -@RequestMapping("/admin") public class AdminController { @Autowired private AdminService adminService; - @PostMapping("/login") + @RequestMapping("/login") public String login(@RequestParam("username") String username, @RequestParam("password") String password) { diff --git a/project/src/main/java/cyou/chenx221/dao/AdminDao.java b/project/src/main/java/cyou/chenx221/dao/AdminDao.java deleted file mode 100644 index fddd440..0000000 --- a/project/src/main/java/cyou/chenx221/dao/AdminDao.java +++ /dev/null @@ -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 getAllAdmins(); -} diff --git a/project/src/main/java/cyou/chenx221/dao/impl/AdminDaoImpl.java b/project/src/main/java/cyou/chenx221/dao/impl/AdminDaoImpl.java deleted file mode 100644 index d790d22..0000000 --- a/project/src/main/java/cyou/chenx221/dao/impl/AdminDaoImpl.java +++ /dev/null @@ -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 getAllAdmins() { - return sqlSession.selectList("AdminMapper.getAllAdmins"); - } -} diff --git a/project/src/main/java/cyou/chenx221/dao/impl/ScoreDaoImpl.java b/project/src/main/java/cyou/chenx221/dao/impl/ScoreDaoImpl.java deleted file mode 100644 index c6e857a..0000000 --- a/project/src/main/java/cyou/chenx221/dao/impl/ScoreDaoImpl.java +++ /dev/null @@ -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 getScoresByStudentId(int studentId) { - return sqlSession.selectList("ScoreMapper.getScoresByStudentId", studentId); - } - - @Override - public List getScoresByCourse(String course) { - return sqlSession.selectList("ScoreMapper.getScoresByCourse", course); - } - - @Override - public List getAllScores() { - return sqlSession.selectList("ScoreMapper.getAllScores"); - } -} diff --git a/project/src/main/java/cyou/chenx221/dao/impl/StudentDaoImpl.java b/project/src/main/java/cyou/chenx221/dao/impl/StudentDaoImpl.java deleted file mode 100644 index 3e57511..0000000 --- a/project/src/main/java/cyou/chenx221/dao/impl/StudentDaoImpl.java +++ /dev/null @@ -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 getAllStudents() { - return sqlSession.selectList("StudentMapper.getAllStudents"); - } -} diff --git a/project/src/main/java/cyou/chenx221/interceptor/ResourcesInterceptor.java b/project/src/main/java/cyou/chenx221/interceptor/ResourcesInterceptor.java new file mode 100644 index 0000000..1b8587f --- /dev/null +++ b/project/src/main/java/cyou/chenx221/interceptor/ResourcesInterceptor.java @@ -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 ignoreUrl; + public ResourcesInterceptor(List 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; + } +} \ No newline at end of file diff --git a/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java b/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java new file mode 100644 index 0000000..8089c64 --- /dev/null +++ b/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java @@ -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); +} diff --git a/project/src/main/java/cyou/chenx221/dao/ScoreDao.java b/project/src/main/java/cyou/chenx221/mapper/ScoreDao.java similarity index 100% rename from project/src/main/java/cyou/chenx221/dao/ScoreDao.java rename to project/src/main/java/cyou/chenx221/mapper/ScoreDao.java diff --git a/project/src/main/java/cyou/chenx221/dao/StudentDao.java b/project/src/main/java/cyou/chenx221/mapper/StudentDao.java similarity index 100% rename from project/src/main/java/cyou/chenx221/dao/StudentDao.java rename to project/src/main/java/cyou/chenx221/mapper/StudentDao.java diff --git a/project/src/main/java/cyou/chenx221/modal/Admin.java b/project/src/main/java/cyou/chenx221/modal/Admin.java index 8c95822..4ac0426 100644 --- a/project/src/main/java/cyou/chenx221/modal/Admin.java +++ b/project/src/main/java/cyou/chenx221/modal/Admin.java @@ -1,6 +1,8 @@ package cyou.chenx221.modal; -public class Admin { +import java.io.Serializable; + +public class Admin implements Serializable { // 管理员id 管理员姓名 管理员用户名 管理员密码 private int id; private String name; diff --git a/project/src/main/java/cyou/chenx221/modal/Score.java b/project/src/main/java/cyou/chenx221/modal/Score.java index 84018b9..cc6a970 100644 --- a/project/src/main/java/cyou/chenx221/modal/Score.java +++ b/project/src/main/java/cyou/chenx221/modal/Score.java @@ -1,6 +1,8 @@ package cyou.chenx221.modal; -public class Score { +import java.io.Serializable; + +public class Score implements Serializable { // 成绩id 学生id 课程 成绩 private int id; private int studentId; diff --git a/project/src/main/java/cyou/chenx221/modal/Student.java b/project/src/main/java/cyou/chenx221/modal/Student.java index f60a897..fe8e3fc 100644 --- a/project/src/main/java/cyou/chenx221/modal/Student.java +++ b/project/src/main/java/cyou/chenx221/modal/Student.java @@ -1,6 +1,8 @@ package cyou.chenx221.modal; -public class Student { +import java.io.Serializable; + +public class Student implements Serializable { // 学号 姓名 年龄 性别 private String id; private String name; diff --git a/project/src/main/java/cyou/chenx221/service/AdminService.java b/project/src/main/java/cyou/chenx221/service/AdminService.java index 4ddb991..8272677 100644 --- a/project/src/main/java/cyou/chenx221/service/AdminService.java +++ b/project/src/main/java/cyou/chenx221/service/AdminService.java @@ -2,20 +2,6 @@ package cyou.chenx221.service; import cyou.chenx221.modal.Admin; -import java.util.List; - public interface AdminService { - void addAdmin(Admin admin); - - void updateAdmin(Admin admin); - - void deleteAdmin(int adminId); - - Admin getAdminById(int adminId); - - Admin getAdminByUsername(String username); - - List getAllAdmins(); - - boolean validateCredentials(String username, String password); + Admin login(Admin admin); } diff --git a/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java b/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java index c27ca38..bbb8e56 100644 --- a/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java +++ b/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java @@ -1,57 +1,6 @@ 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 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 getAllAdmins() { - return adminDao.getAllAdmins(); - } - - @Override - public boolean validateCredentials(String username, String password) { - Admin admin = adminDao.getAdminByUsername(username); - return admin != null && admin.getPassword().equals(password); - } } diff --git a/project/src/main/java/cyou/chenx221/servlet/AdminServlet.java b/project/src/main/java/cyou/chenx221/servlet/AdminServlet.java index a5f16dd..a40000e 100644 --- a/project/src/main/java/cyou/chenx221/servlet/AdminServlet.java +++ b/project/src/main/java/cyou/chenx221/servlet/AdminServlet.java @@ -23,21 +23,21 @@ public class AdminServlet extends HttpServlet { throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); - - // 调用 AdminService 的验证凭证方法进行验证 - boolean isValidCredentials = adminService.validateCredentials(username, password); - - if (isValidCredentials) { - // 登录成功,设置会话状态 - request.getSession().setAttribute("isLoggedIn", true); - response.sendRedirect("dashboard.jsp"); // 重定向到仪表盘页面 - } else { - // 登录失败,返回错误消息 - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - out.println(""); - out.println("

登录失败,用户名或密码不正确。

"); - out.println(""); - } + System.out.println(username+password); +// // 调用 AdminService 的验证凭证方法进行验证 +// boolean isValidCredentials = adminService.validateCredentials(username, password); +// +// if (isValidCredentials) { +// // 登录成功,设置会话状态 +// request.getSession().setAttribute("isLoggedIn", true); +// response.sendRedirect("dashboard.jsp"); // 重定向到仪表盘页面 +// } else { +// // 登录失败,返回错误消息 +// response.setContentType("text/html"); +// PrintWriter out = response.getWriter(); +// out.println(""); +// out.println("

登录失败,用户名或密码不正确。

"); +// out.println(""); +// } } } diff --git a/project/src/main/resources/applicationContext.xml b/project/src/main/resources/applicationContext.xml deleted file mode 100644 index b967a0f..0000000 --- a/project/src/main/resources/applicationContext.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - classpath:db.properties - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/src/main/resources/ignoreUrl.properties b/project/src/main/resources/ignoreUrl.properties new file mode 100644 index 0000000..6b7772d --- /dev/null +++ b/project/src/main/resources/ignoreUrl.properties @@ -0,0 +1 @@ +ignoreUrl=/logout,/selectNewbooks,/findById,/borrowBook,/search,/searchBorrowed,/returnBook,/searchRecords \ No newline at end of file diff --git a/project/src/main/resources/mapper/BookMapper.xml b/project/src/main/resources/mapper/BookMapper.xml new file mode 100644 index 0000000..d4e9a35 --- /dev/null +++ b/project/src/main/resources/mapper/BookMapper.xml @@ -0,0 +1,49 @@ + + + + + + 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}) + + + + update book + + + book_name = #{name}, + + + book_isbn = #{isbn}, + + + book_press = #{press}, + + + book_author = #{author}, + + + book_pagination = #{pagination}, + + + book_price = #{price}, + + + book_uploadtime = #{uploadTime}, + + + book_status = #{status}, + + + book_borrower= #{borrower }, + + + book_borrowtime = #{borrowTime}, + + + book_returntime = #{returnTime} + + + where book_id = #{id} + + diff --git a/project/src/main/resources/mapper/RecordMapper.xml b/project/src/main/resources/mapper/RecordMapper.xml new file mode 100644 index 0000000..165daae --- /dev/null +++ b/project/src/main/resources/mapper/RecordMapper.xml @@ -0,0 +1,8 @@ + + + + + insert into record(record_id,record_bookname,record_bookisbn,record_borrower,record_borrowtime,record_remandtime) + values (#{id},#{bookname},#{bookisbn},#{borrower},#{borrowTime},#{remandTime}) + + diff --git a/project/web/WEB-INF/applicationContext.xml b/project/web/WEB-INF/applicationContext.xml deleted file mode 100644 index b967a0f..0000000 --- a/project/web/WEB-INF/applicationContext.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - classpath:db.properties - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/web/WEB-INF/web.xml b/project/web/WEB-INF/web.xml index bfc4d95..03e4493 100644 --- a/project/web/WEB-INF/web.xml +++ b/project/web/WEB-INF/web.xml @@ -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" version="4.0"> - - dispatcher - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - /WEB-INF/applicationContext.xml - - 1 - - - - dispatcher - / - - - diff --git a/project/web/index.jsp b/project/web/index.jsp index f1a5427..4511d28 100644 --- a/project/web/index.jsp +++ b/project/web/index.jsp @@ -6,11 +6,4 @@ To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> - - - $Title$ - - - $END$ - - + diff --git a/project/web/login.jsp b/project/web/login.jsp new file mode 100644 index 0000000..4a71306 --- /dev/null +++ b/project/web/login.jsp @@ -0,0 +1,122 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + + + 登录 + + + + + + + + + +
+ +
+ +
+
+
+
+
+
+
+

用户登录

+
+ + +
+
+ + +
+
+
+
+ + +
+
+ +
+ + +
+
+
+
+
+
+ + + + + + +
+ +
+ +
+ + + + + diff --git a/project/web/login.html b/project/web/login2.html similarity index 100% rename from project/web/login.html rename to project/web/login2.html