In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the interview questions for the latest version of Mybatis in 2021". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn what are the interview questions for the latest version of Mybatis in 2021.
1. How to write the fuzzy query like statement
2. In the Xml mapping file of Mybatis, can id repeat different Xml mapping files?
For different Xml mapping files, id can be repeated if namespace is configured; if namespace is not configured, id cannot be repeated; after all, namespace is not necessary, it's just a best practice.
The reason is that namespace+id is used as the key of Map, if there is no namespace, only id is left, then id repetition will cause the data to overwrite each other. With namespace, the natural id can be repeated. If the namespace is different, the namespace+id is different.
3. Advantages and disadvantages of Mybatis.
Advantages
Compared with traditional database access technologies, ORM has the following advantages:
Programming based on SQL statements is quite flexible and will not affect the existing design of the application or database. SQL is written in XML to decouple sql from program code and facilitate unified management. It provides XML tags, supports the writing of dynamic SQL statements, and can be reused.
Compared with JDBC, it reduces the amount of code by more than 50%, eliminates a lot of redundant code in JDBC, and does not need to manually switch connections. It is well compatible with various databases (because MyBatis uses JDBC to connect to databases, it is supported by database MyBatis supported by JDBC).
Provide mapping tags to support ORM field mapping between objects and databases, and provide object relational mapping tags to support object relational component maintenance
Be able to integrate well with Spring
Shortcoming
The workload of writing SQL statements is large, especially when there are many fields and associated tables, there are certain requirements for developers to write SQL statements.
The SQL statement depends on the database, which leads to the poor portability of the database, and the database cannot be changed at will.
4. How is Mybatis paginated? What is the principle of the paging plug-in?
Mybatis uses the RowBounds object for paging, which is memory paging for ResultSet result sets rather than physical paging. You can write parameters with physical paging directly within sql to complete physical paging, or you can use paging plug-ins to complete physical paging.
The basic principle of the paging plug-in is to use the plug-in interface provided by Mybatis to implement the custom plug-in, intercept the sql to be executed in the plug-in interception method, then rewrite the sql, and add the corresponding physical paging statements and physical paging parameters according to the dialect dialect.
For example: select * from student, after intercepting sql, rewrite as: select t.* from (select * from student) t limit 0,10
5. Please tell me how MyBatis works
Before learning the MyBatis program, you need to understand how MyBatis works in order to understand the program. How MyBatis works is shown in the following figure:
6. Does Mybatis support delayed loading? If so, what is the principle of its implementation?
Mybatis only supports delayed loading of association associated objects and collection associated collection objects. Association refers to one-to-one and collection refers to one-to-many queries. In the Mybatis configuration file, you can configure whether to enable deferred loading of lazyLoadingEnabled=true | false.
Its principle is to use CGLIB to create a proxy object of the target object, and when the target method is called, enter the interceptor method, such as calling a.getB (). GetName (), the interceptor invoke () method finds that a.getB () is a null value, then the sql of the pre-saved query associated B object is sent separately, the B query is uploaded, and then a.setB (b) is called, so that the object b property of a has a value. Then complete the call to the a.getB () .getName () method. This is the basic principle of delayed loading.
Of course, not only Mybatis, but almost all of them, including Hibernate, support delayed loading on the same principle.
7. How does Mybatis encapsulate the sql execution result as a target object and return it? What are the forms of mapping?
The first is to use tags to define the mapping between column names and object attribute names one by one.
The second is to use the alias function of the sql column to write the column alias as an object property name, such as T_NAME AS NAME, the object property name is generally name, lowercase, but the column name is not case-sensitive, Mybatis will ignore the column name case, intelligently find the corresponding object property name, you can even write as T_NAME AS NaMe,Mybatis can work normally.
8. The difference between # {} and ${}
# {} is a placeholder, precompiled; ${} is a splice, string replacement, no precompilation. When Mybatis processes # {}, the # {} input parameter is passed as a string, and the # {} in SQL will be replaced with? Number, call
PreparedStatement's set method to assign values.
# {} can effectively prevent SQL injection and improve system security; ${} can not prevent SQL injection
The variable substitution of # {} is in DBMS; the variable substitution of ${} is outside DBMS
9. How to pass multiple parameters in mapper
Methods 3:Map transmission parameter method
10. Briefly describe the mapping relationship between Mybatis's Xml mapping file and Mybatis internal data structure?
Answer: Mybatis encapsulates all Xml configuration information inside the All-In-One heavyweight object Confifiguration. In the Xml mapping file, the tag is resolved to a ParameterMap object, and each of its child elements is resolved to a ParameterMapping object. The tag is resolved to a ResultMap object, and each of its child elements is resolved to a ResultMapping object. Each tag will be parsed into a MappedStatement object, and the sql within the tag will be parsed into a BoundSql object.
11. What are the MyBatis programming steps?
1. Create a SqlSessionFactory
2. Create SqlSession through SqlSessionFactory
3. Perform database operations through sqlsession
4. Call session.commit () to commit the transaction
5. Call session.close () to close the session
12. How to get the generated primary key
13. How to perform batch operations in Mybatis
14. What does Mybatis dynamic sql do? What are the dynamic sql? Can you briefly describe the implementation principle of dynamic sql?
Mybatis dynamic sql allows us to write dynamic sql in the form of tags in Xml mapping files to complete the functions of logical judgment and dynamic splicing of sql. Mybatis provides 9 kinds of dynamic sql tags.
Trim | where | set | foreach | if | choose | when | otherwise | bind.
Its execution principle is that it uses OGNL to calculate the value of the expression from the sql parameter object, and dynamically splices the sql according to the value of the expression, so as to complete the function of dynamic sql.
15. Talk about the cache of MyBatis
The cache of MyBatis is divided into first-level cache and second-level cache. The first-level cache is stored in session. By default, second-level cache is stored in its namespace and is not opened by default. Using secondary cache attribute classes requires Serializable serialization.
Interface (which can be used to save the state of an object), which can be configured in its mapping file
What is the interface binding of MyBatis? What are the ways to implement it?
Why is Mybatis a semi-automatic ORM mapping tool? What's the difference between it and full automation?
18. Why pre-compilation is needed
19. How do you specify which Executor actuator to use in Mybatis?
20. Can Mybatis perform one-to-many, one-to-one contact queries? what are the implementation methods
21. Primary and secondary cache of Mybatis
22. Briefly describe the plug-in operation principle of Mybatis, and how to write a plug-in.
23. What are the problems with traditional JDBC development?
24. The difference between Hibernate and MyBatis
25. What are the requirements when calling the mapper API of MyBatis?
The Mapper interface method name is the same as the id for each sql defined in mapper.xml.
The input parameter type of the Mapper interface method is the same as the type of parameterType for each sql defined in mapper.xml.
The output parameter type of the Mapper interface method is the same as the type of resultType for each sql defined in mapper.xml.
The namespace in the Mapper.xml file is the classpath of the mapper interface.
26. How does this Dao interface work? Can the method in the Dao interface be overloaded when the parameters are different?
The Dao interface works as a JDK dynamic proxy. The Mybatis runtime uses the JDK dynamic proxy to generate a proxy proxy object for the Dao interface. The proxy object proxy intercepts the interface method, executes the sql represented by MappedStatement, and returns the sql execution result.
The method in the Dao interface cannot be overloaded because it is the save and search strategy of the fully qualified name + method name.
27. What is DBMS
28. What are the Executor actuators in Mybatis? What's the difference between them?
29. What is MyBatis?
30. What are the ways to write Mapper?
31. What is the functional architecture of MyBatis
We divide the functional architecture of Mybatis into three layers:
API interface layer: provides external use of the interface API, developers through these local API to manipulate the database. As soon as the interface layer receives the call request, it will call the data processing layer to complete the specific data processing.
Data processing layer: responsible for specific SQL lookup, SQL parsing, SQL execution and result mapping processing. Its main purpose is to complete a database operation according to the called request.
Basic support layer: responsible for the most basic functional support, including connection management, transaction management, configuration loading, and caching, which are common things, extracted as the most basic components. It provides the most basic support for the upper data processing layer.
32. What are the shortcomings of JDBC programming and how does MyBatis solve them?
33. What is the framework design of MyBatis
34. What are the other tags in the Xml mapping file besides the common select | insert | updae | delete tags?
35. In the Mybatis mapping file, if the A tag refers to the content of the B tag through include, can the B tag be defined after the A tag, or must it be defined in front of the A tag?
36. What are the applicable scenarios for MyBatis and Hibernate?
At this point, I believe you have a deeper understanding of "what are the latest version of Mybatis interview questions in 2021?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.