基础类型
原始类型:id必须要传,否则报错。
1 | ("/test") |
包装类型:id可以不传,后台接受到null。
1 | ("/test") |
list&set
简单类型
前台
form表单
1 | <form action="${ctx}/test/test" method="post"> |
ajax
1 | var data = []; |
后台
1 | ("/test") |
复杂类型
如list<User>users:(略)同json格式对象
数组
前台
form表单
1 | <form action="${ctx}/test/test" method="post"> |
ajax
1 | var data = []; |
后台
1 | ("/test") |
map
前台
form
1 | <form action="${ctx}/test/test" method="post"> |
ajax
1 | var data = {name:"zhangsan",sex:"man"}; |
后台
1 | ("/test") |
pojo简单属性
前台
form
1 | <form action="${ctx}/test/test" method="post"> |
ajax
1 | var data = {name:"zhangsan",sex:"man"}; |
后台
1 | ("/test") |
pojo包含list
前台
form
1 | <form action="${ctx}/test/test" method="post"> |
ajax
1 | var user={userName:"zhangsan",password:"123"}; |
后台
1 | public class User{ |
date类型
使用注解方式
绑定单个方法
对于传递参数为Date类型,可以在参数前添加@DateTimeFormat注解。如下:
1 | ("/test") |
如果传递过来的是对象,可以在对象属性上添加注解。
1 | ("/test") |
绑定整个controller的所有方法:
1 |
|
使用PropertyEditor方式
使用ConversionService方式
参考:
https://www.2cto.com/kf/201501/374062.html
https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-initbinder
枚举类型
mvc配置文件添加:
1 | <!--枚举类型转化器--> |
参考:
json格式对象
后台
1 | (value = "introductionData.do", method = {RequestMethod.POST}) |
前台
1 | var data = {} |
