Java classic face questions and answers explain finishing (c)

Description:  The following is a student interview, the interviewer asked questions, answer questions about the plane can see below -

Previous: Java finishing the classic face questions and answers explain (b)
the Java interview Zhenti third bomb caught! We believe that through the first two sections of the study, we somewhat understand for Java. Java learning Recommendations or more hands-on exercises, many times you will want to find out and write is not the same child running, this section you can practice according to subject yourself to see ~

1. MyBatis do fuzzy query, to see the implementation of the sql statement in the log, but can not find the results.

Faced with this problem, if you can see the log appear relevant background information display, it means that the current environment to build a whole is no problem, but why data is not it?
Individual lessons learned are the following:
(1) your database data does not meet the conditions, observe your affairs issues, replace with a new client connections;
(2) when you use fuzzy query parameter passed may have a problem, this time the best solution is to observe the incoming data layer inside the content is correct;
(3) when using fuzzy queries must remember to add a "%" at about keywords, If you do not add, it would not be called a fuzzy query;
(4) the database you are connected is not your real database.

2. MyBatis sql statement if the determined transmission over a parameter is not null and is effective, but can not determine the empty string '' '' '. "

Depending on the configuration of dynamic SQL is implemented, it can only judge null. You can append some Analyzing processing functions on the service layer, for example: if it is found to be empty string ( '' ''), then you have to set null.
Dynamic SQL helpful.

3.MyBatis set method and Hibernate

The main core of MyBatis development which asks users to define their own SQL statements used. Due to its characteristics and Hibernate to consider the portability problem, so in the Hibernate process, it needs to consider is an automatically generated SQL problem.
Now all issues are on the POJO class (VO), under Hibernate, if the object is persistent POJO class is in a state status, then each call setter methods will update the data (if your affairs are controlled manually, then the number setter It will be issued after the update was invoked), and MyBatis no such function, because the status of such an object in Hibernate engaged in the design and some bad, but this is in itself reason for the low performance of Hibernate. Investigation of his origin, mainly because the traditional EJB (EntityBean) affected.

4.Resource and Autowired difference

When using an automated annotation Annotation Spring often see two types of notes: @Resource (personal common), @ Autowired, if you want to know the difference between these two, the best approach is to carefully study dependence finished spring when injected through the automatic configuration to explain operations in the auto-configuration mode inside the spring there are two types: by type, by name.
@Autowired: it means in accordance with the type of automatic injection, the disadvantage is that if the same type, you can not inject;
@Resource: with automatic injection according to the type of features, now and then if the same type, you can set a name, which means you use @ Notes automatically scan settings when Component, @ Service and so can set a name, but the name can be used in the @Resource;
SpringBoot inside, because it automatically supports some environmental configuration, if you are using Autowired, so many same configuration Bean type, you will not be able to accurately inject operation. You must use @Resource completed.

5.Hibernate Inversion of Control

Hibernate is now talking about the configuration process for relations inversion of control is to give control to the other, this situation usually appears in the cascade configuration data relationships: one to many, many to many.
To analyze a program as an example: a person how the book is full of magical Hibernate in the world, it can not automatically increase the data processing. Normal process, we must first have a person, this person will have a number, add information during the book when you need to go in together to save this personal number.
If no inversion of control, its treatment:
- increase a person's information;
- increased information for all the books, but this time people associated field contents are saved null;
- and then update information for all the books, people will save the contents of the relationship come.
: Normal flow (Inversion of Control, will use the control of the child table and the parent table to the child table fields associated with its own control) is
the content of the depositary of information, while achieving the number of people, these numbers will be set to the book -
inside; - save the book information

Published 272 original articles · won praise 913 · views 470 000 +

Guess you like

Origin blog.csdn.net/alitech2017/article/details/104427142