Compare commits

...

8 Commits

Author SHA1 Message Date
zhangping 5660393145 第三次作业 2024-09-16 03:27:27 +08:00
zhangping eb3af529e4 Merge branch 'master' of http://10.33.66.31:3000/zhangping/javaee1 2024-09-16 01:56:55 +08:00
zhangping 196cca220a 第三次作业 2024-09-16 01:55:56 +08:00
zhangping 8600412cb1 第三次作业 2024-09-16 01:54:59 +08:00
zhangping 0f60624493 第三次作业 2024-09-16 01:53:17 +08:00
zhangping 42669786dd 第三次作业 2024-09-16 01:32:18 +08:00
zhangping f6398c942e 第三次作业 2024-09-16 01:28:31 +08:00
zhangping be13576c42 第三次作业 2024-09-16 01:18:46 +08:00
47 changed files with 354 additions and 869 deletions

View File

@ -1,6 +1,6 @@
package com.c202101080126.task1.controller; package com.c202101080126.task1.controller;
import com.c202101080126.task1.model.Books; import com.c202101080126.task1.model.Book;
import com.c202101080126.task1.service.BookService; import com.c202101080126.task1.service.BookService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -16,29 +16,10 @@ public class BookController {
@RequestMapping("booklist")
public String booklist(Model model,String title)
{
if(title!=null&&!title.equals("")){
model.addAttribute("books",bookService.searchBooksbyTitle(title));
}
else {
model.addAttribute("books", bookService.getBooks());
}
return "booklist.html";
}
@RequestMapping("commentlist1")
public String commentlist(Model model)
{
model.addAttribute("books", bookService.getBooks());
return "commentlist.html";
}
@RequestMapping("addbook") @RequestMapping("addbook")
public String addbook(Books book) public String addbook(Book book)
{ {
System.out.println(book); System.out.println(book);
bookService.addBook(book); bookService.addBook(book);
@ -51,6 +32,20 @@ public class BookController {
{ {
return "addbook.html"; return "addbook.html";
} }
@RequestMapping("booklist")
public String booklist(Model model,String title)
{
if(title!=null&&!title.equals("")){
model.addAttribute("books", bookService.searchBookbyTitle(title));
}
else
{
model.addAttribute("books", bookService.getBooks());
}
return "booklist.html";
}
@RequestMapping("deletebook") @RequestMapping("deletebook")
public String deleteBook(int id) public String deleteBook(int id)
@ -58,19 +53,26 @@ public class BookController {
bookService.deleteBook(id); bookService.deleteBook(id);
return "redirect:booklist"; return "redirect:booklist";
} }
// 更新
@RequestMapping("updatebook") @RequestMapping("updatebook")
public String updatebook(Books book, Model model) public String updatebook(Book book, Model model)
{ {
//todo 传到一个新的页面更新
model.addAttribute("book",book); model.addAttribute("book",book);
return "updatebook.html"; return "updatebook.html";
} }
@RequestMapping("updatebookcommit") @RequestMapping("updatebookcommit")
public String updatebookcommit(Books book) public String updatebookcommit(Book book)
{ {
bookService.updateBook(book); bookService.updateBook(book);
return "redirect:booklist"; return "redirect:booklist";
} }
@RequestMapping("commentlist")
public String commentlist(Model model) {
model.addAttribute("books", bookService.getBooks());
return "commentlist.html";
}
} }

View File

@ -2,9 +2,9 @@ package com.c202101080126.task1.controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import com.c202101080126.task1.model.Books; import com.c202101080126.task1.model.Book;
import com.c202101080126.task1.model.BorrowRecords; import com.c202101080126.task1.model.BorrowRecords;
import com.c202101080126.task1.model.Users; import com.c202101080126.task1.model.User;
import com.c202101080126.task1.service.BookService; import com.c202101080126.task1.service.BookService;
import com.c202101080126.task1.service.IBorrowRecordsService; import com.c202101080126.task1.service.IBorrowRecordsService;
import com.c202101080126.task1.service.UserService; import com.c202101080126.task1.service.UserService;
@ -32,66 +32,55 @@ public class BorrowRecordsController {
BookService bookService; BookService bookService;
@Autowired @Autowired
UserService userService; UserService userService;
// 查询所有书籍借阅
@RequestMapping("borrowlist") @RequestMapping("borrowlist")
public String borrowlist(Model model, String title) { public String borrowlist(Model model, String title) {
if (title != null && !title.equals("")) { if (title != null && !title.equals("")) {
int bookid = bookService.getBookByTitle(title).getId(); int bookid = bookService.getBookByTitle(title).getId();
model.addAttribute("borrowRecords",borrowRecordsService.searchBorrowByBookId(bookid)); model.addAttribute("borrowrecords", borrowRecordsService.searchBorrowRecordsbyId(bookid));
} else { } else {
model.addAttribute("borrowRecords",borrowRecordsService.getBorrowRecords()); model.addAttribute("borrowrecords", borrowRecordsService.getBorrowRecords());
} }
return "bookborrow.html"; return "borrowlist.html";
} }
//增加书籍借阅 @RequestMapping("addborrowrecord")
@RequestMapping("addborrowpage") public String addborrowrecord(Model model) {
public String addborrowpage(Model model){
List<Books> books=bookService.getBooks();
List<Users> users=userService.getAllUsers();
model.addAttribute("users",users);
model.addAttribute("books",books);
return "addborrow.html"; return "addborrow.html";
} }
@RequestMapping("addborrow")
public String addborrow(int userid, int bookid, LocalDate borrowDate, LocalDate returnDate){
BorrowRecords borrowRecords=new BorrowRecords();
borrowRecords.setUserid(userid);
borrowRecords.setBookid(bookid);
borrowRecords.setBorrowDate(borrowDate);
borrowRecords.setReturnDate(returnDate);
borrowRecords.setStatus("借阅中");
borrowRecordsService.addBorrow(borrowRecords);
return "redirect:borrowlist";
}
@RequestMapping("addborrow")
public String addborrow(BorrowRecords borrowRecords) {
borrowRecordsService.addBorrowRecords(borrowRecords);
return "redirect:/borrowlist";
}
@RequestMapping("deleteborrow") @RequestMapping("deleteborrow")
public String deleteborrow(int id) { public String deleteborrow(int id) {
borrowRecordsService.deleteborrow(id); borrowRecordsService.deleteBorrowRecords(id);
return "redirect:borrowlist"; return "redirect:/borrowlist";
} }
@RequestMapping("updateborrow") @RequestMapping("updateborrow")
public String updateborrowpage(Model model, BorrowRecords borrowRecords){ public String updateborrow(BorrowRecords borrowRecords, Model model) {
model.addAttribute("borrowRecord",borrowRecords); model.addAttribute("borrow", borrowRecords);
//borrowRecordsService.updateBorrowRecords(borrowRecords);
return "updateborrow.html"; return "updateborrow.html";
} }
@RequestMapping("updateborrowcommit") @RequestMapping("updateborrowcommit")
public String updateborrow(int id,int userid, int bookid, LocalDate borrowDate, LocalDate returnDate, String status) { public String updateborrowcommit(int id, int userid, int bookid, LocalDate borrowDate, LocalDate backDate) {
System.out.println("1111" + borrowDate);
BorrowRecords borrowRecords = new BorrowRecords(); BorrowRecords borrowRecords = new BorrowRecords();
borrowRecords.setId(id); borrowRecords.setId(id);
borrowRecords.setUserid(userid); borrowRecords.setUserid(userid);
borrowRecords.setBookid(bookid); borrowRecords.setBookid(bookid);
borrowRecords.setBorrowDate(borrowDate); borrowRecords.setBorrowDate(borrowDate);
borrowRecords.setReturnDate(returnDate); borrowRecords.setBackDate(backDate);
borrowRecords.setStatus(status); borrowRecordsService.updateBorrowRecords(borrowRecords);
System.out.println(borrowRecords.getBorrowDate()); return "redirect:/borrowlist";
borrowRecordsService.updateborrow(borrowRecords);
return "redirect:borrowlist";
} }
// @RequestMapping("addborrow")
// public String addborrow(int bookid,int userid) {
// borrowRecordsService.addBorrowRecord(bookid,userid);
// return "redirect:/borrowlist";
// }
} }

View File

@ -1,33 +0,0 @@
package com.c202101080126.task1.controller;
import com.c202101080126.task1.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class LoginController {
@Autowired
private LoginService loginService;
@RequestMapping("login")
public String login()
{
return "login.html";
}
@RequestMapping("register")
public String register()
{
return "register.html";
}
@RequestMapping("registercommit")
public String registercommit(String username,String password)
{
loginService.register(username,password);
return "login.html";
}
}

View File

@ -3,7 +3,6 @@ package com.c202101080126.task1.controller;
import com.c202101080126.task1.model.Reviews; import com.c202101080126.task1.model.Reviews;
import com.c202101080126.task1.service.IReviewsService; import com.c202101080126.task1.service.IReviewsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -16,11 +15,20 @@ import org.springframework.stereotype.Controller;
* @since 2024-09-14 * @since 2024-09-14
*/ */
@Controller @Controller
public class ReviewsController { public class ReviewsController {
@Autowired @Autowired
IReviewsService reviewsService; IReviewsService reviewsService;
@RequestMapping("addcommentpage")
public String addcommentpage() {
return "addcomment.html";
}
@RequestMapping("addcomment")
public String addcomment(Reviews reviews) {
reviewsService.addreview(reviews);
return "redirect:/booklist";
}
} }

View File

@ -1,69 +1,41 @@
package com.c202101080126.task1.controller; package com.c202101080126.task1.controller;
import com.c202101080126.task1.model.Books;
import com.c202101080126.task1.model.Reviews;
import org.springframework.ui.Model;
import com.c202101080126.task1.service.BookService;
import com.c202101080126.task1.service.IReviewsService;
import com.c202101080126.task1.service.UserService; import com.c202101080126.task1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author zhangping
* @since 2024-09-14
*/
@Controller @Controller
public class UserController
public class UserController {
@Autowired
UserService userService;
@Autowired
IReviewsService reviewsService;
@Autowired
BookService bookService;
//获取所有用户的书籍评价
@RequestMapping("commentlist")
public String commentlist(Model model,String title)
{ {
if(title!=null&&!title.equals("")) { @Autowired
model.addAttribute("users", reviewsService.searchBooksbyTitle(title)); private UserService userService;
}else{
model.addAttribute("users", userService.getAllUsers());
}
return "bookcommentlist.html";
}
//添加书籍评价页面 @RequestMapping("login")
@RequestMapping("addcommentpage") public String login()
public String addcommentpage(Model model,int id)
{ {
Reviews review=new Reviews(); return "login.html";
review.setUserid(id);
List<Books> books=bookService.getBooks();
model.addAttribute("review",review);
model.addAttribute("books",books);
return "addcomment.html";
} }
@RequestMapping("register")
@RequestMapping("addcomment") public String register()
public String addcomment(String id,String bookid,String comment)
{ {
System.out.println(id+" "+bookid+" "+comment); return "register.html";
Reviews review=new Reviews(); }
review.setUserid(Integer.parseInt(id)); @RequestMapping("logincommit")
review.setBookid(Integer.parseInt(bookid)); public String logincommit(String username,String password)
review.setComment(comment); {
reviewsService.addreview(review); String result=userService.getPassword(username);
return "redirect:/commentlist"; System.out.println("result"+result);
System.out.println("password"+password);
if(result.equals(password))
return "book.html";
else
return "loginfail.html";
}
@RequestMapping("registercommit")
public String registercommit(String username,String password)
{
userService.register(username,password);
return "login.html";
} }
} }

View File

@ -1,7 +1,7 @@
package com.c202101080126.task1.dao; package com.c202101080126.task1.dao;
import com.c202101080126.task1.model.Books; import com.c202101080126.task1.model.Book;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -9,14 +9,13 @@ import java.util.List;
@Mapper @Mapper
public interface BookMapper { public interface BookMapper {
public List<Books> getBooks(); public List<Book> getBooks();
public List<Books> getBooks1(); public List<Book> getBooks1();
public Books getBookByBookId(int id); public Book getBookByBookId(int id);
public int addBook(Book book);
public int addBook(Books book);
public int deleteBook(int id); public int deleteBook(int id);
public int updateBook(Books book); public int updateBook(Book book);
public List<Books> searchBooksbyTitle(String title); public List<Book> searchBookbyTitle(String title);
public Books getBookByTitle(String title); public Book getBookByTitle(String title);
} }

View File

@ -16,14 +16,14 @@ import java.util.List;
*/ */
@Mapper @Mapper
public interface BorrowRecordsMapper extends BaseMapper<BorrowRecords> { public interface BorrowRecordsMapper extends BaseMapper<BorrowRecords> {
public List<BorrowRecords> getBorrowRecords(); public List<BorrowRecords> getBorrowRecords();
public List<BorrowRecords> searchBorrowByBookId(int bookid); public int addBorrowRecords(BorrowRecords borrowRecords);
public int addBorrow(BorrowRecords borrowRecords); public List<BorrowRecords> searchBorrowRecordsbyId(int bookid);
public int deleteborrow(int id); public int deleteBorrowRecords(int id);
public int updateborrow(BorrowRecords borrowRecords);
public int updateBorrowRecords(BorrowRecords borrowRecords);
} }

View File

@ -1,8 +0,0 @@
package com.c202101080126.task1.dao;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface LoginMapper {
public void register(String username, String password);
}

View File

@ -1,8 +1,7 @@
package com.c202101080126.task1.dao; package com.c202101080126.task1.dao;
import com.c202101080126.task1.model.Books; import com.c202101080126.task1.model.Book;
import com.c202101080126.task1.model.Reviews; import com.c202101080126.task1.model.Reviews;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -15,14 +14,16 @@ import java.util.List;
* @author zhangping * @author zhangping
* @since 2024-09-14 * @since 2024-09-14
*/ */
@Mapper
public interface ReviewsMapper extends BaseMapper<Reviews> {
public int addreview(Reviews reviews);
public List<Reviews> getReviewsByBookId(int id); @Mapper
public List<Reviews> getCommentByUserId(int id); public interface ReviewsMapper {
public List<Reviews> getreviews(); public List<Reviews> getreviews();
public List<Books> searchBooksbyTitle(String title); public int addreview(Reviews reviews);
public List<Reviews> getCommentByBookId(int id);
public List<Reviews> getCommentByUserId(int id);
} }

View File

@ -1,22 +1,12 @@
package com.c202101080126.task1.dao; package com.c202101080126.task1.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.c202101080126.task1.model.User;
import com.c202101080126.task1.model.Users;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author zhangping
* @since 2024-09-14
*/
@Mapper @Mapper
public interface UserMapper { public interface UserMapper {
public void register(String username,String password);
public String getPassword(String username);
public List<Users> getAllUsers(); public User getUserById(int userid);
public Users getUserById(int id);
} }

View File

@ -1,20 +0,0 @@
package com.c202101080126.task1.model;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.util.List;
@Data
public class Books {
private int id;
private String title;
private String author;
private String isbn;
private String publisher;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate published_date;
private List<Reviews> reviewlist;
}

View File

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -19,7 +18,7 @@ import lombok.Setter;
*/ */
@Getter @Getter
@Setter @Setter
@TableName("borrow_records202101080126") @TableName("borrow_records202101080124")
public class BorrowRecords implements Serializable { public class BorrowRecords implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -31,12 +30,9 @@ public class BorrowRecords implements Serializable {
private Integer bookid; private Integer bookid;
private LocalDate borrowDate;; private LocalDate borrowDate;
private LocalDate returnDate;
private String status;
private Books book;
private Users user;
private LocalDate backDate;
private User user;
private Book book;
} }

View File

@ -28,8 +28,5 @@ public class Reviews implements Serializable {
private Integer bookid; private Integer bookid;
private String comment; private String comment;
private Book book;
private Books book;
} }

View File

@ -1,15 +0,0 @@
package com.c202101080126.task1.model;
import lombok.Data;
import java.util.List;
@Data
public class Users {
private String username;
private String classname;
private int id;
private List<Reviews> reviewlist;
private List<BorrowRecords> borrowlist;
}

View File

@ -1,20 +1,17 @@
package com.c202101080126.task1.service; package com.c202101080126.task1.service;
import com.c202101080126.task1.model.Book;
import com.c202101080126.task1.model.Books;
import java.util.List; import java.util.List;
public interface BookService { public interface BookService {
public List<Books> getBooks(); public List<Book> getBooks();
public int addBook(Book book);
public int addBook(Books book);
public int deleteBook(int id); public int deleteBook(int id);
public int updateBook(Book book);
public int updateBook(Books book); public List<Book> searchBookbyTitle(String title);
public Book getBookByTitle(String title);
public Books getBookByTitle(String title);
public List<Books> searchBooksbyTitle(String title);
} }

View File

@ -14,15 +14,10 @@ import java.util.List;
* @since 2024-09-14 * @since 2024-09-14
*/ */
public interface IBorrowRecordsService { public interface IBorrowRecordsService {
public List<BorrowRecords> getBorrowRecords(); public List<BorrowRecords> getBorrowRecords();
public List<BorrowRecords> searchBorrowRecordsbyId(int bookid);
public List<BorrowRecords> searchBorrowByBookId(int bookid); public int addBorrowRecords(BorrowRecords borrowRecords);
public int deleteBorrowRecords(int id);
public int addBorrow(BorrowRecords borrowRecords); public int updateBorrowRecords(BorrowRecords borrowRecords);
public int deleteborrow(int id);
public int updateborrow(BorrowRecords borrowRecords);
} }

View File

@ -1,12 +1,8 @@
package com.c202101080126.task1.service; package com.c202101080126.task1.service;
import com.c202101080126.task1.model.Books;
import com.c202101080126.task1.model.Reviews; import com.c202101080126.task1.model.Reviews;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Collection;
import java.util.List;
/** /**
* <p> * <p>
* 服务类 * 服务类
@ -16,9 +12,6 @@ import java.util.List;
* @since 2024-09-14 * @since 2024-09-14
*/ */
public interface IReviewsService { public interface IReviewsService {
public int addreview(Reviews reviews); public int addreview(Reviews reviews);
public List<Reviews> getreviews();
public List<Books> searchBooksbyTitle(String title);
} }

View File

@ -1,10 +1,7 @@
package com.c202101080126.task1.service.Impl; package com.c202101080126.task1.service.Impl;
import com.c202101080126.task1.dao.BookMapper; import com.c202101080126.task1.dao.BookMapper;
import com.c202101080126.task1.dao.LoginMapper; import com.c202101080126.task1.model.Book;
import com.c202101080126.task1.model.Books;
import com.c202101080126.task1.service.BookService; import com.c202101080126.task1.service.BookService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -16,13 +13,21 @@ public class BookServiceImpl implements BookService {
@Autowired @Autowired
private BookMapper bookMapper; private BookMapper bookMapper;
@Override @Override
public List<Books> getBooks() { public List<Book> getBooks() {
return bookMapper.getBooks1(); return bookMapper.getBooks1();
} }
@Override
public List<Book> searchBookbyTitle(String title) {
return bookMapper.searchBookbyTitle(title);
}
@Override @Override
public int addBook(Books book) { public Book getBookByTitle(String title) {
return bookMapper.getBookByTitle(title);
}
@Override
public int addBook(Book book) {
return bookMapper.addBook(book); return bookMapper.addBook(book);
} }
@ -32,18 +37,9 @@ public class BookServiceImpl implements BookService {
} }
@Override @Override
public int updateBook(Books book) { public int updateBook(Book book) {
return bookMapper.updateBook(book); return bookMapper.updateBook(book);
} }
@Override
public Books getBookByTitle(String title) {
return bookMapper.getBookByTitle(title);
}
@Override
public List<Books> searchBooksbyTitle(String title) {
return bookMapper.searchBooksbyTitle(title);
} }
}

View File

@ -1,12 +1,17 @@
package com.c202101080126.task1.service.Impl; package com.c202101080126.task1.service.Impl;
import com.c202101080126.task1.dao.BookMapper;
import com.c202101080126.task1.dao.UserMapper;
import com.c202101080126.task1.model.Book;
import com.c202101080126.task1.model.BorrowRecords; import com.c202101080126.task1.model.BorrowRecords;
import com.c202101080126.task1.dao.BorrowRecordsMapper; import com.c202101080126.task1.dao.BorrowRecordsMapper;
import com.c202101080126.task1.model.User;
import com.c202101080126.task1.service.IBorrowRecordsService; import com.c202101080126.task1.service.IBorrowRecordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -19,31 +24,56 @@ import java.util.List;
*/ */
@Service @Service
public class BorrowRecordsServiceImpl implements IBorrowRecordsService { public class BorrowRecordsServiceImpl implements IBorrowRecordsService {
@Autowired @Autowired
BorrowRecordsMapper borrowRecordsMapper; BorrowRecordsMapper borrowRecordsMapper;
@Autowired
BookMapper bookMapper;
@Autowired
UserMapper userMapper;
@Override @Override
public List<BorrowRecords> getBorrowRecords() { public List<BorrowRecords> getBorrowRecords() {
return borrowRecordsMapper.getBorrowRecords(); List<BorrowRecords> borrowRecords =borrowRecordsMapper.getBorrowRecords();
for(BorrowRecords borrow:borrowRecords){
int userid = borrow.getUserid();
int bookid = borrow.getBookid();
User user = userMapper.getUserById(userid);
Book book = bookMapper.getBookByBookId(bookid);
borrow.setUser(user);
borrow.setBook(book);
System.out.println("aaaaaa"+book);
}
System.out.println(borrowRecords.toString());
return borrowRecords;
} }
@Override @Override
public List<BorrowRecords> searchBorrowByBookId(int bookid) { public List<BorrowRecords> searchBorrowRecordsbyId(int bookid) {
return borrowRecordsMapper.searchBorrowByBookId(bookid); List<BorrowRecords> borrowRecords = borrowRecordsMapper.searchBorrowRecordsbyId(bookid);
for(BorrowRecords borrow:borrowRecords){
int userid = borrow.getUserid();
int bookid1 = borrow.getBookid();
User user = userMapper.getUserById(userid);
Book book = bookMapper.getBookByBookId(bookid1);
borrow.setUser(user);
borrow.setBook(book);
}
return borrowRecords;
} }
@Override @Override
public int addBorrow(BorrowRecords borrowRecords) { public int addBorrowRecords(BorrowRecords borrowRecords) {
return borrowRecordsMapper.addBorrow(borrowRecords); return borrowRecordsMapper.addBorrowRecords(borrowRecords);
} }
@Override @Override
public int deleteborrow(int id) { public int deleteBorrowRecords(int id) {
return borrowRecordsMapper.deleteborrow(id); return borrowRecordsMapper.deleteBorrowRecords(id);
} }
@Override @Override
public int updateborrow(BorrowRecords borrowRecords) { public int updateBorrowRecords(BorrowRecords borrowRecords) {
return borrowRecordsMapper.updateborrow(borrowRecords); return borrowRecordsMapper.updateBorrowRecords(borrowRecords);
} }
} }

View File

@ -1,21 +0,0 @@
package com.c202101080126.task1.service.Impl;
import com.c202101080126.task1.dao.LoginMapper;
import com.c202101080126.task1.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private LoginMapper loginMapper;
@Override
public void register(String username, String password) {
loginMapper.register(username, password);
}
}

View File

@ -1,16 +1,12 @@
package com.c202101080126.task1.service.Impl; package com.c202101080126.task1.service.Impl;
import com.c202101080126.task1.model.Books;
import com.c202101080126.task1.model.Reviews; import com.c202101080126.task1.model.Reviews;
import com.c202101080126.task1.dao.ReviewsMapper; import com.c202101080126.task1.dao.ReviewsMapper;
import com.c202101080126.task1.service.IReviewsService; import com.c202101080126.task1.service.IReviewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类
@ -21,26 +17,11 @@ import java.util.List;
*/ */
@Service @Service
public class ReviewsServiceImpl implements IReviewsService { public class ReviewsServiceImpl implements IReviewsService {
@Autowired @Autowired
ReviewsMapper reviewsMapper; ReviewsMapper reviewsMapper;
@Override @Override
public List<Reviews> getreviews() { public int addreview(Reviews reviews) {
return reviewsMapper.getreviews(); return reviewsMapper.addreview(reviews);
} }
@Override
public List<Books> searchBooksbyTitle(String title) {
return reviewsMapper.searchBooksbyTitle(title);
}
@Override
public int addreview(Reviews review) {
return reviewsMapper.addreview(review);
}
} }

View File

@ -1,29 +1,34 @@
package com.c202101080126.task1.service.Impl; package com.c202101080126.task1.service.Impl;
import com.c202101080126.task1.dao.UserMapper; import com.c202101080126.task1.dao.UserMapper;
import com.c202101080126.task1.model.Users; import com.c202101080126.task1.model.User;
import com.c202101080126.task1.service.UserService; import com.c202101080126.task1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author zhangping
* @since 2024-09-14
*/
@Service @Service
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
@Autowired @Autowired
UserMapper userMapper; private UserMapper userMapper;
@Override @Override
public List<Users> getAllUsers() { public void register(String username, String password) {
return userMapper.getAllUsers(); userMapper.register(username,password);
}
@Override
public String getPassword(String username)
{
return userMapper.getPassword(username);
}
@Override
public List<User> getAllUsers() {
return List.of();
}
} }
}

View File

@ -1,8 +0,0 @@
package com.c202101080126.task1.service;
public interface LoginService {
public void register(String username,String password);
}

View File

@ -1,19 +1,12 @@
package com.c202101080126.task1.service; package com.c202101080126.task1.service;
import com.c202101080126.task1.model.Users; import com.c202101080126.task1.model.User;
import java.util.List; import java.util.List;
/** public interface UserService {
* <p> public void register(String username,String password);
* 服务类 public String getPassword(String username);
* </p> public List<User> getAllUsers();
*
* @author zhangping
* @since 2024-09-14
*/
public interface UserService
{
List<Users> getAllUsers();
} }

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.c202101080126.task1.dao.BookMapper"> <mapper namespace="com.c202101080126.task1.dao.BookMapper">
<select id="getBooks" resultType="com.c202101080126.task1.model.Books"> <select id="getBooks" resultType="com.c202101080126.task1.model.Book">
select * from books202101080126 select * from books202101080126
</select> </select>
<insert id="addBook" parameterType="com.c202101080126.task1.model.Books"> <insert id="addBook" parameterType="com.c202101080126.task1.model.Book">
insert into books202101080126(title,author,isbn,publisher,published_date) values(#{title},#{author},#{isbn},#{publisher},#{published_date}) insert into books202101080126(title,author,isbn,publisher,published_date) values(#{title},#{author},#{isbn},#{publisher},#{published_date})
</insert> </insert>
@ -13,27 +13,32 @@
delete from books202101080126 where id=#{id} delete from books202101080126 where id=#{id}
</delete> </delete>
<update id="updateBook" parameterType="com.c202101080126.task1.model.Books"> <update id="updateBook" parameterType="com.c202101080126.task1.model.Book">
update books202101080126 set title=#{title},author=#{author},isbn=#{isbn},publisher=#{publisher},published_date=#{published_date} where id=#{id} update books202101080126 set title=#{title},author=#{author},isbn=#{isbn},publisher=#{publisher},published_date=#{published_date} where id=#{id}
</update> </update>
<select id="searchBooksbyTitle" parameterType="String" resultType="com.c202101080126.task1.model.Books"> <select id="searchBookbyTitle" resultMap="book">
select * from books202101080126 where title like "%"#{title}"%" select * from books202101080126 where title like '%${title}%'
</select>
<select id="getBookByTitle" resultType="com.c202101080126.task1.model.Book">
select * from books202101080126 where title=#{title}
</select> </select>
<select id="getBooks1" resultMap="book"> <select id="getBooks1" resultMap="book">
select * from books202101080126 select * from books202101080126
</select> </select>
<resultMap id="book" type="com.c202101080126.task1.model.Books">
<id property="id" column="id"/> <resultMap id="book" type="com.c202101080126.task1.model.Book">
<result property="title" column="title"/> <id column="id" property="id"/>
<result property="author" column="author"/> <result column="title" property="title"/>
<result property="isbn" column="isbn"/> <result column="author" property="author"/>
<result property="publisher" column="publisher"/> <result column="isbn" property="isbn"/>
<result property="published_date" column="published_date"/> <result column="publisher" property="publisher"/>
<result column="published_date" property="published_date"/>
<collection property="reviewlist" <collection property="reviewlist"
column="id" column="id"
select="com.c202101080126.task1.dao.ReviewsMapper.getReviewsByBookId" select="com.c202101080126.task1.dao.ReviewsMapper.getCommentByBookId"
ofType="com.c202101080126.task1.model.Reviews"> ofType="com.c202101080126.task1.model.Reviews">
</collection> </collection>
</resultMap> </resultMap>
@ -41,29 +46,4 @@
<select id="getBookByBookId" resultMap="book"> <select id="getBookByBookId" resultMap="book">
select * from books202101080126 where id=#{id} select * from books202101080126 where id=#{id}
</select> </select>
<!-- property 实体类字段名字 column数据库字段名字-->
<!-- <resultMap id="PersonMap1" type="com.zp.spring.springboot.model.Person">-->
<!-- <id property="id" column="id"/>-->
<!-- <result property="name" column="name"/>-->
<!-- <result property="age" column="age"/>-->
<!-- <association property="idCard"-->
<!-- column="idcardid"-->
<!-- select="com.zp.spring.springboot.dao.IdcardMapper.getIdcard"-->
<!-- javaType="com.zp.spring.springboot.model.IdCard">-->
<!-- </association>-->
<!-- <collection property="orderList"-->
<!-- column="id"-->
<!-- select="com.zp.spring.springboot.dao.OrderMapper.getOrderByUserId"-->
<!-- ofType="com.zp.spring.springboot.model.Order">-->
<!-- </collection>-->
<!-- </resultMap>-->
<!-- </select>-->
</mapper> </mapper>

View File

@ -2,58 +2,24 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.c202101080126.task1.dao.BorrowRecordsMapper"> <mapper namespace="com.c202101080126.task1.dao.BorrowRecordsMapper">
<!-- <select id="getBorrowRecordsByUserId" resultMap="bookBorrow">--> <select id="getBorrowRecords" resultType="com.c202101080126.task1.model.BorrowRecords">
<!-- select * from borrow_records202101080112 where userid=#{id}--> select * from borrow_records202101080126
<!-- </select>-->
<!-- <resultMap id="bookBorrow" type="com._202101080112.task1.model.BorrowRecords">-->
<!-- <id column="id" property="id"/>-->
<!-- <result column="userid" property="userid"/>-->
<!-- <result column="bookid" property="bookid"/>-->
<!-- <result column="borrow_date" property="borrowDate"/>-->
<!-- <result column="return_date" property="returnDate"/>-->
<!-- <association property="book"-->
<!-- column="bookid"-->
<!-- select="com._202101080112.task1.dao.BookMapper.getBookByBookId"-->
<!-- javaType="com._202101080112.task1.model.Books">-->
<!-- </association>-->
<!-- </resultMap>-->
<select id="getBorrowRecords" resultMap="bookBorrow">
select * from borrow_records202101080112
</select>
<resultMap id="bookBorrow" type="com.c202101080126.task1.model.BorrowRecords">
<id column="id" property="id"/>
<result column="userid" property="userid"/>
<result column="bookid" property="bookid"/>
<result column="borrow_date" property="borrowDate"/>
<result column="return_date" property="returnDate"/>
<association property="book"
column="bookid"
select="com._202101080112.task1.dao.BookMapper.getBookByBookId"
javaType="com.c202101080126.task1.model.Books">
</association>
<association property="user"
column="userid"
select="com._202101080112.task1.dao.UserMapper.getUserById"
javaType="com.c202101080126.task1.model.Users">
</association>
</resultMap>
<select id="searchBorrowByBookId" resultMap="bookBorrow">
select * from borrow_records202101080126 where bookid=#{id}
</select> </select>
<insert id="addBorrow" parameterType="com.c202101080126.task1.model.BorrowRecords"> <insert id="addBorrowRecords" parameterType="com.c202101080126.task1.model.BorrowRecords">
insert into borrow_records202101080126(userid,bookid,borrow_date,return_date,status) values(#{userid},#{bookid},#{borrowDate},#{returnDate},#{status}) insert into borrow_records202101080126(bookid,userid,borrow_date,back_date) values(#{bookid},#{userid},#{borrowDate},#{backDate})
</insert> </insert>
<delete id="deleteborrow" parameterType="int">
<select id="searchBorrowRecordsbyId" resultType="com.c202101080126.task1.model.BorrowRecords">
select * from borrow_records202101080126 where bookid=#{bookid}
</select>
<delete id="deleteBorrowRecords" parameterType="Integer">
delete from borrow_records202101080126 where id=#{id} delete from borrow_records202101080126 where id=#{id}
</delete> </delete>
<update id="updateborrow" parameterType="com.c202101080126.task1.model.BorrowRecords"> <update id="updateBorrowRecords" parameterType="com.c202101080126.task1.model.BorrowRecords">
update borrow_records202101080126 set borrow_date=#{borrowDate},return_date=#{returnDate},status=#{status} where id=#{id} update borrow_records202101080126 set bookid=#{bookid},userid=#{userid},borrow_date=#{borrowDate},back_date=#{backDate} where id=#{id}
</update> </update>
</mapper> </mapper>

View File

@ -1,7 +0,0 @@
<?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.c202101080126.task1.dao.LoginMapper">
<insert id="register" parameterType="com.c202101080126.task1.model.Users">
insert into users202101080126(username,password) values(#{username},#{password})
</insert>
</mapper>

View File

@ -15,7 +15,7 @@
<association property="book" <association property="book"
column="bookid" column="bookid"
select="com.c202101080126.task1.dao.BookMapper.getBookByBookId" select="com.c202101080126.task1.dao.BookMapper.getBookByBookId"
javaType="com.c202101080126.task1.model.Books"> javaType="com.c202101080126.task1.model.Book">
</association> </association>
</resultMap> </resultMap>
@ -34,9 +34,18 @@
<select id="searchBooksbyTitle" resultMap="reviews"> <select id="searchBooksbyTitle" resultMap="reviews">
select * from reviews202101080126 where title like '%${title}%' select * from reviews202101080126 where title like '%${title}%'
</select> </select>
<select id="getCommentByBookId" resultType="com.c202101080126.task1.model.Reviews">
select * from reviews202101080126 where bookid=#{bookid}
</select>
<insert id="addreview" parameterType="com.c202101080126.task1.model.Reviews"> <insert id="addreview" parameterType="com.c202101080126.task1.model.Reviews">
insert into reviews202101080126(userid,bookid,comment) values(#{userid},#{bookid},#{comment}) insert into reviews202101080126(userid,bookid,comment) values(#{userid},#{bookid},#{comment})
</insert> </insert>
</mapper> </mapper>
<!-- ofType="com.zp.spring.springboot.model.Order">-->
<!-- </collection>-->
<!-- </resultMap>-->
<!-- </select>-->

View File

@ -1,25 +1,14 @@
<?xml version="1.0" encoding="UTF-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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.c202101080126.task1.dao.UserMapper"> <mapper namespace="com.c202101080126.task1.dao.UserMapper">
<insert id="register" parameterType="com.c202101080126.task1.model.User">
<select id="getAllUsers" resultMap="usercomment"> insert into users202101080126(username,password) values(#{username},#{password})
select * from users202101080126 </insert>
<select id="getPassword" parameterType="String" resultType="String">
select password from users202101080126 where username=#{username}
</select> </select>
<resultMap id="usercomment" type="com.c202101080126.task1.model.Users">
<id column="id" property="id"/>
<result column="username" property="username"/>
<collection property="reviewlist"
column="id"
select="com.c202101080126.task1.dao.ReviewsMapper.getCommentByUserId"
ofType="com.c202101080126.task1.model.Reviews">
</collection>
</resultMap>
<select id="getUserById" resultType="com.c202101080126.task1.model.Users"> <select id="getUserById" parameterType="int" resultType="com.c202101080126.task1.model.User">
select * from users202101080126 where id=#{id} select * from users202101080126 where id=#{id}
</select> </select>
</mapper> </mapper>

View File

@ -1,21 +1,20 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>添加书籍评价页面</h1> <h1>增加书本页面</h1>
<form th:action="@{/addbook}" method="post">
<form th:action="@{/addcomment}" method="post"> <input type="text" name="title" placeholder="书名"><br/>
<input type="id" name="id" th:value="${review.userid}" hidden="hidden"><br/></input> <input type="text" name="author" placeholder="作者"><br/>
<!-- 下拉框显示所有书籍--> <input type="text" name="isbn" placeholder="ISBN号"><br/>
<select name="bookid"> <input type="text" name="publisher" placeholder="出版社">
<option th:each="book:${books}" th:value="${book.id}" th:text="${book.title}"></option> <input type="date" name="published_date" placeholder="出版日期"><br/>
</select> <input type="submit" value="增加书本"></input>
<input type="text" name="comment" placeholder="请输入评价"><br/></input>
<input type="submit" value="增加书籍评价"></input>
</input> </input>
</form> </form>
<a th:href="@{/booklist}">增加书本</a>
</body> </body>
</html> </html>

View File

@ -1,27 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>添加书本借阅页面</h1> <h1>增加书本借阅页面</h1>
<form th:action="@{/addborrow}" method="post"> <form th:action="@{/addborrow}" method="post">
<input type="int" name="userid" placeholder="用户id"><br/>
<select name="userid"> <input type="int" name="bookid" placeholder="书籍id"><br/>
<option th:each="user:${users}" th:value="${user.id}" th:text="${user.username}"></option> <input type="date" name="borrowDate" placeholder="借阅时间"><br/></input>
</select><br/> <input type="date" name="backDate" placeholder="归还时间"><br/></input>
<select name="bookid">
<option th:each="book:${books}" th:value="${book.id}" th:text="${book.title}"></option>
</select><br/>
<input type="date" name="borrowDate" placeholder="借阅时间"><br>
<input type="date" name="returnDate" placeholder="归还时间"><br></br></input>
<input type="submit" value="增加书本借阅"></input> <input type="submit" value="增加书本借阅"></input>
</input> </input>
</form> </form>
</body> </body>
</html> </html>

View File

@ -1,19 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>添加书籍评价页面</h1> <h1>增加书本评价页面</h1>
<form th:action="@{/addcomment}" method="post"> <form th:action="@{/addcomment}" method="post">
<input type="id" name="id" th:value="${review.userid}" hidden="hidden"><br/></input> <input type="text" name="userid" placeholder="用户id"><br/>
<input type="int" name="bookid" placeholder="书籍id"><br/>
<select name="bookid"> <input type="text" name="comment" placeholder="评论"><br/>
<option th:each="book:${books}" th:value="${book.id}" th:text="${book.title}"></option>
</select>
<input type="text" name="comment" placeholder="评价"><br/></input>
<input type="submit" value="增加书本评价"></input> <input type="submit" value="增加书本评价"></input>
</input> </input>
</form> </form>

View File

@ -6,7 +6,7 @@
</head> </head>
<body> <body>
<h1>书本管理页面</h1> <h1>书本管理页面</h1>
<a th:href="@{/booklist}">查询书本</a>
<a th:href="@{/addbookpage}">增加书本</a> <a th:href="@{/addbookpage}">增加书本</a>
<a th:href="@{/booklist}">查询书本</a>
</body> </body>
</html> </html>

View File

@ -1,45 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>书本借阅页面</h1>
<form th:action="@{/borrowlist}" method="post">
<input type="text" name="title" placeholder="书名">
<input type="submit" value="搜索书本借阅"></input>
</input>
</form>
<a th:href="@{/addborrowpage}">增加借阅书籍</a>
<table border="1">
<tr>
<td>id</td>
<td>借阅人</td>
<td>书名</td>
<td>借阅时间</td>
<td>归还时间</td>
<td>状态</td>
<td>删除</td>
<td>更新</td>
</tr>
<tr th:each="borrow:${borrowRecords}">
<td th:text="${borrow.id}"></td>
<td th:text="${borrow.user.username}"></td>
<td th:text="${borrow.book.title}"></td>
<td th:text="${borrow.borrowDate}"></td>
<td th:text="${borrow.returnDate}"></td>
<td th:text="${borrow.status}"></td>
<td>
<a th:href="@{/deleteborrow(id=${borrow.id})}">删除</a>
</td>
<td>
<a th:href="@{/updateborrow(id=${borrow.id},userid=${borrow.user.id},bookid=${borrow.book.id},borrowDate=${borrow.borrowDate},returnDate=${borrow.returnDate})}">更新</a>
</td>
</tr>
</table>
</body>
</html>

View File

@ -1,46 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>书本评价页面</h1>
<form th:action="@{/booklist}" method="post">
<input type="text" name="title" placeholder="书名">
<input type="submit" value="搜索书本评价"></input>
</input>
</form>
<table border="1">
<tr>
<td>id</td>
<td>用户名</td>
<td>书本评价</td>
<td>增加书本评价</td>
</tr>
<tr th:each="user:${users}">
<td th:text="${user.id}"></td>
<td th:text="${user.username}"></td>
<div th:if="${user.reviewlist}!=null">
<td>
<ul th:each="review:${user.reviewlist}">
<li>
<div th:text="${review.book.title}"></div>
<div th:text="${review.comment}"></div>
</li>
</ul>
</td>
</div>
<td>
<a th:href="@{/addcommentpage(id=${user.id})}">增加书本评价</a>
</td>
<!-- <td>-->
<!-- <a th:href="@{/updatebook(id=${book.id},title=${book.title},author=${book.author},isbn=${book.isbn},publisher=${book.publisher},published_date=${book.published_date})}">更新</a>-->
<!-- </td>-->
</table>
</body>
</html>

View File

@ -5,26 +5,28 @@
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>图书管理页面</h1> <h1>书本管理页面</h1>
<form th:action="@{/booklist}" method="post"> <form th:action="@{/booklist}" method="post">
<input type="text" name="title" placeholder="请输入书名"> <input type="text" name="title" placeholder="书名">
<input type="submit" value="搜索书"></input> <input type="submit" value="搜索书"></input>
</input> </input>
</form> </form>
<a th:href="@{/addbookpage}">添加书籍</a> <a th:href="@{/addbookpage}">增加书本</a>
<a th:href="@{/addcommentpage}">增加书本评价</a>
<table border="1"> <table border="1">
<tr> <tr>
<td>id</td> <td>id</td>
<td>书名</td> <td>书名</td>
<td>作者</td> <td>作者</td>
<td>isbn</td> <td>ISBN</td>
<td>出版社</td> <td>出版社</td>
<td>出版时间</td> <td>出版日期</td>
<td>评价</td> <td>评论</td>
<td>删除书本</td> <td>删除操作</td>
<td>更新书本</td> <td>更新操作</td>
</tr> </tr>
<tr th:each="book:${books}"> <tr th:each="book:${books}">
<td th:text="${book.id}"></td> <td th:text="${book.id}"></td>
@ -33,6 +35,8 @@
<td th:text="${book.isbn}"></td> <td th:text="${book.isbn}"></td>
<td th:text="${book.publisher}"></td> <td th:text="${book.publisher}"></td>
<td th:text="${book.published_date}"></td> <td th:text="${book.published_date}"></td>
<div th:if="${book.reviewlist}!=null"> <div th:if="${book.reviewlist}!=null">
<td> <td>
<ul th:each="review:${book.reviewlist}"> <ul th:each="review:${book.reviewlist}">
@ -41,15 +45,15 @@
</li> </li>
</ul> </ul>
</td> </td>
</div> </div>
<td> <td>
<a th:href="@{/deletebook(id=${book.id})}">删除</a> <a th:href="@{/deletebook(id=${book.id})}">删除</a>
</td> </td>
<td> <td>
<a th:href="@{/updatebook(id=${book.id},title=${book.title},author=${book.author},isbn=${book.isbn},publisher=${book.publisher},published_date=${book.published_date})}">更新</a> <a th:href="@{/updatebook(id=${book.id},title=${book.title},author=${book.author},
isbn=${book.isbn},publisher=${book.publisher},published_date=${book.published_date})}">更新</a>
</td> </td>
</tr>
</table> </table>
</body> </body>
</html> </html>

View File

@ -1,16 +1,16 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>页面</h1> <h1>页面</h1>
<a th:href="@{/register}">没有账号?点击注册</a> <a href="register">注册</a>
<form th:action="@{/logincommit}" method="post"> <form th:action="@{/logincommit}" method="post">
<input type="text" name="username" placeholder="请输入用户名"><br> <input type="text" name="username" placeholder="用户名"><br/>
<input type="password" name="password" placeholder="请输入密码"><br> <input type="text" name="password" placeholder="密码"><br/>
<input type="submit" value="登"></input> <input type="submit" value="登"></input>
</input> </input>
</form> </form>
</body> </body>

View File

@ -5,6 +5,6 @@
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>失败</h1> <h1>失败</h1>
</body> </body>
</html> </html>

View File

@ -6,9 +6,10 @@
</head> </head>
<body> <body>
<h1>注册页面</h1> <h1>注册页面</h1>
<a href="register">注册</a>
<form th:action="@{/registercommit}" method="post"> <form th:action="@{/registercommit}" method="post">
<input type="text" name="username" placeholder="请输入用户名"><br> <input type="text" name="username" placeholder="用户名"><br/>
<input type="password" name="password" placeholder="请输入密码"><br> <input type="text" name="password" placeholder="密码"><br/>
<input type="submit" value="注册"></input> <input type="submit" value="注册"></input>
</input> </input>
</form> </form>

View File

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>书本评价页面</h1>
<a th:href="@{/book/reviewpage}">增加书本评价</a>
<form th:action="@{/reviewlist}" method="post">
<input type="text" name="title" placeholder="请输入评价">
<input type="submit" value="搜索书本评价">
</form>
<table border="1">
<tr>
<td>id</td>
</tr>
<tr th:each="review:${reviews}">
<td th:text="${review.id}"></td>
</tr>
</table>
</body>
</html>

View File

@ -5,16 +5,15 @@
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>更新书籍页面</h1> <h1>更新书本页面</h1>
<form th:action="@{/updatebookcommit}" method="post"> <form th:action="@{/updatebookcommit}" method="post">
<input type="id" name="id" th:value="${book.id}" hidden="hidden"><br/> <input type="id" name="id" th:value="${book.id}" hidden="hidden"><br/>
<input type="text" name="title" placeholder="书名" th:value="${book.title}"><br/></input> <input type="text" name="title" placeholder="书名" th:value="${book.title}"><br/>
<input type="text" name="author" placeholder="作者" th:value="${book.author}"><br/></input> <input type="text" name="author" placeholder="年龄" th:value="${book.author}"><br/>
<input type="text" name="isbn" placeholder="isbn号" th:value="${book.isbn}"><br/></input> <input type="text" name="isbn" placeholder="ISBN号" th:value="${book.isbn}"><br/>
<input type="text" name="publisher" placeholder="出版社" th:value="${book.publisher}"><br/></input> <input type="text" name="publisher" placeholder="出版社" th:value="${book.publisher}"><br/>
<input type="date" name="published_date" placeholder="出版时间" th:value="${book.published_date}"><br/></input> <input type="date" name="published_date" placeholder="出版日期" th:value="${book.published_date}"><br/></input>
<input type="submit" value="更新书"></input> <input type="submit" value="更新书"></input>
</input> </input>
</form> </form>
</body> </body>

View File

@ -5,16 +5,15 @@
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>更新书籍借阅页面</h1> <h1>更新书本借阅页面</h1>
<form th:action="@{/updateborrowcommit}" method="post"> <form th:action="@{/updateborrowcommit}" method="post">
<input type="id" name="id" th:value="${borrowRecord.id}" hidden="hidden"> <input type="id" name="id" th:value="${borrow.id}" hidden="hidden"><br/>
<input type="id" name="userid" th:value="${borrowRecord.userid}" hidden="hidden"> <input type="int" name="userid" placeholder="用户id" th:value="${borrow.userid}"><br/>
<input type="id" name="bookid" th:value="${borrowRecord.bookid}" hidden="hidden"> <input type="int" name="bookid" placeholder="书籍id" th:value="${borrow.bookid}"><br/>
<input type="date" name="borrowDate" placeholder="借阅时间" th:value="${borrowRecord.borrowDate}"><br/> <input type="date" name="borrowDate" placeholder="借阅时间" th:value="${borrow.borrowDate}"><br/></input>
<input type="date" name="returnDate" placeholder="返还时间" th:value="${borrowRecord.returnDate}"><br/></input> <input type="date" name="backDate" placeholder="归还时间" th:value="${borrow.backDate}"><br/></input>
<input type="text" name="status" placeholder="状态" th:value="${borrowRecord.status}"><br/></input>
<input type="submit" value="更新借阅信息"></input> <input type="submit" value="更新书本"></input>
</input> </input>
</form> </form>
</body> </body>

View File

@ -1,48 +0,0 @@
<?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.c202101080126.task1.dao.BookMapper">
<select id="getBooks" resultType="com.c202101080126.task1.model.Books">
select * from books202101080126
</select>
<insert id="addBook" parameterType="com.c202101080126.task1.model.Books">
insert into books202101080126(title,author,isbn,publisher,published_date) values(#{title},#{author},#{isbn},#{publisher},#{published_date})
</insert>
<update id="updatebook" parameterType="com.c202101080126.task1.model.Books">
update books202101080126 set title=#{title},author=#{author},isbn=#{isbn},publisher=#{publisher},published_date=#{published_date} where id=#{id}
</update>
<delete id="deletebook" parameterType="int">
delete from books202101080126 where id=#{id}
</delete>
<select id="searchBooksbyTitle" resultMap="book">
select * from books202101080126 where title like '%${title}%'
</select>
<select id="getBookByTitle" resultType="com.c202101080126.task1.model.Books">
select * from books202101080126 where title=#{title}
</select>
<select id="getBooks1" resultMap="book">
select * from books202101080126
</select>
<resultMap id="book" type="com.c202101080126.task1.model.Books">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="author" property="author"/>
<result column="isbn" property="isbn"/>
<result column="publisher" property="publisher"/>
<result column="published_date" property="published_date"/>
<collection property="reviewlist"
column="id"
select="com.c202101080126.task1.dao.ReviewsMapper.getCommentByBookId"
ofType="com.c202101080126.task1.model.Reviews">
</collection>
</resultMap>
<select id="getBookByBookId" resultMap="book">
select * from books202101080126 where id=#{id}
</select>
</mapper>

View File

@ -1,43 +0,0 @@
<?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.c202101080126.task1.dao.BorrowRecordsMapper">
<select id="getBorrowRecords" resultMap="bookBorrow">
select * from borrow_records202101080126
</select>
<resultMap id="bookBorrow" type="com.c202101080126.task1.model.BorrowRecords">
<id column="id" property="id"/>
<result column="userid" property="userid"/>
<result column="bookid" property="bookid"/>
<result column="borrow_date" property="borrowDate"/>
<result column="return_date" property="returnDate"/>
<association property="book"
column="bookid"
select="com.c202101080126.task1.dao.BookMapper.getBookByBookId"
javaType="com.c202101080126.task1.model.Books">
</association>
<association property="user"
column="userid"
select="com._202101080112.task1.dao.UserMapper.getUserById"
javaType="com.c202101080126.task1.model.Users">
</association>
</resultMap>
<select id="searchBorrowByBookId" resultMap="bookBorrow">
select * from borrow_records202101080126 where bookid=#{id}
</select>
<insert id="addBorrow" parameterType="com.c202101080126.task1.model.BorrowRecords">
insert into borrow_records202101080126(userid,bookid,borrow_date,return_date,status) values(#{userid},#{bookid},#{borrowDate},#{returnDate},#{status})
</insert>
<delete id="deleteborrow" parameterType="int">
delete from borrow_records202101080126 where id=#{id}
</delete>
<update id="updateborrow" parameterType="com.c202101080126.task1.model.BorrowRecords">
update borrow_records202101080126 set borrow_date=#{borrowDate},return_date=#{returnDate},status=#{status} where id=#{id}
</update>
</mapper>

View File

@ -1,12 +0,0 @@
<?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.c202101080126.task1.dao.LoginMapper">
<insert id="register" parameterType="com.c202101080126.task1.model.Users">
insert into users202101080126(username,password) values(#{username},#{password})
</insert>
<select id="getPassword" resultType="String">
select password from users202101080126 where username=#{username}
</select>
</mapper>

View File

@ -1,43 +0,0 @@
<?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.c202101080126.task1.dao.ReviewsMapper">
<select id="getReviewsByBookId" resultType="com.c202101080126.task1.model.Reviews">
select * from reviews202101080126 where bookid=#{id}
</select>
<select id="getCommentByUserId" resultMap="bookreview">
select * from reviews20210108026 where userid=#{id}
</select>
<resultMap id="bookreview" type="com.c202101080126.task1.model.Reviews">
<id column="id" property="id"/>
<result column="bookid" property="bookid"/>
<result column="review" property="comment"/>
<association property="book"
column="bookid"
select="com.c202101080126.task1.dao.BookMapper.getBookByBookId"
javaType="com.c202101080126.task1.model.Books">
</association>
</resultMap>
<select id="getreviews" resultMap="reviews">
select * from reviews202101080126
</select>
<resultMap id="reviews" type="com.c202101080126.task1.model.Reviews">
<id column="id" property="id"/>
<result column="bookid" property="bookid"/>
<result column="review" property="comment"/>
</resultMap>
<select id="searchBooksbyTitle" resultMap="reviews">
select * from reviews202101080126 where title like '%${title}%'
</select>
<insert id="addreview" parameterType="com.c202101080126.task1.model.Reviews">
insert into reviews202101080126(userid,bookid,comment) values(#{userid},#{bookid},#{review})
</insert>
</mapper>

View File

@ -1,20 +0,0 @@
<?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.c202101080126.task1.dao.UserMapper">
<select id="getAllUsers" resultMap="usercomment">
select * from users202101080126
</select>
<resultMap id="usercomment" type="com.c202101080126.task1.model.Users">
<id column="id" property="id"/>
<result column="username" property="username"/>
<collection property="reviewlist"
column="id"
select="com._202101080112.task1.dao.ReviewsMapper.getCommentByUserId"
ofType="com.c202101080126.task1.model.Reviews">
</collection>
</resultMap>
<select id="getUserById" resultType="com.c202101080126.task1.model.Users">
select * from users202101080126 where id=#{id}
</select>
</mapper>