Simple query
Insert Add
Insert can use the automatically generated primary key policy supported by the database, set usegeneratedkeys= "true", and then set the Keyproperty to the corresponding column, it is done. For example, the studententity above uses auto-generated to generate a primary key for the ID column.
You can also use the Selectkey element. In the following example, use MySQL database nextval (' student ') as a custom function to generate a key.
Update modification
The SQL element is used to define a reusable SQL statement segment that can be called by other statements. Like what:
The difference between Resulttype and Resultmap
1, Resulttype
Return a single instance
<select id= "Selectuser" parametertype= "int" resulttype= "User" >
SELECT * from user where id = #{id}
</select>
Returns the list collection
<select id= "Selectuserall" resulttype= "User" > <!--resultmap= "UserMap"-
SELECT * FROM user
</select>
2, Resultmap
Simple query:
<resultmap type= "User" id= "UserMap" >
<id column= "id" property= "id"/>
<result column= "name" property= "name"/>
</resultMap>
Column: Name in database, property: attribute name in class
Resultmap: The case of a custom entity class that is suitable for using return values
Resulttype: Suitable for use return-worthy data types are non-customizable, that is, the supplied type of JDK
Resultmap:
Mapping the data type of an entity class
Unique identification of the RESULTMAP
Column: Field name of the library table
Property: The attribute name in the entity class
Mybatis SQL mapping File