Meaven搭建springboot项目

1.创建一个简单的maven project项目

 

2.项目目录结构

**注意启动类的位置:

 

3.pom.xml 配置jar包

 

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/>
</parent>
  
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>  
View Code

4、创建一个SpringBoot项目运行的启动类

 

package com.lxp.Application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

5、创建一个controller(@Controller只返回页面;@RestController返回json格式的数据)

package com.lxp.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWordController {

    @RequestMapping("hello")
    public String hello() {

        return "HelloWord";
    }

}
View Code

6.查看效果

 

posted @ 2019-02-22 15:14  学海无涯皆比邻  阅读(417)  评论(0编辑  收藏  举报