spring boot 传参
spring boot 中的Controller或者RestController接收参数的方法是一样的。这章目标是对几种常用的传参都写个例子。
创建package: com.biboheart.demos.api,这个包里放置API接口的RestController
在com.biboheart.demos.api包中创建一个class: ParamController。这章的示例都在这个类中进行。
PathVariable
路径中包含参数,这种情况适合与传递一个不能为空值的参数。比如有些应用中,查询某个企业的数据,必须包含企业的编号,就可以在地址里接收这个编号。
在ParamController中增加一个函数PathParam
package com.biboheart.demos.api;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ParamController {
@RequestMapping(value = "/demo/param/path/{sn}")
public String pa