forked from hisenyuan/SSM_BookSystem
-
Notifications
You must be signed in to change notification settings - Fork 47
/
BookController.java
58 lines (51 loc) · 1.83 KB
/
BookController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.hisen.web;
import com.hisen.entity.Book;
import com.hisen.service.BookService;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by hisen on 17-4-24.
*/
@Controller
@RequestMapping("/book")
public class BookController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private BookService bookService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
private String list(Model model) {
List<Book> list = bookService.getList(0, 1000);
model.addAttribute("list", list);
return "list";// WEB-INF/jsp/"list".jsp
}
@RequestMapping(value = "/detail/{bookId}", method = RequestMethod.GET)
private String detail(@PathVariable("bookId") Long bookId, Model model) {
Book book = bookService.getById(bookId);
model.addAttribute("book", book);
return "detail";
}
@RequestMapping(value = "/add", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
@ResponseBody
private String add(Book book) {
Book hasBook = bookService.getById(book.getBookId());
int i = -2;
if (hasBook == null) {
i = bookService.addBook(book);
}
return i > 0 ? "success" : "error";
}
@RequestMapping(value = "/del/{bookId}", method = RequestMethod.GET)
@ResponseBody
private String deleteBookById(@PathVariable("bookId") Long id) {
int i = bookService.deleteBookById(id);
return i > 0 ? "success" : "error";
}
}