Chapter 2 mybatis implements in query (mysql) using annotations and mybatismysql

Source: Internet
Author: User

Chapter 2 mybatis implements in query (mysql) using annotations and mybatismysql

Mybatis implements in query in two ways:

  • Xml format (recommended)
  • Annotation method (I personally like annotation, but the in scenario may not be suitable for annotation)

Code:

1 @ Select ("<script>" 2 + "select idfa from t_xxx where idfa in" 3 + "<foreach item = 'item' index = 'index' collection = 'strlist' open = '('separator = ', 'Close = ')'> "4 +" # {item} "5 +" </foreach> "6 +" </script> ") 7 @ Results (value = {@ Result (column = "user_name", property = "username")}) 8 public List <String> getXxxList (@ Param ("strList ") list <String> strList); View Code

Note: The above method is actually a method that completely replaces xml annotations.

The foreach collection can be directly written as the value in @ param.

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.