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 (); } }
}