中秋节的网页制作模板,快手seo,南山优化网站建设案例,导航网站搭建1、GET查询串传参#xff1a; 2、RESTFul形式传参#xff08;参数少#xff09; 3、form表单传参 4、混合传参#xff0c;查询串表单 5、终极王者#xff0c;json传参#xff08;参数多#xff09;
package com.book.admin.controller;import com.book.admin.entity.Us…1、GET查询串传参 2、RESTFul形式传参参数少 3、form表单传参 4、混合传参查询串表单 5、终极王者json传参参数多
package com.book.admin.controller;import com.book.admin.entity.User;
import org.springframework.web.bind.annotation.*;import java.util.Date;
import java.util.Random;/*** version v1.0 创建时间8:52* author: 作者陈子枢* web CSDNhttps://blog.csdn.net/nutony* description 描述回顾SpringMVC如何接收参数以及POSTMAN测试。*/
RestController
public class ParamController {//1、GET查询串传参//请求http://localhost:6060/user/show?namechenage28GetMapping(/user/show)public User show(String name, Integer age){User user new User();user.setName(name);user.setAge(age);return user;}//2、RESTFul形式传参参数少//请求http://localhost:6060/user/add/wang/16GetMapping(/user/add/{name}/{age})public User get(PathVariable String name, PathVariable Integer age){Integer id new Random().nextInt(101); //0~100User user new User();user.setId(id);user.setName(name);user.setAge(age);user.setCreated(new Date());return user;}//3、form表单传参PostMapping(/user/form)public User form(RequestParam String name, RequestParam Integer age){User user new User();user.setName(name);user.setAge(age);return user;}//4、混合传参查询串表单PostMapping(/user/mix)public String form(RequestParam String title, ModelAttribute User user){return {title:title,user.toString()};}//5、终极王者json传参参数多PostMapping(/user/add)public User get(RequestBody User user){Integer id new Random().nextInt(101); //0~100user.setId(id);user.setCreated(new Date());return user;}
}