spring mvc controller可以用Map接收jsp传来的值么???jsp怎么写,controller又怎么写??请求大神指教
@RequestMapping("/我是路径/我是方法")
public String 我是方法(String 我是参数, ModelMap map)throws Exception{
map.put("我是参数", 我是参数);
return "/我是啥啥啥";
}
这样的么?我也新手
我想要的是这种的 public String 我是方法(Map 我是参数, ModelMap map)throws Exception{
或者是public String 我是方法(Page<实体> 我是参数, ModelMap map)throws Exception{
Page是我写的一个分页
那样的话,在前台就要把参数组织好
jsp map.name 后台直接map接
实体类写了么 map也写成个对象 然后前台传值封装成对象试试
map没有用过,用了这么久的springMVC传值,用得最多的就是绑定实体类,也就是你的entity(bean),这样返回错误也简单,可以上一个例子:
jsp页面如RedPacket类有一个属性叫做name,那么可以,提交表单自动封装。
@RequestMapping(value="/create", method = RequestMethod.POST)
public String create(@Valid RedPacket redPacket,BindingResult result,Model model) {
if(........){
result.reject("errStatus", "非法的状态");
}
if(..........){
result.reject("errType", "非法红包类型");
}
前台用的是freemarker ${errStatus?default('')}接受,如果你参数实在是多又不能与entity匹配,直接放一个HttpServletRequest也不错
,虽然原始了点。model参数可以addAttribute(String type,Object value),类似于request.setAttribute方法,没必要用Map,实在是想,那也没办法
springmvc 接受 map类型的参数
spring mvc 值传递:
利用Map可以实现 无需依赖实体对象加载多个不同类型的参数
Jsp页面正常的封装数据 :
例如:
Controller层可以接受的参数
@RequestMapping("/Test")
Test(@RequestParam Map map){
String name = map.get("name");
String text = map.get("user");
String password = map.get("password");
}
可以解决查询条件不是同一个实体对象,查询参数比较多,不适合统一传递到后台方法上进行接受。可以通过这样来接受参数。