6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【備忘】myBatisのjdbcType=DATEは時刻を切り捨てる

Posted at

myBatisを使う時に、SQLのDATETIME型をJavaのDate型にマッピングしようとして

hogeMapper.xml
<resultMap id="hogeResultMap" type="com.example.app.models.HogeViewModel">
	<id column="ID" property="id" />
	<result column="HOGE_START_DATETIME" jdbcType="DATE" property="hogeStartDateTime" />
	<result column="HOGE_END_DATETIME" jdbcType="DATE" property="hogeEndDateTime" />
</resultMap>

などと書くと、マッピングされるhogeStartDateTimeやhogeEndDateTimeの時刻部分は切り捨てられる。
日付と時刻両方の値を使いたい場合は、jdbcTypeを書かないようにする。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?