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 ())";