Differences in @param usage in @param and MyBatis in spring

Source: Internet
Author: User

    1. Spring in @param
    /**      * 查询指定用户和企业关联有没有配置角色      * @param businessId  memberId      * @return      */     int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId"
    1. The Param in MyBatis
    /**      * 查询指定用户和企业关联有没有配置角色      * @param businessId memberId      * @return      */     int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId"

On the surface, there is no difference between the two, but it is different when used in XML files, and the @param in spring need to refer to variables as follows in XML.

<select id="selectRoleCount" resultType="java.lang.Integer" >select     count(tbm.id)    from t_business_member_relation tbm    where#{0,jdbcType=INTEGER}    and#{1,jdbcType=INTEGER}    andisnot null</select>

Values are taken according to the order of the parameters, and starting from 0. The MyBatis @param in XML is the following reference to the variable

<select id="selectRoleCount" resultType="java.lang.Integer" >    select     count(tbm.id)    from t_business_member_relation tbm    where#{businessId,jdbcType=INTEGER}    and#{memberId,jdbcType=INTEGER}    andisnot null </select>

is referenced by a parameter name.
Note: If the Mapper.java file is referenced by the spring

org.springframework.data.repository.query.Param;

However, the use of MyBatis is used in Mapper.xml, then the following error

nestedis‘businessId‘not found. Available parameters are [10, param1, param2]

As follows

So be sure to pay attention to the consistency of @param reference and use when using

Differences in @param usage in @param and MyBatis in spring

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.