spring-boot web 简单的搭建

pom.xml

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.8.RELEASE</version>
</parent>

<dependencies>
  <!--web依赖开始 -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
</dependencies>

启动类建议放在根目录下

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * @Author sunli
 * @Date 2018/8/15 10:51
 */

@SpringBootApplication
@EnableWebMvc//开启web
public class Starter {
    public static void main(String[] args) {
        SpringApplication.run(Starter.class,args);
    }
}
控制层controller类
package com.ssdz.com.sddz.controller;

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

/**
 * @Author sunli
 * @Date 2018/8/15 10:55
 */

@RestController
public class TestController {         //解决乱码的一种方式
    @RequestMapping(value = "/test" ,produces="application/json;charset=UTF-8")
    public String home() {
        System.out.println("springboot项目启动成功!");
        return "springboot项目启动成功!";
    }
}

猜你喜欢

转载自blog.csdn.net/qq_38432390/article/details/81700853