Springframework.data.domain.page.map SpelEvaluationException“无法找到字段”timestamp“的属性..”

时间:2017-05-04 16:32:22

标签: java spring pagination spring-data spelevaluationexception

我尝试实施分页支持。从服务成功获取页面后,我想将其转换为具有给定字符串作为主键的对象。寻呼信息应保留后。

我尝试了以下内容:

Page<String> userIds = studentService.getAllUserIds(pageable);
Page<StudentStatistics> studentStatistics = userIds.map(new Converter<String, StudentStatistics>(){
            @Override
            public StudentStatistics convert(String userId) {
                return answerService.getUserStatistics(userId);
            }
        });

或者:

List<StudentStatistics> studentStatistics = new ArrayList<StudentStatistics>();
    for(String userId : userIds){
        studentStatistics.add(answerService.getUserStatistics(userId));
    }
new PageImpl<>(studentStatistics, pageable, userIds.getTotalElements()));

两者都以异常结束:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242)
    at org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$ExpressionResolver.resolvePlaceholder(ErrorMvcAutoConfiguration.java:279)
    at org.springframework.boot.autoconfigure.web.NonRecursivePropertyPlaceholderHelper$NonRecursivePlaceholderResolver.resolvePlaceholder(NonRecursivePropertyPlaceholderHelper.java:56)
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:147)
    at org.springframework.boot.autoconfigure.web.NonRecursivePropertyPlaceholderHelper.parseStringValue(NonRecursivePropertyPlaceholderHelper.java:38)
    at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
    at org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView.render(ErrorMvcAutoConfiguration.java:217)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) 
...

为什么在这种情况下抛出此异常? Page实体是否具有时间戳属性?

解决这个问题的优雅方法是什么?

亲切的问候

更新:当存储库模块的查询语法出错时,通常会导致spel.SpelEvaluationException错误。如果不使用本机查询,则可以使用Springs查询的Spel功能来处理此错误。

0 个答案:

没有答案