1. Springboot简单上手视频
链接:https://pan.baidu.com/s/1Wl0_7VECqeq5oO5Ems20Og
提取码:gjdc
起步练习
Book类
package com.springboot.quickstrat.entity;
public class Book {
private Integer id;
private String name;
private Double price;
public Book(Integer id, String name, Double price) {
this.id = id;
this.name = name;
this.price = price;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public Double getPrice() {
return price;
}
public void setId(Integer id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(Double price) {
this.price = price;
}
@Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
'}';
}
}
BookDAO类
package com.springboot.quickstrat.dao;
import com.springboot.quickstrat.entity.Book;
import org.springframework.stereotype.Component;
import sun.swing.BakedArrayList;
import java.util.ArrayList;
import java.util.List;
/**
* 图书的DAO类
*/
@Component
public class BookDAO {
public List<Book>getBooks() {
List<Book> books = new ArrayList<>();
books.add(new Book(1, "spring boot", 88.8));
books.add(new Book(2, "spring ", 88.8));
books.add(new Book(3, "spring boot", 88.8));
return books;
}
}
BookController类
package com.springboot.quickstrat.controller;
import com.springboot.quickstrat.dao.BookDAO;
import com.springboot.quickstrat.entity.Book;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class BookController {
@Resource
private BookDAO bookDAO;
@RequestMapping(value="/books" ,method= RequestMethod.GET)
public List<Book> getBooks(){
return bookDAO.getBooks();
}
}
运行结果: