在 spring mvc + mybatis + mysql
数据表
CREATE TABLE `test_jdbc_java_type` (
`id` int(11) NOT NULL,
`_char` char(50) DEFAULT NULL,
`_varchar` varchar(200) DEFAULT NULL,
`_numeric` decimal(10,2) DEFAULT NULL,
`_decimal` decimal(10,2) DEFAULT NULL,
`_bit` bit(1) DEFAULT NULL,
`_tinyint` tinyint(4) DEFAULT NULL,
`_smallint` smallint(6) DEFAULT NULL,
`_integer` int(11) DEFAULT NULL,
`_bigint` bigint(20) DEFAULT NULL,
`_real` double DEFAULT NULL,
`_float` float DEFAULT NULL,
`_double` double DEFAULT NULL,
`_binary` binary(255) DEFAULT NULL,
`_varbinary` varbinary(255) DEFAULT NULL,
`_date` date DEFAULT NULL,
`_time` time DEFAULT NULL,
`_timestamp` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`_blob` blob,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
数据
INSERT INTO `test_jdbc_java_type` VALUES (1, 'char类型', 'varchar类型', 11.00, 22.00, '', 1, 1, 1, 1, 1, 1, 1, NULL, NULL, '2017-4-14', '11:17:43', '2017-4-14 11:17:33', NULL);
xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hqpe.itm.dao.user.UserDao">
<select id="getData" resultType="Map">
SELECT (SELECT 1 ) _num ,1 _num2,t.* FROM `test_jdbc_java_type` t
</select>
</mapper>
java代码
package com.hqpe.itm.controller.account;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.sql.Time;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.hqpe.itm.dao.user.UserDao;
@Controller
@RequestMapping("/jdbcjava")
public class TestJdbcJavaType
{
@Resource
private UserDao userDao;
@RequestMapping("test")
public void test(Model model) {
List<Map<String,Object>> list = userDao.getData();
for(Map<String,Object> map: list){
int id = (Integer)map.get("id");
long _num = (Long)map.get("_num");
long _num2 = (Long)map.get("_num2");
String _char= (String)map.get("_char");
String _varchar= (String)map.get("_varchar");
BigDecimal _numeric= (BigDecimal)map.get("_numeric");
BigDecimal _decimal= (BigDecimal)map.get("_decimal");
boolean _bit= (Boolean)map.get("_bit");
int _tinyint= (Integer)map.get("_tinyint");
int _smallint= (Integer)map.get("_smallint");
int _integer= (Integer)map.get("_integer");
long _bigint= (Long)map.get("_bigint");
double _real= (Double)map.get("_real");
float _float= (Float)map.get("_float");
double _double= (Double)map.get("_double");
//Byte[] _binary= (Byte[])map.get("_binary");
//Byte[] _varbinary= (Byte[])map.get("_varbinary");
Date _date= (Date)map.get("_date");
Time _time= (Time)map.get("_time");
Timestamp _timestamp= (Timestamp)map.get("_timestamp");
//Blob _blob= (Blob)map.get("_blob");
System.out.println(id);
System.out.println(_num);
System.out.println(_num2);
System.out.println(_char);
System.out.println(_varchar);
System.out.println(_numeric);
System.out.println(_decimal);
System.out.println(_bit);
System.out.println(_tinyint);
System.out.println(_smallint);
System.out.println(_integer);
System.out.println(_bigint);
System.out.println(_real);
System.out.println(_float);
System.out.println(_double);
//System.out.println(_binary);
//System.out.println(_varbinary);
System.out.println(_date);
System.out.println(_time);
System.out.println(_timestamp);
//System.out.println(_blob);
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
}
}
}