MyBatis Use Experience Summary

Source: Internet
Author: User

Only in the use of the summary of the process, I am still in constant practice ...
A helpful information about MyBatis website: http://www.mybatis.tk/

Use of multiple parameters
MyBatis query or UPDATE, if you need more than one parameter: object mapping, the creation of a Java object, and as an interface parameter, the object's properties can be directly accessed using the #{property name} ; map, the parameter is a map, key for the property name , value for the parameter value, this method is to pass parameter is required to establish a map temporary object @param parameter annotations, before the interface method parameters to add parameter name annotation, so that you can directly in the mapper through the parameter name access through the ordinal access, the first parameter #{0} or #{ PARAM1}, second parameter #{1}, #{param2}

Use of Time fields in MyBatis – return
Return of the Time field the author now uses the way to put back the string:
Date_format (Update_time, '%y-%c-%d%h:%i:%s ') updatetime
Use the MySQL time format method.
Or put back the data of the timestamp type, requiring that the object property parameter be put back to timestamp.

Use of Time fields in MyBatis-parameters
If you need to query data for a time range, you can query the data by using the following dynamic SQL:

<if test= "StartTime! = null" > and 
    lbr.update_time &gt; #{starttime}
</if>
<if test= " EndTime! = null "> 
    and Lbr.update_time &lt; #{endtime, Javatype=date, jdbctype=timestamp}
</if>

The interface method names for are as follows:
... Date startTime, Date endTime ...
I think this method will be more efficient than a format conversion.
4. Use of Time fields in MyBatis-write
Writes are written directly to the timestamp data, and some written jdbctype need to be described, as follows:
#{installtime, Jdbctype=timestamp}

Continue to update in ...

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.