zmd50 5 years ago
parent 81fe96ac36
commit 700358a697

@ -0,0 +1,77 @@
package com.book.demo.controller;
import com.book.demo.entity.Book;
import com.book.demo.mapper.BookMapper;
import com.book.demo.services.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class BookController {
@Autowired
BookMapper bookMapper;
@Autowired
Result res;
@ResponseBody
@GetMapping("/getallbooks")
public Result getAllBooks(){
Book []books=bookMapper.getAll();
if(books.length<=0){
res.setCode(-1);
res.setMsg("当前系统没有书籍信息");
res.data=null;
}
else{
res.setCode(0);
res.setMsg("获取成功");
for (Book book : books) {
res.data.add(book);
}
}
return res;
}
@ResponseBody
@GetMapping("/getbooks")
public Result getAllBooks(@RequestParam("kind")int kind){
Book []books=bookMapper.getBooksByKind(kind);
if(books.length<=0){
res.setCode(-1);
res.setMsg("当前系统没有此类别书籍信息");
res.data=null;
}
else{
res.setCode(0);
res.setMsg("获取成功");
for (Book book : books) {
res.data.add(book);
}
}
return res;
}
@ResponseBody
@GetMapping("/searchbooks")
public Result getAllBooks(@RequestParam("bookname")String bookname){
Book []books=bookMapper.searchBooks(bookname);
if(books.length<=0){
res.setCode(-1);
res.setMsg("当前系统没有相关书籍信息");
res.data=null;
}
else{
res.setCode(0);
res.setMsg("获取成功");
for (Book book : books) {
res.data.add(book);
}
}
return res;
}
}
Loading…
Cancel
Save