Ibatis transfers the date Parameter

Source: Internet
Author: User

This was originally a simple problem, but I did not find the result after checking it online for a long time. Finally, I found a method after reading the official documentation.

In fact, it is very simple. You only need to add the @ Param annotation to the interface method parameters.

In addition, you can use this annotation to implement multiple parameters.

Example:

public List<Teacher> selectTeacher(@Param(value="id") String id, @Param(value="sex") String sex, @Param(value="createTime") Date createTime);

XML

  <select id="selectTeacher" resultType="com.myapp.domain.Teacher">  select * from Teacher where c_id=#{id} and sex=#{sex} and create_time<#{createTime}   </select>

Do not back up when you encounter problems. Although there are other methods to solve this problem (such as passing a string and converting it to a date type in SQL, this will cause database compatibility problems, for example, Oracle date functions and MySQL date functions are written differently), but they are not ideal. Think carefully and analyze them to find the answer persistently.

I stick to this because ibatis, As An ORM framework, must consider database compatibility (for example, Hibernate supports cross-database hql), such as passing a date type Java parameter, how can ibatis not be supported? We also need to use the map, object, string, and other stupid methods. This is a permanent task. Therefore, I think it is worthwhile to spend time and energy.

Under this mark, I would like to share with you the hope that you will soon solve this problem.

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.