2016-12-05 45 views
0

我認爲從我的Spring Boot應用程序中的Thymeleaf模板轉換到EJS模板(需要在服務器端執行一些JavaScript代碼)。我已經成功地配置好,並使用一些網上的例子創建了我的第一個觀點:如何在EJS模板中使用Spring消息?

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"/> 
    <title>Hello</title> 
</head> 
<body> 
    Hello <%= username %> 
</body> 
</html> 

當我通過這個工程確定從控制器命名爲「用戶名」字符串變量來查看。不過,我希望我的視圖使用靜態文件「/resources/i18n/messages.properties」中的消息。在thymeleaf它被廣泛使用,簡單,可以通過:

th:text="#{messages.hellomessage}" 

如何實現使用EJS同樣的結果?

回答

0

你必須創建一個新的ScriptTemplateViewResolver,並創建一個新的ScriptTemplateConfigurer利用Nashorn支持作爲引擎。

Take a look at this tutorial for an example

+0

這是如何回答我的問題?我的問題是在「.ejs」模板或者「.js」腳本中使用靜態的「messages.properties」文件,就像在jsp中一樣(https://www.mkyong.com/spring-mvc/spring-mvc-internationalization-例如/)或百里香(https://justinrodenbostel.com/2014/05/13/part-4-internationalization-in-spring-boot/)。 Hovewer,感謝您的教程,我會試着問問作者。 –