第三次作业

This commit is contained in:
zhangping 2024-09-16 01:29:33 +08:00
parent f6398c942e
commit 42669786dd
1 changed files with 0 additions and 76 deletions

View File

@ -1,76 +0,0 @@
package com.c202101080126.task1.controller;
import com.c202101080126.task1.model.Books;
import com.c202101080126.task1.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class BookController {
@Autowired
private BookService bookService;
@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")
public String addbook(Books book)
{
System.out.println(book);
bookService.addBook(book);
return "redirect:booklist";
}
@RequestMapping("addbookpage")
public String addbookpage()
{
return "addbook.html";
}
@RequestMapping("deletebook")
public String deleteBook(int id)
{
bookService.deleteBook(id);
return "redirect:booklist";
}
// 更新
@RequestMapping("updatebook")
public String updatebook(Books book, Model model)
{
//todo 传到一个新的页面更新
model.addAttribute("book",book);
return "updatebook.html";
}
@RequestMapping("updatebookcommit")
public String updatebookcommit(Books book)
{
bookService.updateBook(book);
return "redirect:booklist";
}
}