Application of mybatis framework in springboot project


Mybatis overview
1) Excellent persistence layer framework? Persistence layer: the layer (DAO) responsible for storing objects in memory into the database
2) Biggest advantage? (it can quickly realize data operation in the database at low cost)
2.1) open source (free – low cost)
2.2) simple (operation steps, parameter mapping, result mapping)
2.4) flexible (dynamic SQL can better adapt to different requirements – for, if,…)
2.5) stable (no mistakes in three or two days)

2. Application architecture of mybatis framework?
1) Dao (self written data access object – mybatis specification – sqlsession to be called in this object)
2) Mybatis API (specification, implementation of specification – encapsulating JDBC operation)
3) JDBC API specification (Java official definition)
4) Driver (implementation of JDBC specification – the database manufacturer provides its driver)

1) How to understand sqlsession? (an entry object that implements a database session in mybatis)
2) Who is the specific implementation of sqlsession specification during testing? (SqlSessionTemplate)
3) Did we create the sqlsessionfactory object ourselves during the test? (no, the springboot project is created at the bottom – out of the box)
4) When the sqlsession object gets a connection, where does the connection come from? (connection pool object associated with hikaridatasource)

1)IllegalArgumentException (Mapped Statement Collections does not contains …..)

The mybatis framework creates implementation classes for our interfaces?
Add the @ mapper annotation on the goodsdao interface or on the startup class
@Mapperscan (“package of Dao interface”)

1) What is the function of @ mapper annotation?
Describe the data logic layer interface and tell the mybatis framework that the implementation class of this interface is created by mybatis,
And give the object of its implementation class to spring for management, and spring will name the bean he manages
, the default is the interface name, and then the first letter is lowercase.

2) What does mybatis do inside the implementation class and its methods created for our Dao interface?

a) Get sqlsession object
b) Get the key information (namespace, elementid) of SQL mapping
c) Obtain SQL mapping information based on the statement (the bottom layer is stored in the mappedstatement object)
d) Realize the session with database based on SQL session and SQL.

3) Can the data layer interface (xdao) have multiple implementation classes? (yes, but we need to inject that when necessary)


1. Bindingexception (mybatis binding exception)

1) Who is the logging API used in the business class? (org.slf4j.Logger)
2) What design patterns are used in the application of logging API? (facade mode)
3) Do you know which log levels? (trace,debug,info,error)
4) Do you know why the underlying layer defines the log level when logging output? (convenient for opening and closing log behaviors)
5) What is the role of “{}” in log output? (placeholder, similar to that in SQL?)
6) Can the log be recorded to a file? How to configure? (yes, logging. File. Path)
7) Why do you want to put the log records into the commodity business logic object? (logging itself belongs to a business)

Recommended Today


Supervisor [note] Supervisor – H view supervisor command help Supervisorctl – H view supervisorctl command help Supervisorctl help view the action command of supervisorctl Supervisorctl help any action to view the use of this action 1. Introduction Supervisor is a process control system. Generally speaking, it can monitor your process. If the process exits abnormally, […]