我使用这样无法传入
我们直接写List是会报错的,因为springmvc不知道怎么初始化list对象,因此它是会报错的
这个时候可以借助加一层模型,因为第一层(方法参数),是直接调用class的实例化来初始化的。
另外可以改用数组,比如
或者直接用list的子类
@requestMapping("/test")
public String getTest(List<User> users){
return "test";
}
我们直接写List是会报错的,因为springmvc不知道怎么初始化list对象,因此它是会报错的
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:102)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:81)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:104)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:684)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
这个时候可以借助加一层模型,因为第一层(方法参数),是直接调用class的实例化来初始化的。
E{
List<F> flist;
getter/setter;
}
Controller{
public execute(E e){
List<F> list = e.getFlist(); ---
}
}
另外可以改用数组,比如
Controller{
public execute(String[] es){
}
}
或者直接用list的子类
@RequestMapping(value = "/classify/listTreeAndSelect.html")
public void listAndSelect(HttpServletRequest request, ModelMap model,
UnifiedUser user,ArrayList<Long> selectIds) {
}