Spring Boot文集系列

Spring Boot的第一个起步练习

2019-03-19  本文已影响0人  tmac09

新建一个quickstart项目

过程:

file-new-project-Empty-quickstart和F:\SpringBootStudy-finish

自动跳入以下图片

pox.xml的包

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

第一个练习

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 +

'}';

}

}

上一篇下一篇

猜你喜欢

热点阅读