Mybatis XML mapping file (four)

The real power lies in its MyBatis mapping statements, but also its magic lies. Because of its extremely powerful, XML mapper file becomes relatively simple. If you take it compare with JDBC code with the same function, you will immediately find save nearly 95% of the code. MyBatis is built for SQL, and do better than ordinary method.

The basic structure of the mapping file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="">
    
</mapper>

Several top-level element SQL mapping file (in the order they should be defined):

  • cache: cache for a given namespace configuration.
  • cache-ref: other namespaces referenced cache configurations.
  • resultMap: is the most complex and powerful element that describes how to load from the database result object.
  • sql: reusable statement block can be referenced by other statements.
  • insert: Mapping insert statements
  • update: mapped UPDATE statement.
  • delete: Mapping delete statement
  • select - map query

A, select

 

Guess you like

Origin www.cnblogs.com/myitnews/p/11562872.html