Java 常用的数据类型: https://blog.csdn.net/zhangyong01245/article/details/101310236
Mysql 常用的数据类型: https://blog.csdn.net/zhangyong01245/article/details/101157289
Mysql | jdbcType | Java |
---|---|---|
tinyint | TINYINT | Integer |
int | INTEGER | Integer |
integer | INTEGER | Integer |
bigint | BIGINT | Long |
float | FLOAT | Float |
double | DOUBLE | Double |
decimal | DECIMAL | BigDecimal |
char | CHAR | String |
varchar | VARCHAR | String |
varchar | VARCHAR | String |
datetime | TIMESTAMP | Date |
timestamp | TIMESTAMP | Date |
在接受 Mysql 的结果类型也不是一定的,大类型可以接受小类型,高精度也接受低精度的 。
创建一张表 tb_example:
CREATE TABLE `tb_example` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`tinyint_column` tinyint(4) NOT NULL COMMENT 'tinyint',
`int_column` int(11) NOT NULL COMMENT 'int',
`integer_column` int(11) NOT NULL COMMENT 'integer',
`bigint_column` bigint(20) NOT NULL COMMENT 'bigint',
`float_column` float(5,2) NOT NULL COMMENT 'float',
`double_column` double(5,1) NOT NULL COMMENT 'double',
`decimal_column` decimal(2,1) NOT NULL COMMENT 'decimal',
`char_column` char(1) NOT NULL COMMENT 'char',
`varchar_column` varchar(10) NOT NULL COMMENT 'varchar',
`text_column` text NOT NULL COMMENT 'text',
`date_column` date NOT NULL COMMENT 'date',
`datetime_column` datetime NOT NULL COMMENT 'datetime',
`timestamp_column` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'timestamp',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='测试例子表';
定义 Example:
public class Example implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Byte tinyintColumn;
private Integer intColumn;
private Integer integerColumn;
private Long bigintColumn;
private Float floatColumn;
private Double doubleColumn;
private BigDecimal decimalColumn;
private String charColumn;
private String varcharColumn;
private Date dateColumn;
private Date datetimeColumn;
private Date timestampColumn;
private String textColumn;
// 省略 Get 、Set 方法
}
ExampleMapper.xml 中 result Map 定义:
<resultMap id="BaseResultMap" type="com.morning.all.entity.Example" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="tinyint_column" property="tinyintColumn" jdbcType="TINYINT" />
<result column="int_column" property="intColumn" jdbcType="INTEGER" />
<result column="integer_column" property="integerColumn" jdbcType="INTEGER" />
<result column="bigint_column" property="bigintColumn" jdbcType="BIGINT" />
<result column="float_column" property="floatColumn" jdbcType="FLOAT" />
<result column="double_column" property="doubleColumn" jdbcType="DOUBLE" />
<result column="decimal_column" property="decimalColumn" jdbcType="DECIMAL" />
<result column="char_column" property="charColumn" jdbcType="CHAR" />
<result column="varchar_column" property="varcharColumn" jdbcType="VARCHAR" />
<result column="date_column" property="dateColumn" jdbcType="DATE" />
<result column="datetime_column" property="datetimeColumn" jdbcType="TIMESTAMP" />
<result column="timestamp_column" property="timestampColumn" jdbcType="TIMESTAMP" />
</resultMap>
END !!!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/179900.html原文链接:https://javaforall.cn