params势就、form-data 都可以使用get、post發(fā)送
package com.xinyue.one;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/user")
public class UserController {
@RequestMapping("/hello")
public String hello(){
return "你好我的中國(guó)????";
}
@RequestMapping("/name")
public String getName(){
User user = new User();
user.setId(1);
user.setName("心飛");
return user.getName();
}
@RequestMapping("/name1")
public String getName1(@RequestParam("name") String name){
/**
* http://127.0.0.1:8080/user/name1?name=英雄聯(lián)盟
* params 使用get脉漏、post都可以發(fā)送
*/
return name;
}
@RequestMapping(value = "/par1", method = RequestMethod.GET)
public String reqPar1(@RequestParam("name") String name){
return name;
}
@RequestMapping(value = "/par2", method = RequestMethod.GET)
public String reqPar2(@RequestParam(value = "name", required = false) String name){
if(null != name){
return name;
}else{
return "未傳入?yún)?shù)";
}
}
@RequestMapping(value = "/par3", method = RequestMethod.GET)
public String reqPar3(@RequestParam(value = "name", defaultValue = "心悅飛飛") String name){
return name;
}
@RequestMapping(value = "/par4/{id}", method = RequestMethod.GET)
public Integer reqPar4(@PathVariable("id") Integer id){
return id;
}
@RequestMapping(value = "/{id}/par5", method = RequestMethod.GET)
public Integer reqPar5(@PathVariable("id") Integer id){
return id;
}
@RequestMapping(value = "/par6/{name}", method = RequestMethod.GET)
public String reqPar4(@PathVariable("name") String name){
return name;
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者