快速创建项目
![](https://img.haomeiwen.com/i7915418/634dde80f615ffa6.png)
![](https://img.haomeiwen.com/i7915418/ea297a925df29002.png)
![](https://img.haomeiwen.com/i7915418/63302b98757611a2.png)
![](https://img.haomeiwen.com/i7915418/6af2e0a3783efce3.png)
![](https://img.haomeiwen.com/i7915418/a0e87d30b8d878fc.png)
添加web模块
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
![](https://img.haomeiwen.com/i7915418/9d52ffbf7b643506.png)
创建一个demo接口
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
@RestController
public class DemoController {
@RequestMapping("/demo")
public Object demo(String name){
return new HashMap<String,String>(){{put("name",name);}};
}
}
注意controller的位置要和Application同级,(反正不能放下***Applicagtion的上级,不然扫不到)
![](https://img.haomeiwen.com/i7915418/e2bc84338307e2f8.png)
启动项目
![](https://img.haomeiwen.com/i7915418/ad65d8b2dbfa8cb3.png)
访问地址: http://localhost:8080/demo?name=%E5%BC%A0%E9%A3%9E
看到如下图,成功!!!
![](https://img.haomeiwen.com/i7915418/226a08b258dc080c.png)
网友评论