Insert the Date and DateTime fields in mybatis, mybatisdatetime

Source: Internet
Author: User

Insert the Date and DateTime fields in mybatis, mybatisdatetime
Recently, the company used MyBatis3 as the data persistence layer. There are Date and DateTime types in the field. When inserting data, as long as the object attribute is set to Timestamp, it will correspond to the DateTime type of mysql, date corresponds to the mysql Date type.

The ing type must be indicated in the MyBatis ing file.

<result column="modified_date" jdbcType="TIMESTAMP" property="modified_date" javaType="java.sql.Timestamp" />  <result column="date" jdbcType="DATE" property="date" javaType="java.util.Date" />  <result column="date" jdbcType="TIMESTAMP" property="date" javaType="java.util.Date" />  

The type # {modified_date, jdbcType = TIMESTAMP}, # {date, jdbcType = DATE} must also be specified when fields are used }.


Insert a datetime field in mysql

If (intval ($ end_time)-intval ($ start_time) <= 7200 ){
$ SQL = "insert into table values (/* insertion time */)";
} Else {
$ SQL = "";
}
 
How to insert data of the date and date-time types into MYSQL?

If the current time is obtained
Use functions provided by mysql
Curdate () returns 'yyyy-MM-DD'
Now () returns datetime data 'yyyy-MM-DD HH: MM: ss'

$ SQL = "insert into xxx_table (xxx_date, xxx_datetime) values (curdate (), now ())";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.