@PathVariable
package com.test.demo;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class hello {
/**
*@author pxChen
*@date 2019/6/11 10:56
*/
@RequestMapping(value = "/test/{id}/{name}", method = RequestMethod.GET)
public String say(@PathVariable("id") Integer id, @PathVariable("name") String name) {
return "id:"+id+";name:"+name;
}
}
@RequestParam
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String msg(@RequestParam("name") String name, @RequestParam("msg") String msg) {
return name+" say: "+msg;
}
@RequestBody(傳遞JSON數據)
@PostMapping("/show")
public String show(Person person) {
return "id:"+person.getId()+";name:"+person.getName();
}