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

Source: Internet
Author: User

    1. Spring in @param
<code class= "Hljs java has-numbering" >    <span class= "Hljs-javadoc" >/**      * Query specified user and Enterprise Association have no configuration roles      *<span class= "Hljs-javadoctag" > @param </span> businessid  memberid *<span      class= " Hljs-javadoctag "> @return </span>      */</span>     <span class=" Hljs-keyword ">int</span > Selectrolecount (<span class= "hljs-annotation" > @Param </span> (<span class= "hljs-string" > " Businessid "</span>) Integer businessid,<span class=" hljs-annotation "> @Param </span> (<span class= "hljs-string" > "MemberID" </span>) Long MemberID); </code><ul style= "Display:block;" class= "pre-numbering" ><li>1</li><li>2</li> <li>3</li><li>4</li><li>5</li><li>6</li></ul>
    1. The Param in MyBatis
<code class= "Hljs java has-numbering" >    <span class= "Hljs-javadoc" >/**      * Query specified user and Enterprise Association have no configuration roles      *<span class= "Hljs-javadoctag" > @param </span> businessid memberid *<span      class= "Hljs-javadoctag" > @return </span>      */</span>     <span class= "Hljs-keyword" >int</span> Selectrolecount (<span class= "hljs-annotation" > @Param </span> (<span class= "hljs-string" > " Businessid "</span>) Integer businessid,<span class=" hljs-annotation "> @Param </span> (<span class= "hljs-string" > "MemberID" </span>) Long MemberID); </code><ul style= "Display:block;" class= "pre-numbering" ><li>1</li><li>2</li> <li>3</li><li>4</li><li>5</li><li>6</li></ul>

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.

<code class= "Hljs vbnet has-numbering" ><<span class= "Hljs-keyword" >select</span> Id=<span class= "hljs-string" > "Selectrolecount" </span> resulttype=<span class= "hljs-string" > " Java.lang.Integer "</span> ><span class=" Hljs-keyword ">select</span> count (tbm.id) <span CLA ss= "Hljs-keyword" >from</span> t_business_member_relation TBM <span class= "Hljs-keyword" >where</ span> tbm.business_id = <span class= "hljs-preprocessor" >#{0,jdbcType=INTEGER}</span> <span class= " Hljs-keyword ">and</span> tbm.member_id = <span class=" Hljs-preprocessor ">#{1,jdbctype=integer}</ span> <span class= "Hljs-keyword" >and</span> tbm.role_business_id <span class= "Hljs-keyword" >is </span> <span class= "Hljs-keyword" >not</span> null</<span class= "Hljs-keyword" >select </span>></code><ul style= "Display:block;" class= "pre-numbering" >&Lt;li>1</li><li>2</li><li>3</li><li>4</li><li>5</li> <li>6</li><li>7</li><li>8</li></ul>

The

is based on the order of the parameters, and starts at 0. The MyBatis @param in XML is the following

that refers to a variable.

<code class= "Hljs vbnet has-numbering" ><<span class= "Hljs-keyword" >select</span> Id=<span class= "hljs-string" > "Selectrolecount" </span> resulttype=<span class= "hljs-string" > "  Java.lang.Integer "</span> > <span class=" Hljs-keyword ">select</span> count (tbm.id) <span class= "Hljs-keyword" >from</span> t_business_member_relation TBM <span class= "Hljs-keyword" >where    </span> tbm.business_id = <span class= "Hljs-preprocessor" >#{businessId,jdbcType=INTEGER}</span> <span class= "Hljs-keyword" >and</span> tbm.member_id = <span class= "Hljs-preprocessor" >#{memberid, jdbctype=integer}</span> <span class= "Hljs-keyword" >and</span> tbm.role_business_id <span class= "Hljs-keyword" >is</span> <span class= "Hljs-keyword" >not</span> null </<span class= "Hljs-keyword" >select</span>></code><ul style= "Display:block;" Class= "Pre-numbering" ><li>1</li><li>2</li><li>3</li><li>4</li> <li>5</li><li>6</li><li>7</li><li>8</li></ul>

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

<code class= "Hljs avrasm has-numbering" >org<span class= "Hljs-preprocessor" >.springframework</span ><span class= "Hljs-preprocessor" >.data</span><span class= "Hljs-preprocessor" >.repository </span><span class= "Hljs-preprocessor" >.query</span><span class= "Hljs-preprocessor";. Param</span><span class= "hljs-comment" >;</span></code><ul style= "Display:block;" Class = "Pre-numbering" ><li>1</li></ul>

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

<code class= "Hljs oxygene has-numbering" >org.mybatis.spring.mybatissystemexception: <span class= " Hljs-keyword ">nested</span> exception <span class=" Hljs-keyword ">is</span> Org.apache.ibatis.binding.BindingException:Parameter <span class= "hljs-string" > ' Businessid ' </span> <span class= "Hljs-keyword" >not</span> found. Available parameters is [<span class= "Hljs-number" >1</SPAN> <span class= "Hljs-number" >0</span , param1, Param2]</code><ul style= "display:block; class=" Pre-numbering "><li>1</li> </ul>

As follows

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

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.