1、file-new-project-Spring Initializr-next:输入项目信息-next:web-next-finish
2、创建controller包
3、创建StudyController类
@RestController
@RequestMapping
public class StudyController {
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(@RequestParam(value = "userName") String userName){
return userName;
}
}
4、访问http://localhost:8080/test?userName=a
备注:如果pom文件有问题
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> 修改为 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>