美文网首页
3.Spring Boot的第一个起步练习

3.Spring Boot的第一个起步练习

作者: 六年的承诺 | 来源:发表于2019-03-18 20:33 被阅读0次

    新建一个quickstart项目
    过程:
    file-new-project-Empty-quickstart和F:\SpringBootStudy-finish
    自动跳入以下图片


    11.png

    点加号+,选中以下的东西


    9.png
    QQ截图20190318083540.png
    然后什么都不用选,看路径,最后finish

    建以下的包


    12.png

    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 +
    '}';
    }
    }

    相关文章

      网友评论

          本文标题:3.Spring Boot的第一个起步练习

          本文链接:https://www.haomeiwen.com/subject/wufimqtx.html