在经历了之前开发的大量代码之后,我意识到我需要移动所有基于金钱的列以不使用 float 学。在 Java 方面,这意味着使用 BigDecimal,但是当使用 Hibernate/JPA 和 MySQL 5 时,生成该列的适当 MySQL 数据类型是什么?
最佳答案
十进制和数字。
The recommended Java mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal. The
java.math.BigDecimal
type provides math operations to allow BigDecimal types to be added, subtracted, multiplied, and divided with other BigDecimal types, with integer types, and with floating point types.The method recommended for retrieving DECIMAL and NUMERIC values is ResultSet.getBigDecimal. JDBC also allows access to these SQL types as simple Strings or arrays of char. Thus, Java programmers can use getString to receive a DECIMAL or NUMERIC result. However, this makes the common case where DECIMAL or NUMERIC are used for currency values rather awkward since it means that application writers have to perform math on strings. It is also possible to retrieve these SQL types as any of the Java numeric types.
看看here了解更多详情。
关于java - 你会在 MySQL 中映射 Java/Hibernate 中的 BigDecimal 什么类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550337/