官网quick-start系列:https://projects.spring.io/spring-boot/#quick-start
1、编码环境:jdk版本1.8、intellij idea版本2016.2.5、gradle版本3.2
2、新建项目
项目的build.gralde配置如下:
group 'org.changs'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile("org.springframework.boot:spring-boot-starter-web:1.5.7.RELEASE")
testCompile("org.springframework.boot:spring-boot-starter-test:1.5.7.RELEASE")
}
3、添加Application入口函数
package org.changs.learn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
4、添加示例接口:
package org.changs.learn.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by yincs on 2017/1/9.
*/
@RestController
public class HelloController {
@RequestMapping("hello")
public String hello() {
return "hello spring-boot";
}
}
5、运行Application类的main函数,启动成功后用浏览器访问http://localhost:8080/hello。页面上出现hello spring-boot!
ok!初步搭建已完成。

本文介绍如何使用Spring Boot搭建一个简单的Web应用,包括环境配置、项目创建、添加控制器及运行测试等步骤。
&spm=1001.2101.3001.5002&articleId=54293498&d=1&t=3&u=53a952c04ac84405b346f45000b57d24)
1万+

被折叠的 条评论
为什么被折叠?



