java - 选择实体类中属性的日期格式

标签 java spring-boot spring-data-jpa

我正在使用 Spring Data Jpa ,我想要一个注释来弥补属性上的不足,以选择日期格式。我寻找一些注释,但什么也没找到。 我想要这样的东西:

@Entity 
public class User(){

......(format dd/mm/aa)
private Date birthDay;
}

谢谢。

最佳答案

您可以使用Spring org.springframework.format.annotation.DateTimeFormat,它有多种日期格式。

在您的实体中注释您的birthDay 属性

@Entity 
public class User(){

@DateTimeFormat(pattern="dd/MM/yyyy")
private Date birthDay;
}

关于java - 选择实体类中属性的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57231039/

相关文章:

java - 将 Akka PoisonPill 连接到 actor 系统和 JVM 关闭 Hook

java - Spring Mvc 测试 webapp @Autowired 注释不起作用

java - 使用 Spring Data JPA native 查询在两个日期之间搜索记录?

java - 添加 spring-batch 依赖项时 spring-repository save 不起作用?

java - 自定义存储库基类 + QueryDslPredicateExecutor

java - 将加密的 AES key 导入 Android Keystore 并将其存储在新别名下

java - 学校辅导类请指教

spring-boot - 是否可以为 Spring Boot 应用程序提供 oauth 和基本用户名密码登录选项?

spring-mvc - Spring Boot 提供内容类型错误的静态 .webm 和 .mp4 文件

spring-boot - 在不启用 bean 覆盖的情况下在 Spring Boot 2.1 中连接测试