MyBatis official Chinese document www.mybatis.org/mybatis-3/z…

Java API problem

Field not found

The text field could not be found

Cause: The MyBatis selectByExample method does not query fields of type TEXT and needs to use selectByExampleWithBLOBs()

@ Mapper and @ MapperScan

@ Mapper and @ MapperScan

In order for Mybatis to scan a Bean from a mapper interface, the @mapper annotation should be added to each interface, or the @mapperscan annotation should be used to specify all packets to be scanned, and the ‘*’ wildcard character can be used

@SpringBootApplication
@MapperScan({"com.kk.mysql.*.mapper"."com.kk.tidb.mapper"}) public class MyBatisApplication { public static void main(String[] args) { SpringApplication.run(MyBatisApplication.class, args); }}Copy the code

@mapperscan Conflicts are reported when scanning Mapper of the same name in different packages

Explanation: If there are two data sources (i.e. two libraries), the startup file will scan the mapper of both libraries. However, if there are OrderMapper in both packages, the startup will not be able to start. The mapper package of two data sources cannot have the same mapper.

sqlSession

SqlSession creation process

  1. Define a Configuration object that contains data sources, transactions, mapper file resources, and Settings for properties that affect database behavior (mybatis-config, spring-boot projects can also be configured by setting application profiles)
  2. By configuring the object, you can create an SqlSessionFactoryBuilder object or SqlSessionFactoryBean
  3. Get an instance of SqlSessionFactory from SqlSessionFactoryBuilder or SqlSessionFactoryBean
  4. An instance of SqlSessionFactory can get an INSTANCE of SqlSession that operates on data, and use this instance to operate on the database