Book

WS})P$YEL]8[FT@8S044$BQ.png
entity类
public class Book {
private Integer id;
private String name;
private Double price;
public Book() {
}
public Book(Integer id, String name, Double price) {
this.id = id;
this.name = name;
this.price = price;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
'}';
}
}
dao/BookDAo
@Component
public class BookDAO {
public List<Book> getBooks(){
List<Book> books=new ArrayList<>();
books.add(new Book(1,"springboot",88.7));
books.add(new Book(1,"MAC", (double) 98));
books.add(new Book(1,"Java", (double) 98));
return books;
}
}
Controller/BookController
@RestController
public class BookController {
@Resource
private BookDAO bookDAO;
@RequestMapping(value = "/books",method = RequestMethod.GET)
public List<Book> getBooks(){
return bookDAO.getBooks();
}
}
网友评论