Java 实战项目锤炼之网上图书馆管理系统的实现流程
短信预约 -IT技能 免费直播动态提醒
一、项目简述
功能: 区分为管理员用户和普通用户,普通用户:用户登录,个 人信息修改,图书查询,用户借阅,用户归还,管理员用 户:图书馆里,归还管理,借阅信息查询,图书维护,分 类管理,读者管理等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP + Servlert + html+ css + JavaScript + JQuery + Ajax等等。
用户登陆模块代码:
用户登陆模块:
@Controller
public class LoginController {
private LoginService loginService;
@Autowired
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
@RequestMapping(value = {"/", "/login.html"})
public String toLogin(HttpServletRequest request) {
request.getSession().invalidate();
return "index";
}
@RequestMapping("/logout.html")
public String logout(HttpServletRequest request) {
request.getSession().invalidate();
return "redirect:/login.html";
}
//负责处理loginCheck.html请求
//请求参数会根据参数名称默认契约自动绑定到相应方法的入参中
@RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST)
public @ResponseBody
Object loginCheck(HttpServletRequest request) {
long id = Long.parseLong(request.getParameter("id"));
String passwd = request.getParameter("passwd");
boolean isReader = loginService.hasMatchReader(id, passwd);
boolean isAdmin = loginService.hasMatchAdmin(id, passwd);
HashMap<String, String> res = new HashMap<>();
if (isAdmin) {
Admin admin = new Admin();
admin.setAdminId(id);
admin.setPassword(passwd);
String username = loginService.getAdminUsername(id);
admin.setUsername(username);
request.getSession().setAttribute("admin", admin);
res.put("stateCode", "1");
res.put("msg", "管理员登陆成功!");
} else if (isReader) {
ReaderCard readerCard = loginService.findReaderCardByReaderId(id);
request.getSession().setAttribute("readercard", readerCard);
res.put("stateCode", "2");
res.put("msg", "读者登陆成功!");
} else {
res.put("stateCode", "0");
res.put("msg", "账号或密码错误!");
}
return res;
}
@RequestMapping("/admin_main.html")
public ModelAndView toAdminMain(HttpServletResponse response) {
return new ModelAndView("admin_main");
}
@RequestMapping("/reader_main.html")
public ModelAndView toReaderMain(HttpServletResponse response) {
return new ModelAndView("reader_main");
}
@RequestMapping("/admin_repasswd.html")
public ModelAndView reAdminPasswd() {
return new ModelAndView("admin_repasswd");
}
@RequestMapping("/admin_repasswd_do")
public String reAdminPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) {
Admin admin = (Admin) request.getSession().getAttribute("admin");
long id = admin.getAdminId();
String password = loginService.getAdminPassword(id);
if (password.equals(oldPasswd)) {
if (loginService.adminRePassword(id, newPasswd)) {
redirectAttributes.addFlashAttribute("succ", "密码修改成功!");
return "redirect:/admin_repasswd.html";
} else {
redirectAttributes.addFlashAttribute("error", "密码修改失败!");
return "redirect:/admin_repasswd.html";
}
} else {
redirectAttributes.addFlashAttribute("error", "旧密码错误!");
return "redirect:/admin_repasswd.html";
}
}
@RequestMapping("/reader_repasswd.html")
public ModelAndView reReaderPasswd() {
return new ModelAndView("reader_repasswd");
}
@RequestMapping("/reader_repasswd_do")
public String reReaderPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) {
ReaderCard reader = (ReaderCard) request.getSession().getAttribute("readercard");
long id = reader.getReaderId();
String password = loginService.getReaderPassword(id);
if (password.equals(oldPasswd)) {
if (loginService.readerRePassword(id, newPasswd)) {
redirectAttributes.addFlashAttribute("succ", "密码修改成功!");
return "redirect:/reader_repasswd.html";
} else {
redirectAttributes.addFlashAttribute("error", "密码修改失败!");
return "redirect:/reader_repasswd.html";
}
} else {
redirectAttributes.addFlashAttribute("error", "旧密码错误!");
return "redirect:/reader_repasswd.html";
}
}
//配置404页面
@RequestMapping("*")
public String notFind() {
return "404";
}
}
静态资源和拦截器配置代码:
静态资源和拦截器配置:
@Configuration
@EnableWebMvc
@ComponentScan("com.library.controller")
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/img/**")
.addResourceLocations("/static/img/");
registry.addResourceHandler("/js/**").addResourceLocations("/static/js/");
registry.addResourceHandler("/css/**").addResourceLocations("/static/css/");
}
}
以上就是Java 实战项目锤炼之网上图书馆管理系统的实现流程的详细内容,更多关于Java 图书馆管理系统的资料请关注编程网其它相关文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341