springboot helloworld
idea下新建一个普通maven项目:
1.sprintboot父节点添加<parent>依赖包如下,<parent>好处,一旦添加version后,之后的depends依赖不需要在配置version,springboot会自行选择:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
在添加如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
//start-web,集成了springmvc,AOP的依赖包
新建HelloController
package com.example.sprintboot; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/hello") public String hello(){ return "hello"; } }
@RestController将函数return值转成字符串形式输出:
@RequestMapping("/hello")定义方法的访问路径。
至此hello教程结束。

浙公网安备 33010602011771号