




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第Java實戰(zhàn)圖書管理系統(tǒng)的實現(xiàn)流程//負(fù)責(zé)處理loginCheck.html請求
//請求參數(shù)會根據(jù)參數(shù)名稱默認(rèn)契約自動綁定到相應(yīng)方法的入?yún)⒅?/p>
@RequestMapping(value="/api/loginCheck",method=RequestMethod.POST)
public@ResponseBody
ObjectloginCheck(HttpServletRequestrequest){
longid=Long.parseLong(request.getParameter("id"));
Stringpasswd=request.getParameter("passwd");
booleanisReader=loginService.hasMatchReader(id,passwd);
booleanisAdmin=loginService.hasMatchAdmin(id,passwd);
HashMapString,Stringres=newHashMap();
if(isAdmin){
Adminadmin=newAdmin();
admin.setAdminId(id);
admin.setPassword(passwd);
Stringusername=loginService.getAdminUsername(id);
admin.setUsername(username);
request.getSession().setAttribute("admin",admin);
res.put("stateCode","1");
res.put("msg","管理員登陸成功!");
}elseif(isReader){
ReaderCardreaderCard=loginService.findReaderCardByReaderId(id);
request.getSession().setAttribute("readercard",readerCard);
res.put("stateCode","2");
res.put("msg","讀者登陸成功!");
}else{
res.put("stateCode","0");
res.put("msg","賬號或密碼錯誤!");
returnres;
@RequestMapping("/admin_main.html")
publicModelAndViewtoAdminMain(HttpServletResponseresponse){
returnnewModelAndView("admin_main");
@RequestMapping("/reader_main.html")
publicModelAndViewtoReaderMain(HttpServletResponseresponse){
returnnewModelAndView("reader_main");
@RequestMapping("/admin_repasswd.html")
publicModelAndViewreAdminPasswd(){
returnnewModelAndView("admin_repasswd");
@RequestMapping("/admin_repasswd_do")
publicStringreAdminPasswdDo(HttpServletRequestrequest,StringoldPasswd,StringnewPasswd,StringreNewPasswd,RedirectAttributesredirectAttributes){
Adminadmin=(Admin)request.getSession().getAttribute("admin");
longid=admin.getAdminId();
Stringpassword=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")
publicModelAndViewreReaderPasswd(){
returnnewModelAndView("reader_repasswd");
@RequestMapping("/reader_repasswd_do")
publicStringreReaderPasswdDo(HttpServletRequestrequest,StringoldPasswd,StringnewPasswd,StringreNewPasswd,RedirectAttributesredirectAttributes){
ReaderCardreader=(ReaderCard)request.getSession().getAttribute("readercard");
longid=reader.getReaderId();
Stringpassword=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("*")
publicStringnotFind(){
return"404";
}
圖書控制層:
@Controller
publicclassBookController{
@Autowired
privateBookServicebookService;
@Autowired
privateLendServicelendService;
privateDategetDate(Stringpubstr){
try{
SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-dd");
returndf.parse(pubstr);
}catch(ParseExceptione){
e.printStackTrace();
returnnewDate();
@RequestMapping("/queryBook.html")
publicModelAndViewqueryBookDo(StringsearchWord){
if(bookService.matchBook(searchWord)){
ArrayListBookbooks=bookService.queryBook(searchWord);
ModelAndViewmodelAndView=newModelAndView("admin_books");
modelAndView.addObject("books",books);
returnmodelAndView;
}else{
returnnewModelAndView("admin_books","error","沒有匹配的圖書");
@RequestMapping("/reader_querybook_do.html")
publicModelAndViewreaderQueryBookDo(StringsearchWord){
if(bookService.matchBook(searchWord)){
ArrayListBookbooks=bookService.queryBook(searchWord);
ModelAndViewmodelAndView=newModelAndView("reader_books");
modelAndView.addObject("books",books);
returnmodelAndView;
}else{
returnnewModelAndView("reader_books","error","沒有匹配的圖書");
@RequestMapping("/admin_books.html")
publicModelAndViewadminBooks(){
ArrayListBookbooks=bookService.getAllBooks();
ModelAndViewmodelAndView=newModelAndView("admin_books");
modelAndView.addObject("books",books);
returnmodelAndView;
@RequestMapping("/book_add.html")
publicModelAndViewaddBook(){
returnnewModelAndView("admin_book_add");
@RequestMapping("/book_add_do.html")
publicStringaddBookDo(@RequestParam(value="pubstr")Stringpubstr,Bookbook,RedirectAttributesredirectAttributes){
book.setPubdate(getDate(pubstr));
if(bookService.addBook(book)){
redirectAttributes.addFlashAttribute("succ","圖書添加成功!");
}else{
redirectAttributes.addFlashAttribute("succ","圖書添加失??!");
return"redirect:/admin_books.html";
@RequestMapping("/updatebook.html")
publicModelAndViewbookEdit(HttpServletRequestrequest){
longbookId=Long.parseLong(request.getParameter("bookId"));
Bookbook=bookService.getBook(bookId);
ModelAndViewmodelAndView=newModelAndView("admin_book_edit");
modelAndView.addObject("detail",book);
returnmodelAndView;
@RequestMapping("/book_edit_do.html")
publicStringbookEditDo(@RequestParam(value="pubstr")Stringpubstr,Bookbook,RedirectAttributesredirectAttributes){
book.setPubdate(getDate(pubstr));
if(bookService.editBook(book)){
redirectAttributes.addFlashAttribute("succ","圖書修改成功!");
}else{
redirectAttributes.addFlashAttribute("error","圖書修改失敗!");
return"redirect:/admin_books.html";
@RequestMapping("/admin_book_detail.html")
publicModelAndViewadminBookDetail(HttpServletRequestrequest){
longbookId=Long.parseLong(request.getParameter("bookId"));
Bookbook=bookService.getBook(bookId);
ModelAndViewmodelAndView=newModelAndView("admin_book_detail");
modelAndView.addObject("detail",book);
returnmodelAndView;
@RequestMapping("/reader_book_detail.html")
publicModelAndViewreaderBookDetail(HttpServletRequestrequest){
longbookId=Long.parseLong(request.getParameter("bookId"));
Bookbook=bookService.getBook(bookId);
ModelAndViewmodelAndView=newModelAndView("reader_book_detail");
modelAndView.addObject("detail",book);
returnmodelAndView;
@RequestMapping("/admin_header.html")
publicModelAndViewadmin_header(){
returnnewModelAndView("admin_header");
@RequestMapping("/reader_header.html")
publicModelAndViewreader_header(){
returnnewModelAndView("reader_header");
@RequestMapping("/reader_books.html")
publicModelAndViewreaderBooks(HttpServletRequestrequest){
ArrayListBookbooks=bookService.getAllBooks();
ReaderCardreaderCard=(ReaderCard)request.getSession().getAttribute("readercard");
ArrayListLendmyAllLendList=lendService.myLendList(readerCard.getReaderId());
ArrayListLongmyLendList=newArrayList();
for(Lendlend:myAllLendList){
//是否已歸還
if(lend.getBackDate()==null){
myLendList.add(lend.getBookId());
ModelAndViewmodelAndView=newModelAndView("reader_books");
modelAndView.addObject("books",books);
modelAndView.addObject("myLendList",myLendList);
returnmodelAndView;
}
借書控制層:
@Controller
publicclassLendController{
@Autowired
privateLendServicelendService;
@Autowired
privateBookServicebookService;
@RequestMapping("/deletebook.html")
publicStringdeleteBook(HttpServletRequestrequest,RedirectAttributesredirectAttributes){
longbookId=Long.parseLong(request.getParameter("bookId"));
if(bookService.deleteBook(bookId)){
redirectAttributes.addFlashAttribute("succ","圖書刪除成功!");
}else{
redirectAttributes.addFlashAttribute("error","圖書刪除失?。?);
return"redirect:/admin_books.html";
@RequestMapping("/lendlist.html")
publicModelAndViewlendList(HttpServletRequestrequest){
ModelAndViewmodelAndView=newModelAndView("admin_lend_list");
modelAndView.addObject("list",lendService.lendList());
returnmodelAndView;
@RequestMapping("/mylend.html")
publicModelAndViewmyLend(HttpServletRequestrequest){
ReaderCardreaderCard=(ReaderCard)request.getSession().getAttribute("readercard");
ModelAndViewmodelAndView=newModelAndView("reader_lend_list");
modelAndView.addObject("list",lendService.myLendList(readerCard.getReaderId()));
returnmodelAndView;
@RequestMapping("/deletelend.html")
publicStringdeleteLend(HttpServletRequestrequest,RedirectAttributesredirectAttributes){
longserNum=Long.parseLong(request.getParameter("serNum"));
if(lendService.deleteLend(serNum)0){
redirectAttributes.addFlashAttribute("succ","記錄刪除成功!");
}else{
redirectAttributes.addFlashAttribute("error","記錄刪除失??!");
return"redirect:/lendlist.html";
@RequestMapping("/lendbook.html")
publicStringb
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- java面試題及答案2021
- 2025年海洋科學(xué)專業(yè)畢業(yè)生考試試題及答案
- oraclesql考試題及答案
- java面試題及答案四個人偷吃蘋果
- 設(shè)計原型的構(gòu)建方法及試題與答案
- 軟件測試中的性能評估試題及答案
- 軟件設(shè)計師考試面臨的挑戰(zhàn)試題及答案
- 項目實施過程中的合規(guī)審查試題及答案
- 網(wǎng)絡(luò)工程師關(guān)鍵能力測評試題及答案
- 解密考試規(guī)則的信息系統(tǒng)項目管理師試題及答案
- 粒子加速器用30-4000 MHz級固態(tài)功率源系統(tǒng) 征求意見稿
- SL631水利水電工程單元工程施工質(zhì)量驗收標(biāo)準(zhǔn)第1部分:土石方工程
- 2025年湖南出版中南傳媒招聘筆試參考題庫含答案解析
- GB/T 44880-2024因果矩陣
- (高清版)TDT 1075-2023 光伏發(fā)電站工程項目用地控制指標(biāo)
- 談?wù)勅绾巫龊每蒲泄ぷ髡n件
- 人教版英語(一年級起點)1-3年級單詞表【完整版】
- 實驗室生物安全程序文件(共43頁)
- 數(shù)學(xué)分析試題及答案(兩份)
- 示范區(qū)精裝修成品保護(hù)
- JISG3506-2004高碳鋼盤條(中文版)
評論
0/150
提交評論