工做须要使用mybatis generator,另外Oracle和mybatis也没有作过深刻的了解,只是能用会写业务代码,不报错就能够了。html
废话,割------------------------------------------------------------------------------------------------------------------------------------java
在使用Oracle+mybatis作sql查询时,发现查询出来的结果只精确到年月日,由于mybatis的orm映射由mybatis generator来作的,因此本身觉得在哪一个地方业务代码转换是出了错,Debug的时候才发现出错的是sql查询。sql
其中一点在网上找到了(http://www.soso.io/article/72293.html),文章中提到:网络
mybatis jdbcType: DATE ,TIMESTAMP 区别: mybatis
1. mybatis中 jdbcType 时间类型spa
当jdbcType = DATE 时, 只传入了 年月日code
jdbcType = TIMESTAMP , 年月日+ 时分秒orm
2. jdbcType 是否必须:htm
使用时, 没有加jdbcType 正常, blog
加上jdbcType缘由(网络): 当传入字段值为null,时,须要加入. 不然报错.
因而修改了,sqlMap中的全部jdbcType=DATE 为TIMESTAMP,保存编译运行结果仍是精确到年月日。
翻开旧项目须要差别,发现由于Oracle中的字段类型是Date的缘故,mybatis generator自动生成了几个个addCriterionForJDBCDate方法,而全部对应Date类型的字段,都使用了该方法,代码以下:
1 protected void addCriterionForJDBCDate(String condition, Date value, String property) { 2 if (value == null) { 3 throw new RuntimeException("Value for " + property + " cannot be null"); 4 } 5 addCriterion(condition, new java.sql.Date(value.getTime()), property); 6 } 7 8 protected void addCriterionForJDBCDate(String condition, List<Date> values, String property) { 9 if (values == null || values.size() == 0) { 10 throw new RuntimeException("Value list for " + property + " cannot be null or empty"); 11 } 12 List<java.sql.Date> dateList = new ArrayList<java.sql.Date>(); 13 Iterator<Date> iter = values.iterator(); 14 while (iter.hasNext()) { 15 dateList.add(new java.sql.Date(iter.next().getTime())); 16 } 17 addCriterion(condition, dateList, property); 18 } 19 20 protected void addCriterionForJDBCDate(String condition, Date value1, Date value2, String property) { 21 if (value1 == null || value2 == null) { 22 throw new RuntimeException("Between values for " + property + " cannot be null"); 23 } 24 addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property); 25 }
其中Java.sql.Date(value1.getTime())结果是精确到年月日,至于为何,后续有时间补充。