Lock screen interview questions 100 days brush, every weekday insist on updating the interview questions. Lock screen interview app and mini program are now online, official website address:www.demosoftware.cc/#/introduct…. Has included the daily update of all the content of the interview questions, also includes features to unlock the screen to review the interview questions, daily programming questions email push and other functions. Let you in the interview one step ahead, blow the interviewer! Here’s today’s interview question:

====Mybatis # and difference? # is equivalent to putting double quotes around the data, which is equivalent to displaying the data directly

  1. # Treat all incoming data as a string and place double quotes around automatically passed data. Order by #user_id# = 111 order by #user_id# = 111

  2. Display the incoming data directly in SQL. For example, Order Derby displays incoming data directly in SQL. For example, order by displays incoming data directly in SQL. For example, orderByUser_id $, if the value passed in is 111, then the value parsed into SQL is orderby 111, if the value passed in is id, then the value parsed into SQL is orderby ID.

  3. The # method largely prevents SQL injection. The $method does not prevent Sql injection.

4. The $method is generally used to pass in database objects, such as table names.

5. Don’t use $when you can usually use #.

What are the programming steps for ====Mybatis?

Create SqlSessionFactory

// Get sqlSessionFactory from mybatis-config. XML

String resource = “mybatis-config.xml”;

InputStream inputStream = Resources.getResourceAsStream(resource);

SqlSessionFactory sqlSessionFactory = new

SqlSessionFactoryBuilder().build(inputStream);

Create SqlSession with SqlSessionFactory

3. Perform database operations using SQLSession

Call session.mit () to commit transaction

5. Call session.close() to close the session

==== What are the shortcomings of JDBC programming, and how does MyBatis address them?

  1. The frequent creation and release of database links waste system resources and affect system performance. This problem can be solved by using database link pools.

Solution: Configure a data link pool in sqlmapconfig. XML and use the connection pool to manage database links.

  1. Sql statements are written in the code, which makes the code difficult to maintain. As a result, the ACTUAL APPLICATION of Sql may change greatly, and the CHANGE of Sql requires the change of Java code.

Solution: Separate the Sql statement configuration from the Java code in xxxxmapper.xml.

  1. It is difficult to pass parameters to SQL statements because SQL statements may have more or less WHERE conditions. Placeholders need to correspond to parameters one by one.

Solution: Mybatis automatically maps Java objects to SQL statements.

  1. It is troublesome to parse the result set. SQL changes lead to parsing code changes, and it is necessary to traverse before parsing. It is convenient to encapsulate database records into POJO object solutions.

Solution: Mybatis automatically maps SQL execution results to Java objects.

==== What are the requirements when using MyBatis mapper interface?

  1. The Mapper interface method name is the same as the ID of each SQL defined in mapper.xml

  2. The input parameter types for the Mapper interface methods are the same type as parameterType for each SQL defined in mapper.xml

  3. The output parameter type of the Mapper interface method is the same type as the resultType of each SQL defined in mapper.xml

  4. The namespace in the mapper. XML file is the class path of the Mapper interface.

==== tell about level 1 cache and level 2 cache in Mybatis?

  1. Level 1 cache: A HashMap local cache based on PerpetualCache that stores at Session scope when Session flush or

After close, all caches in the Session will be cleared.

  1. Level 2 caches have the same mechanism as Level 1 caches, with PerpetualCache and HashMap storage by default, but with Mapper(Namespace) storage scope and customizable storage source, such as Ehcache. Namespance indicates the configuration of the namespance

All select operations in the file are cached so that the secondary cache can be shared between different threads. Enable level 2 cache: Configure nodes in the Mapper configuration file.

<mapper namespace="com.yihaomen.mybatis.dao.StudentMapper"> <! -- Enable level 2 cache in namespace of mapper --> <! MyBatis is designed to exclude cache reclamation policies from any design design. (1) LRU, the least recently used object, and the most recently used object. (2) FIFO, which removes objects in the order in which they enter the cache. (3) SOFT, which removes objects based on garbage collector status and SOFT reference rules. More aggressively remove objects based on garbage collector state and weak reference rules. Here, LRU is used to remove the pair image that has not been used for the longest timeCopy the code

FlushInterval: flushInterval in milliseconds. If you do not flushInterval, the cache will be flushed only when the SQL is executed.

Size: indicates the number of references. It is a positive integer. It indicates the maximum number of objects that can be stored in the cache. Too many Settings will cause memory overflow. ReadOnly: 1024 objects readOnly: 1024 objects readOnly: 1024 objects readOnly: 1024 objects readOnly: 1024 objects readOnly: 1024 objects readOnly: 1024 objects readOnly: 1024 objects <cache eviction="LRU" flushInterval="100000" readOnly="true" size="1024"/> </mapper>Copy the code

3. 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.

====MyBatis how to set to return primary key ID during insert operation?

When the database is MySql:

<insert id=”insert” parameterType=”com.test.User” keyProperty=”userId”

UseGeneratedKeys =”true” > “keyProperty” indicates which property of the object the returned ID is to be stored in, the “useGeneratedKeys” table

The primary key ID is in auto-growth mode.

MySQL > alter table MySQL > alter table MySQL > alter table MySQL

Oracle database:

`<insert id="insert" parameterType="com.test.User"> <selectKey resultType="INTEGER" order="BEFORE" keyProperty="userId">  SELECT SEQ_USER.NEXTVAL as userId from DUAL </selectKey> insert into user (user_id, user_name, modified, state) values (#{userId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{modified,jdbcType=TIMESTAMP}, #{state,jdbcType=INTEGER}) </insert>`Copy the code

Since Oracle does not have a term for auto-growth, only sequences that mimic auto-growth, useGeneratedKeys is no longer available. But to make use

            <selectKey> 
Copy the code

Gets and assigns the ID to the property of the object. Insert Inserts the ID normally during the insert operation.

More interview questions can be paid attention to “Demo locked screen interview questions” public account through the mini program or App to obtain interview questions and learning resources