Ing configuration file 947
<! -- Type: ID of the Data Type of the ing object class: Unique Identifier of resultmap --> <resultmap type = "person" id = "baseresultmap"> <! -- Column: Field Name property of the database table: property name in the object class --> <ID column = "person_id" property = "personid"/> <result column = "name" property = "name"/> <result column = "gender" property = "gender"/> <result column = "person_addr" property = "personaddr"/> <result column = "Birthday" property = "Birthday"/> </ resultmap>
The ing configuration query statement is 947 better
<Insert id = "insert" parametertype = "com. hao947.model. Person"> <! -- Keyproperty: Id attribute name in the object class. When the primary key is returned, it is returned to the keyproperty order: the order in which the primary key is generated and the insert statement is executed. In MySQL, it is after, use before resulttype in Oracle: the data type returned by the primary key. It is the same as the type of the primary key in the object class. Select last_insert_id (): SQL statement for generating the primary key in MySQL, and select XXXX in Oracle. nextval from dual --> <selectkey keyproperty = "personid" Order = "after" resulttype = "Java. lang. integer "> select last_insert_id (); </selectkey> insert into person (person_id, name, gender, person_addr, birthday) values (# {personid}, # {name }, # {gender}, # {personaddr}, # {birthday}) </Insert>
Ing management library table file hao947
<! -- Centrally manage the ing files of database tables --> <mappers> <mapper resource = "com/hao947/SQL/mapper/personmapper. xml"/> </mappers>
Test File hao947
@ Test public void insert () {sqlsession session = sqlsessionfactory. opensession (); try {person P = new person (); // P. setpersonid (3); p. setname ("architect"); p. setgender (1); p. setpersonaddr ("Beijing"); p. setbirthday (New simpledateformat ("yyyy-mm-dd "). parse ("1985-03-14"); Session. insert ("com. hao947. SQL. mapper. personmapper. insert ", P); // The transaction session must be submitted after the database and table changes are completed. commit ();} catch (parseexception e) {session. rollback (); E. printstacktrace ();} finally {session. close ();}}
Big sites like collection: Collect all the data! Havip 947: Product