内容简介:Hibernate Types是Hibernate默认不支持的一组额外类型。其中一种类型是java.time.YearMonth。这里展示一个Spring Boot应用程序,说明是如何使用关键点:源代码可以在
Hibernate Types是Hibernate默认不支持的一组额外类型。其中一种类型是java.time.YearMonth。这里展示一个Spring Boot应用程序,说明是如何使用 Hibernate Type 将YearMonthMySQL数据库存储为整数或日期。
关键点:
-
对于Maven,将Hibernate Types添加为依赖项pom.xml
<dependency> <groupId>com.vladmihalcea</groupId> <artifactId>hibernate-types-52</artifactId> <version>2.3.5</version> </dependency>
-
在实体中,用@TypeDef映射typeClass到defaultForType
@Entity @TypeDef( typeClass = YearMonthIntegerType.<b>class</b>, <font><i>// or, YearMonthDateType</i></font><font> defaultForType = YearMonth.<b>class</b> ) <b>public</b> <b>class</b> Royalty implements Serializable { <b>private</b> <b>static</b> <b>final</b> <b>long</b> serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) <b>private</b> Long id; <b>private</b> <b>float</b> amount; <b>private</b> YearMonth payedOn; </font>
源代码可以在 这里 找到
以上所述就是小编给大家介绍的《如何在Hibernate将java.time.YearMonth类型存储为整数或日期》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 989-数组形式的整数加法
- leetcode刷题-----7. 整数反转
- Python 2.7 源码 - 整数对象
- c# – 为负整数返回零
- 深入理解动态规划算法:凑整数
- 剑指offer 16——数值的整数次方
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Mining
Jiawei Han、Micheline Kamber、Jian Pei / Morgan Kaufmann / 2011-7-6 / USD 74.95
The increasing volume of data in modern business and science calls for more complex and sophisticated tools. Although advances in data mining technology have made extensive data collection much easier......一起来看看 《Data Mining》 这本书的介绍吧!