新建一個quickstart項目
- 過程:
file-new-project-Empty-quickstart和F:\SpringBootStudy-finish
自動跳入以下圖片

- 點加號+,選中以下的東西


- 然后什么都不用選,看路徑,最后finish
建以下的包

- pox.xml的包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 第一個練習(xí)
HelloController類
package com.springboot.quickstart.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
//springboot的第一個請求
@RestController
class HelloController {
@RequestMapping(value="/hello",method=RequestMethod.GET)
public String getHello(){
return "Hello,Spring boot...";
}
}
- QuickstartApplication類
package com.springboot.quickstart;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//啟動主類
@SpringBootApplication
public class QuickstartApplication {
public static void main(String[] args) {
SpringApplication.run(QuickstartApplication.class, args);
}
}
- Book類
package com.springboot.quickstart.entity;
public class Book {
private Integer id;
private String name;
private Double price;
public Book() {
}
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;
}
public Book(Integer id, String name, Double price) {
this.id = id;
this.name = name;
this.price = price;
}
@Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + ''' +
", price=" + price +
'}';
}
}