MyBatis incoming SQL query for ID type, string type, map type, ben type parameter

Source: Internet
Author: User

Used to hibernate, and then replaced by MyBatis will encounter some abnormal problems, as the following error prompt, with the MyBatis query, pass in a string argument, and when judged, the error is reported

There is no getter for property named ' Modulecode ' in ' class java.lang.String  
DAO Layer Invocation Mode

/*  DAO Layer Query *  /@Overridepublic list<cityface> findcityfacebycondition (String eqdate) {return Sqlsession.selectlist (CityFace.class.getName () + "_mapper.findcityfacebycondition", eqdate); }
Common error notation:XML Mapping SQL

<select id= "findcityfacebycondition" parametertype= "String" resulttype= "Cityface" >select * FROM (SELECT Unitname, To_char (rdate, ' yyyy-mm ') Rdate,analysistype, scope from cityscapeanalysis) pivot (sum (scope) for Analysistype In (' Esscope ' esscope, ' eoscope ' Eoscope, ' gcscope ' Gcscope, ' cscope ' Cscope) '  <if test= ' eqdate!= ' "' >where Rdate = #{eqdate}</if></select>
Need to be modified to:

<select id= "findcityfacebycondition" parametertype= "String" resulttype= "Cityface" >select * FROM (SELECT Unitname, To_char (rdate, ' yyyy-mm ') Rdate,analysistype, scope from cityscapeanalysis) pivot (sum (scope) for Analysistype In (' Esscope ' esscope, ' eoscope ' Eoscope, ' gcscope ' Gcscope, ' Cscope ' Cscope))  <if test= ' _parameter!= ' ' > where rdate = #{_parameter}</if></select>
Whatever your parameters are, change to "_parameter", but the ID doesn't have to be changed.

Java Invocation ID Example

@Overridepublic visitlogs Findvisitlogsbyid (int id) {return sqlsession.selectone (Visitlogs.class.getName () + "_ Mapper.findvisitlogsbyid ", id);}
XML mapping

<!--query user--><select id= "Findvisitlogsbyid" parametertype= "int" resultmap= "resultvisitlogs" by ID >select * From Visitlogs where id=#{id}</select>
——————————————————————————— Split Line ————————————————————————————

The above is a single string value, if it is multiple values can be used to encapsulate the map object and the Bean class object, and then can be used in a common way to receive, such as the following case

Java Call Map sample

@Overridepublic appuser Loginuser (string userName, string password) {map<string, string> Map = new Hashmap<strin G, string> (); Map.put ("name", UserName), Map.put ("password", password); return Sqlsession.selectone ( AppUser.class.getName () + "_mapper.loginuser", map);}
XML mapping

<!--login user--><select id= "loginuser" parametertype= "map" resulttype= "Appuser" >select * from App_user where Name=#{name} and Password=#{password}</select>
Java invoke Bean class example

@Overridepublic appuser Loginuser (string userName, string password) {appuser user = new Appuser (); User.setname (UserName) ; User.setpassword (password); return Sqlsession.selectone (AppUser.class.getName () + "_mapper.loginuser", user);}
XML mapping

<!--login user--><select id= "loginuser" parametertype= "Appuser" resulttype= "Appuser" >select * from App_user Where Name=#{name} and password=#{password}</select>




Java Invocation ID Example

@Overridepublic visitlogs Findvisitlogsbyid (int id) {return sqlsession.selectone (Visitlogs.class.getName () + "_ Mapper.findvisitlogsbyid ", id);}
XML mapping

<!--query user--><select id= "Findvisitlogsbyid" parametertype= "int" resultmap= "resultvisitlogs" by ID >select * From Visitlogs where id=#{id}</select>

MyBatis incoming SQL query for ID type, string type, map type, ben type parameter

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.