例如:http://localhost:8080/sprsds/index?name=87123
@RequestMapping(value = "/sprsds/index")
@ResponseBody
String eat(@RequestParam("name") String name) {
System.out.println("test");
return name;
}
响应
|—@PathVariable 即:url/id/87123形式 |—@RequestParam 即:url?name=87123形式
package com.example.demo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class index {
@RequestMapping(value = "/sprsds/{name}")
@ResponseBody String eat(@PathVariable("name") String name) {
System.out.println("test");
return name;
}
}
响应
@RequestParam
package com.example.demo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class index {
@RequestMapping(value = "/sprsds/index")
@ResponseBody
String eat(@RequestParam("name") String name) {
System.out.println("test");
return name;
}
}
响应