Good 947 Mybatis configuration resultmap with parameter query map note SelectOne database returns results a database or it will be an error

Source: Internet
Author: User

TMD wrote a few demos and a station collection.

<a target=_blank href= "http://hao947.com/" target= "_blank" > Good 947</a>

Mapping configuration Files

<!--type: The unique identifier of the data type Id:resultmap for the entity class-<resultmap id=baseresultmap type= "person" ><pre Name= "code" Class= "Java" ><a target=_blank href= "http://hao947.com/" target= "_blank" > Good 947</a>
<!--column: The field name of the Library table property: attribute name in entity class---<id property= "personId" column= "person_id"/> <result property= "Name" column= "name"/> <result property= "gender" column= "gender"/> <result property= "personaddr" column= " Person_addr "/> <result property=" Birthday "column=" Birthday "/> </RESULTMAP>



Mapping Configuration Query statements

<!--Resultmap Specify key and value when the query is worth it. Map.put ("Name", "Project manager") Map.put ("Gender" 1) <pre name= "code" class= "java" ><a target=_blank href= "/http hao947.com/"target=" _blank "> Good 947</a>
--<select id=selectpersonbyparams resultmap= "Baseresultmap" parametertype= "Java.util.Map" > select * FROM Person p where p.name = #{name} and P.gender =#{gender} </SELECT>



Map Management Library Table files

<!--centrally manage map files for library tables--><pre name= "code" class= "java" ><a target=_blank href= "http://hao947.com/" target= "_ Blank "> Good 947</a>
<MAPPERS> <mapper resource= "Com/hao947/sql/mapper/personmapper.xml"/> </MAPPERS>



Test file
@Test public void Selectpersonbyparams () {//Create a sqlsession   <a target=_blank href= "http://hao947.com" target= "_  Blank "> Good 947</a>    sqlsession session = Sqlsessionfactory.opensession ();   try {map<string, object= "" > Map = new hashmap<string, object= "" > ();   Map.put ("Name", "project manager");   Map.put ("Gender", 0); The first parameter looks for SQL, and the rule namespace+ "." +sql ID, the second parameter is the SQL to receive the parameter list<person> List = session. SelectList ("Com.hao947.sql.mapper.PersonMapper.selectPer   Sonbyparams ", map);   for (person p:list) {System.out.println (P);  }} finally {Session.close (); } }




}

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.