1、最基本的“/name”,用@RequestBody
//在Body里放参数
//可以是json{"":"",……}
@Controller
@ResponseBody
@RequestMapping("/classmapping")
public class WarningController {
@RequestMapping(value = "/mapping", method = RequestMethod.POST)
public void fun(@RequestBody JsonObject jo, HttpServletRequest request) {
//TODO
//String time = jo.get("time").getAsString();
}
}
2、“/abc/{name}”,@PathVariable获取{name}
{ }是直接在url里输入相应的值,如***/abc/garfield
@RequestMapping(value = "/login/{admin}",method = RequestMethod.GET)
public Object logout(@PathVariable(value = "admin") String name,
@RequestParam(value = "loginName",required = false) String loginName) {
//name loginName直接用
return *;
}
3、“/task?id=xxx”
获得GET请求参数用@RequestParams
params: id xxx
//获取租户任务执行状态
@RequestMapping(value = "/task", method = RequestMethod.GET)
public Object getTenantTaskState(@RequestParam("id") int taskId) {
//TODO
}
获得GET请求参数用@RequestParams
//可以是json{"":"",……}
几种HTTP url应用
最新推荐文章于 2024-03-27 22:10:27 发布