springmvc controller ajax 一些使用说明
来源:互联网 发布:仓库管理php源码 编辑:程序博客网 时间:2024/05/18 20:36
springmvc中controller方法的参数有多种定义形式,记录并说明几种常用方式
第1种:
RequestMapping(“test1”)
String test1(String userName) {
}
说明:
1)要求方法参数名称和请求传递的参数名完全一致,
2)通过这种方式获取数据时SpringMVC调用了request的getParameterValues方法
3)用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容,提交方式GET、POST
第2种:
RequestMapping(“test2”)
String test2(@RequestParam(“name”) String userName) {
}
说明:
1)和第2种方式相同,只是当方法参数名称和请求传递的参数名称不一致时,可以指定传递的参数名
第3种:
RequestMapping(“test3”)
String test3(User user) {
}
说明:
1)要求方法参数对象中的属性名称和请求传递的参数名完全一致,
2)通过这种方式获取数据时SpringMVC调用了request的getParameterValues方法
3)用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容,提交方式GET、POST
第4种:
RequestMapping(“test4”)
String test4(@RequestBody User user) {
}
说明:
1)用来处理Content-Type: 为 application/json或者xml编码的内容,提交方式GET、POST
2)通过使用HandlerAdapter配置的HttpMessageConverters来解析post data body,然后绑定到相应的bean上
第5种:
RequestMapping(“test5/{id}”)
String test5(@PathVariable(“id”) String id) {
}
说明:
1)获取路径变量
第6种:
RequestMapping(“test6/{id}”)
String test6(Model model1, Map model2, ModelMap model3) {
}
说明:
1)暴露渲染视图需要的模型数据
2)3个变量实际上是同一个对象,使用的时候可以任选其中一种
第7种:
RequestMapping(“test7”)
String test7(HttpServletRequest req, HttpServletResponse res, HttpSession session) {
}
说明:
1)spring在调用方法时会自动给上面方法参数赋值,方法中可以直接使用
Springmvc中controller方法的返回值,常见的两种形式
1)使用ReponseBody返回json对象
2)返回String类型的视图名
3)返回ModelAndView对象
关于Ajax调用时的content-type
1)ajax调用时默认的content-type是 application/x-www-form-urlencoded
2)通过contest-type的设定,可以指定json格式,contentType: “application/json”
3)springmvc中controller方法获取参数的形式,content-type是密切相关的,不同的类型需要采用不同的方法,详见第一部分的说明
- springmvc controller ajax 一些使用说明
- AJAX向springmvc controller提交
- SpringMVC Controller中常用到的一些注解
- jquery + json + springMVC集成在controller中实现Ajax功能
- jquery + json + springMVC集成在controller中实现Ajax功能
- 关于SpringMVC ajax controller 找不到请求的错误
- 关于springmvc的controller返回页面无法跳转,使用ajax
- SpringMVC学习笔记:Ajax与Controller的参数交互
- ajax发送json数据到springmvc的controller
- SpringMVC下,ajax提交数据到Controller方式之一
- springmvc+ajax时controller中return跳转不了前台页面
- springMVC Controller
- SpringMVC--Controller
- SpringMVC Controller
- springMVC - Controller
- SpringMVC-Controller
- SpringMVC Controller
- TPTP Agent Controller使用说明
- 安装oracle12c后,用dbca建数据库老遇到ora-12560错误的解决策
- Leetcode-container-with-most-water
- 键盘移动div样例
- 275. H-Index II
- Spring bean 设值注入和 构造注入
- springmvc controller ajax 一些使用说明
- SimpleNet网络框架源码分析
- 银行家算法的实现,有关进程资源分配的算法
- spring 2 bean配置--基本配置
- java.util.ConcurrentModificationException错误
- com.alibaba.dubbo.rpc.RpcException的解决方法
- JS跨域:1.解决方案之-SpringMVC拦截器
- Urho3D 使用Billboard 设置属性如:enabled/size后,未生效
- 键盘事件