数据接收

前端通过name对数据进行一个传输,后台名字匹配就可以使用,名字不匹配,可以利用我们的注解进行一个转换;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.saxon.controller;


import com.saxon.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class MyController {
@PostMapping ("/hello")//详相当于servletmappering
public String hello (User user, @RequestParam("age") int a) {
System.out.println (user+"age="+a);
return "Hello";
}
}

**@RequestParam(“age”)**:前端传下来的数据就是我们的name=age的值,前端的数据就是age;如果是对象的话,输出信息的时候,我们的字段名如果匹配的话就会进行一个映射,如果没有的话,就会输出为空;这一个可以让我们省略以前的getParameter 来获取前端数据;