方式①通过URL传参
只要后端处理请求的⽅法中,存在参数,键同名属性,在请求的过程中 Spring 会⾃动将参数值,赋值到属性中,最后在⽅法中直接⽤即可。
–通过URL传参:
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(String name) {
return "hello world,"+name;
}
}