简单快速的搭建springboot项目

以前一直用的ssm,由于新公司用的springboot,看了一些文档,觉得确实很好用,下面就简单说下搭建的过程:

1.新建maven项目。这个应该都会就不多说了。

  2.在pom.xml文件添加以下内容

<!-- 11   spring-boot 父引用 -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>
   
   
  <dependencies>
  <!-- 11   spring-boot 核心依赖 -->
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
 </dependencies>

3.编写springboot的入口文件(报错的话,可以maven update 试试,)

@SpringBootApplication
public class Main {
 
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
     
}

4.可以在resources文件夹下新建application.properties

server.port=9002  //访问端口

5. 此时springboot项目搭建完成,启动入口类Main,就看到控制台的启动日志。

      6. 浏览器输入 localhost:9002/ 访问

         会发现报错:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 10 15:22:09 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

 注意:这只是404,页面找不到而已。 

  7. 新建controller

2

3

4

5

6

7

8

@RestController

@RequestMapping("test")

public class TestController {

    @RequestMapping(value = "hh",method = RequestMethod.GET)

    public String test(){

        return "hello123";

    }

}

8. 重启项目,再次访问 http://localhost:9002/test/hh

    就会看到浏览器内容显示如下:

hello123

 至此一个springboot及测试controller搭建完成。 

猜你喜欢

转载自blog.csdn.net/waitu88/article/details/82591629