I. Principles of MAPPER Agent development
Requires the namespace attribute value in the mapper mapping file, which must be the fully qualified name of the Mapper proxy interface
Requires a declaration of the SQL statement label in the Mapper mapping file, consistent with the declaration of the Mapper interface method (method with the same name)
Requires the type specified by the Resulttype property of the SQL statement (if the return value is a collection, resulttype specifies the type stored in the collection), and the return value type of the Mapper interface method is the same
Requires the id attribute value of the SQL statement, consistent with the method name of the Mapper interface
Requires the type specified by the ParameterType property of the SQL statement, consistent with the parameter type of the Mapper interface method
1. Increase operation
<insert id="Insertuser" parametertype="Com.code.po.User">
Insert INTO ' user ' (ID,username, birthday,sex,address)
VALUES (#{id},#{username},#{birthday},#{sex},#{address})//The property here should correspond to the previous
</insert>
2. Get primary key values for database maintenance (only available when you just insert)
<!--before?oracle Database Usage--
<selectkey keycolumn= "id" keyproperty= "id" resulttype= "int" order= "before" >
Select Seq.nextval from dual
</selectKey>
<!--after?oracle Database Usage--
<selectkey keycolumn="id" keyproperty="id " resulttype="int" order="after" >
Select LAST_INSERT_ID ()
</selectKey>
3. modifying data by ID
<update id="Updateuserbyid" parametertype="com.code. Po. User ">
Update ' user '
Set username=#{username},sex=#{sex} where Id=#{id}
</update>
4. Delete data by ID
<delete id="Deleteuserbyid" parametertype="int">
Delete from ' user ' where Id=#{id}
</delete>
SQL usage for MyBatis (configuration of mapper mapping file)