post请求,ie9之前版本都不支持,兼容不了post请求。
get请求,路径长度最大255。路径后面?传参却可以很长很长,所以为了兼容老ie,我们用了这种方式。
今天讲讲java后台注解如何接收这些get,post请求参数:
1.get请求,路径直接传参,没有key
后台接收:-------------------------------
@RequestMapping(value = "/info/{loginKey}", method = RequestMethod.GET)
public WrappedResult info(@PathVariable String loginKey) {
try {
2. get请求,问号?传参
前台请求:-------------------------------
jQuery.support.cors = true;//配置IE9及以下浏览器支持cors跨域ajax访问
var restClient = new RESTClient();
restClient.authorization = cube.authorization('userServer');
var params = "{\"items\":[{\"uname\":\""+nuser+"\",\"pass\":\""+npass+"\",\"type\":\"2\",\"code\":\""+yz+"\"}]}";
restClient.post(cube.baseUrl('userServer')+"/user/login",params,function(data){
if(data.successful){
var loginJson = data.resultValue;
后台接收:-------------------------------
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(
@RequestParam("uname") String uname,
@RequestParam("pass") String pass,
@RequestParam("code") String code,
@RequestParam("type") String type) {
3.post请求,后台注解@RequestBody (这个是post特有的,get不能用)接收,
前台请求:-------------------------------
// 用户登录后台交接
var params="{\"items\":[{\"userSfz\":\""+nuser+"\",\"pass\":\""+npass+"\",\"answer\":\""+mba+"\",\"code\":\""+yzm+"\"}]}";// 直接传到后台查询方法
restClient.post(cube.baseUrl("userServer")+"/user/findPass/",params,function(data) {
console.log(data.successful)
if(data.successful){
后台接收:-------------------------------
@RequestMapping(value = "/findPass", method = RequestMethod.POST)
public WrappedResult findPass(@RequestBody FormRequestObject