我有一个使用服务器端Mustache-Templates(JMustache)的Spring启动应用程序。
一个带有@DateTimeFormat
- 注释的简单Bean:
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
public class GeneralInformation {
private Date serverTime = new Date();
@DateTimeFormat(pattern="dd.MM.yyyy")
public Date getServerTime() {
return serverTime;
}
public void setServerTime(Date serverTime) {
this.serverTime = serverTime;
}
}
将bean添加到模型的简单控制器:
@Controller
@RequestMapping(value="/")
public class RootController {
// some Autowiring stuff here...
@RequestMapping(value="")
public String index(Model model){
model.addAttribute("generalInformation", new GeneralInformation());
return "hello";
}
}
我的服务器端Mustache模板存储在templates/hello.html
<p>Servertime: {{generalInformation.serverTime}}</p>
使用JSP时,日期的输出格式化为@DateTimeFormat
- 注释中使用的模式,但不是在使用我的胡子模板时。
我可以在@Controller
- Annotated-Method中格式化日期并将其存储为Bean中的String
,但这似乎不是一个好方法。
有人知道,是否可以让JMustache知道验证标签?
与SpringMVC一起使用JMustache时,我还能如何实现格式化?
答案 0 :(得分:-1)
@DateTimeFormat仅适用于JSP