我有 User 类,该类具有重载的方法:
public boolean checkAccessAvoid(Role... groups) {
...
}
public boolean checkAccessAvoid(String string) {
...
}
控制器:
@RequestMapping(method = RequestMethod.GET, value = "list")
public ModelAndView list(...) {
ModelAndView mav = new ModelAndView();
mav.addObject("user", Session.getUser());
mav.addObject("notAllowedToAddGameUsers", AccessUtils.GroupArrayToString(Permission.MAIN_GAME_NOT_ALLOWED_TO_ADD_GAME));
mav.setViewName("home");
return mav;
}
'-Guest-GameDeveloper-GameQA-TechnicalWriter'
home.jsp :
<c:set var="test" value="${user.checkAccessAvoid(notAllowedToAddGameUsers)}" />
<% System.out.println( "result = " + pageContext.findAttribute("test") ); %>
问题是当我尝试获取清单时遇到错误:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw exception [An exception occurred processing JSP page /WEB-INF/views/home.jsp at line 26
26: <c:set var="test" value="${user.checkAccessAvoid(notAllowedToAddGameUsers)}" />
27: <% System.out.println( "result = " + pageContext.findAttribute("test") ); %>
javax.el.ELException: Cannot convert '-Guest-GameDeveloper-GameQA-TechnicalWriter' of type class java.lang.String to class com.domain.enums.Role
我试图将varargs参数更改为array并成功了,但是在很多地方,使用Role type参数调用方法。 所以我想了解为什么会发生此错误。