使用VarArgs的方法首先从JSP调用

时间:2019-06-04 08:15:25

标签: java jsp variadic-functions

我有 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;
    }
  • 在notAllowedToAddGameUsers对象中,我有一个字符串,其中列出了用户的所有角色。就我而言,它看起来像: '-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参数调用方法。 所以我想了解为什么会发生此错误。

0 个答案:

没有答案