使用eclipse工具新建一个maven项目,在项目的pom.xml文件加入spring-boot-starter-web依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
这样marvn会自动帮我们下载好相关的依赖包
接下编定一个简单的控制器
import java.util.Calendar;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class SpringController {
@RequestMapping(value="/helloword")
public helloword() {
return "hello word!";
}
}
当用户访问 localhost:8080/helloword时会返回一个hello word
编写spring boot 启动类
package com.ch14.springtest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* Hello world!
*
*/
@SpringBootApplication
public class App
{
public static void main( String[] args ) {
new SpringApplicationBuilder(App.class).run(args);
}
}
使用了@SpringBootApplication注解来标识这是一个spring boot的启动类. 直接在ele工具中运行就开始启动了spring boot
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
这样marvn会自动帮我们下载好相关的依赖包
接下编定一个简单的控制器
import java.util.Calendar;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class SpringController {
@RequestMapping(value="/helloword")
public helloword() {
return "hello word!";
}
}
当用户访问 localhost:8080/helloword时会返回一个hello word
编写spring boot 启动类
package com.ch14.springtest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* Hello world!
*
*/
@SpringBootApplication
public class App
{
public static void main( String[] args ) {
new SpringApplicationBuilder(App.class).run(args);
}
}
使用了@SpringBootApplication注解来标识这是一个spring boot的启动类. 直接在ele工具中运行就开始启动了spring boot