2017-04-05 4 views
0

私のApplicationAdviceクラスからcurrentUserを取得し、中:Thymeleafの画像src + ParseException:例外:SpringEL式の評価: "currentUser.get( 'profilePicture')。get( 'url')"

@ModelAttribute("currentUser") 
public TmtUser currentUser(Model model) { 

    TmtUser currentUser = TmtUser.currentUser; 
    model.addAttribute("currentUser", currentUser); 

    return currentUser; 
} 

currentUserオブジェクトは、それが利用可能なurl属性を持っています。しかし、私はページにURLをレンダリングするエラーを取得しています。おそらく、url値が提供される前にDOMがレンダリングされるでしょうか?どうすればわかるのですか?

HTML:

<img th:src="${currentUser.get('profilePicture').get('url')}" src="" /> 

例外:

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "currentUser.get('profilePicture').get('url')" (template: "fragments/header" - line 72, col 139) 
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.2.RELEASE.jar:2.0.2.RELEASE] 
    at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.2.RELEASE.jar:2.0.2.RELEASE] 
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE] 
    ... 105 common frames omitted 

オブジェクトモデル:

enter image description here

ブラウザのコンソールエラー:構文解析ファイル自体がブラウザにロードされていないよう

[email protected] Failed to load resource: the server responded with a status of 404() 

は思えます。

答えて

1

この表現はどういう意味ですか?

currentUser.get('profilePicture').get('url') 

currentUserオブジェクトには次のようなメソッドがありますか?

public class TmtUser { 
    public Map<String, Object> get(String key) { 
     ... 
     ... 
    } 
} 

これは、あなたがしているように見えるためです。しかし、あなたのオブジェクトの画像によれば、そのようなものはありません。これらの式を作成するときは、Javaでどのように見えるか考える必要があります。たとえば、Javaでそれは次のようになりますので、私は構文解析ファイルに慣れていないよcaviatで(

${currentUser.data['profilePicture'].url} 
or 
${currentUser.data.get('profilePicture').url} 

式に翻訳
currentUser.getData().get("profilePicture").getUrl() 

を、それは次のようになります。 URLプロパティの取得と設定があるかどうかはわかりません)

関連する問題