后台代码
Controller 类
@RestController
public class TestController {
@Autowired
private HttpServletRequest request;
@PostMapping("/hello")
public String helloworld(@RequestBody User<Student> user) {
System.out.println(user.getName()+" "+user.getAge()+" "+user.getParam().getNumber()+
" "+user.getParam().getClassName());
return "index";
}
}
实体类结构
public class User<T> {
private String name;
private int age;
T param;
}
前端数据传递
var str = JSON.stringify( {name:"张三" , age : 15 , param : {number : "1000" , className : "1班"}} );
$.ajax({
url : "http://localhost:88/hello/hello",
type : "post",
contentType: 'application/json',
data: str,
});
网友评论