Spring Boot中路由传递参数
在路由时传递参数,一般有两种形式,一种是拼接在url地址中,另一种是查询参数。如:http://localhost:8080/router/tang/101?type=spor&num=12。下面根据代码看一下,VUE 和 Spring Boot 中各自是如何处理传递和接受参数的。Spring Bootpackage com.tang.demo1.controller;import
·
在路由时传递参数,一般有两种形式,一种是拼接在url地址中,另一种是查询参数。如:http://localhost:8080/router/tang/101?type=spor&num=12。下面根据代码看一下,VUE 和 Spring Boot 中各自是如何处理传递和接受参数的。
Spring Boot
-
package com.tang.demo1.controller;
-
-
import org.springframework.web.bind.annotation.*;
-
-
-
public class RouterController {
-
-
"/router/{name}/{classid}"}, method = RequestMethod.GET)(path = {
-
public String router(@PathVariable("name") String name
-
,@PathVariable("classid") int classid
-
,@RequestParam(value = "type", defaultValue = "news") String type
-
,@RequestParam(value = "num", required = falsef) int num){
-
-
// 访问 http://localhost:8080/router/tang/101?type=spor&num=12
-
return name + classid + type + num;
-
}
-
}
在url路径中的参数,被称为pathVariable,查询参数被称为requestParm。在controller中接受参数,可以直接在方法里用了。
更多推荐
所有评论(0)