First, talk about your understanding of MyBatis?

1. Mybatis is a semi-ORM (Object Relational Mapping) framework, which encapsulates JDBC internally. During development, we only need to pay attention to THE SQL Statement itself, and do not need to spend energy to deal with the complex process of loading drivers, creating connections, creating statements and so on. Programmers directly write the original SQL, SQL execution performance can be strictly controlled, high flexibility.

2. MyBatis can configure and map native information using XML or annotations to map POJOs to records in the database, avoiding almost all JDBC code and manually setting parameters and fetching result sets.

3. Configure various statements to be executed through XML files or annotations, and map Java objects to dynamic parameters of SQL in the Statement to generate the SQL statements to be executed. Finally, the MyBatis framework executes the SQL and maps the results to Java objects and returns them. (The process from executing SQL to returning Result).

What are the advantages and disadvantages of MyBaits?

§ advantages:

1. Based on SQL statement programming, quite flexible, will not cause any impact on the existing design of the application program or database, SQL written in XML, remove the COUPLING of SQL and program code, easy to unified management; Provides XML tags, supports writing dynamic SQL statements, and can be reused;

2. Compared with JDBC, reduce the amount of code, eliminate a lot of redundant CODE JDBC, do not need to manually switch the connection;

3. Good compatibility with a variety of databases (because MyBatis uses JDBC to connect to the database, so as long as JDBC support database MyBatis support);

4. Provide mapping labels to support ORM field relational mapping between objects and databases; Provides object-relational mapping labels to support object-relational component maintenance.

§ faults:

1. The workload of COMPILING SQL statements is large, especially when there are many fields and associated tables, there are certain requirements for developers to write SQL statements;

2. SQL statements depend on the database, which leads to poor database portability. Therefore, the database cannot be replaced at will.

What are the differences between MyBatis and Hibernate?

MyBatis, unlike Hibernate, is not a complete ORM framework because MyBatis requires programmers to write their own SQL statements. Hibernate object/relational mapping ability is strong, database independence is good, for software with high requirements of relational model, if Hibernate development can save a lot of code, improve efficiency;

2. MyBatis directly writes the original SQL, which can strictly control the PERFORMANCE of SQL execution and has high flexibility. It is very suitable for software development with low requirements on relational data model, because this kind of software needs to change frequently and output results quickly once the requirements change. However, the premise of flexibility is that MyBatis cannot achieve database independence. If you need to implement software supporting a variety of databases, you need to customize multiple sets of SQL mapping files, and the workload is heavy.

${} ${} ${} ${} ${}

§ #{} is precompiled processing, and ${} is string substitution

1. Mybatis will replace #{} with? Call the set method in PreparedStatement to assign the value. Using #{} can effectively prevent SQL injection, improve system security;

${} = ${}; ${} = ${};

How to paginate MyBatis? How does paging plug-ins work?

MyBatis uses the RowBounds object for paging, which is memory paging performed against a ResultSet ResultSet rather than physical paging. Physical paging can be done by writing parameters with physical paging directly in SQL, or physical paging can be done using paging plug-ins.

The basic principle of the paging plug-in is to use the plug-in interface provided by MyBatis to implement a custom plug-in to intercept the SQL to be executed in the interception method of the plug-in, and then rewrite the SQL to add the corresponding physical paging statement and physical paging parameters according to the dialect.

6, MyBatis has several kinds of paging methods?

1. Array paging

2. SQL paging

3. Interceptor paging

4. RowBounds paging

What is the difference between logical paging and physical paging in MyBatis?

1. Physical pages are not necessarily faster than logical pages, and logical pages are not necessarily faster than physical pages.

2. Physical paging is always better than logical paging: there is no need to put pressure on the database side on the application side, even if there is a speed advantage, but other performance advantages more than compensate for this disadvantage.

Does MyBatis support lazy loading? If so, how does it work?

Mybatis only supports lazy loading of association associative objects and collection associative objects. Association refers to one-to-one and collection refers to one-to-many queries. In MyBatis configuration file, you can configure whether to enable lazy-loading lazyLoadingEnabled = true | false.

The principle is that CGLIB is used to create a proxy object for the target object. When the target method is called, the interceptor method is entered, such as a.geb ().getName(). The interceptor invoke() method finds that A.geb () is null. A. setb (); a.getName (); a.getname (); a.getb (); a.getname (); This is the basic principle of lazy loading.

MyBatis level 1 cache and level 2 cache?

Level 1 Cache: A HashMap local Cache based on PerpetualCache, with storage scope of Session. When a Session is flushed or closed, all caches in that Session are flushed. Level 1 Cache is enabled by default.

Level 2 cache: Same mechanism as Level 1 cache, default PerpetualCache, HashMap storage, except that it has Mapper(Namespace) storage scope and can customize storage source, such as Ehcache. Level 2 cache is not enabled by default. To enable level 2 cache, use the Level 2 cache attribute class to implement the Serializable interface (which can be used to store the state of objects). You can configure
in its mapping file.

If a C/U/D operation is performed on a Session (level 1) or Namespaces (level 2), all caches in the select area will be cleared by default.

What executors do Mybatis have?

Mybatis has three basic executors:

1. SimpleExecutor: Every time an Update or SELECT is performed, a Statement object is opened and the Statement object is closed immediately.

2. ReuseExecutor: Perform update or SELECT to search for a Statement object using SQL as its key. If the Statement object exists, use it; if it does not exist, create it. In short, the Statement object is reused;

3. BatchExecutor: Update (no SELECT, JDBC batch does not support SELECT), add all SQL to the batch (addBatch()), and wait for execution (executeBatch()), which caches multiple Statement objects. Each Statement object is addBatch(), and the executeBatch() batch is executed one by one. Same as JDBC batch processing.

What does MyBatis dynamic SQL do? What is the dynamic SQL? Can you briefly explain how dynamic SQL is executed?

1. MyBatis dynamic SQL allows us to write dynamic SQL in the form of tags in XML mapping files, complete logical judgment and dynamic splicing SQL functions;

2. MyBatis provides 9 types of dynamic SQL tags: trim, WHERE, SET, foreach, if, Choose, when, otherwise, bind;

3. Execution principle: using OGNL to calculate the value of the expression from the SQL parameter object, according to the value of the expression dynamic splicing SQL, in order to complete the function of dynamic SQL.

Message queue interview questions

1. What are the basic functions of message queues?

2. What are the advantages and disadvantages of message queues?

3. How to ensure high availability of message queues?

4. How to ensure that messages are not reused? In other words, how can message consumption be idempotent?

5. How to ensure the reliability of message transmission? In other words, how do you handle message loss?

6. How to ensure the sequential nature of messages?

7, a large number of messages in MQ backlog for a long time, how to solve?

8. What if messages in MQ are out of date?

9. What are the important roles of RabbitMQ?

10. What are the important components of RabbitMQ?

11. How many broadcast types are available for RabbitMQ?

Can Kafka be used independently of ZooKeeper? Why is that?

13. How many data retention strategies does Kafka have?

14. What are Kafka’s partitioning policies?

Redis interview questions

1. What do you know about Redis?

2. What are the general usage scenarios of Redis?

3. What are the common functions of Redis?

4. What data types are supported by Redis?

5. Why is Redis single threaded?

6. Why is Redis so fast?

7. What is cache penetration? How to solve it?

What is cache avalanche? How to solve it?

9. How to ensure the consistency of cache and database data?

How many ways can Redis persist?

11. How does Redis implement distributed lock?

12. What are the Redis elimination strategies?

Redis common performance problems and solutions?



The last

Welcome to pay attention to my public number [programmer chasing wind], the article will be updated in it, sorting out the data will be placed in it.