The most frequently asked framing questions


1. The advantages of struts2 (in fact, why do you use the struts2 framework for this project?)

1.Struts2 is based on the MVC architecture, the framework structure is clear, the development process is clear at a glance, and developers can control the development process well.
    In the process of project development, the development process of a specific function is: get a specific functional requirement document and the designed front-end interface (I am not responsible for designing the page during development), analyze which parameters need to be passed from the front-end, and determine the parameters. Variable name, set the corresponding variable in the Action, how to display these parameters in the foreground, and replace some controls on the page with the server-side controls provided by Struts2, write the corresponding method of the Action to complete the business logic, and finally, do some Configuration file related settings. Of course, the actual development is more complicated than this process, involving database, verification, exception and other processing. But using Struts2 for development, most of your focus is on how to implement business logic, and the development process is very clear.
2. Use OGNL for parameter passing.
    OGNL provides a simple way to access data in various scopes in Struts2. You can easily obtain data in Request, Attribute, Application, Session, and Parameters. This greatly simplifies the amount of code developers have to code when fetching this data.
3. Powerful interceptor
    Struts2's interceptor is an Action-level AOP. Many features in Struts2 are implemented through interceptors, such as exception handling, file uploading, and verification. The interceptor is configurable and reusable, and some common functions such as login verification, permission verification, etc. can be placed in the interceptor to complete some common functions in Java Web projects. In a Web project I implemented, the Struts2 interceptor was used to complete the authorization verification function in the system.
4. Easy to test
    The Actions of Struts2 are all simple POJOs, which can easily write test cases for the Actions of Struts2, which greatly facilitates the testing of Java Web projects.
5. Easy-to-extensible plug-in mechanism
    Adding extensions to Struts2 is a pleasant and easy thing, just put the required Jar package in the WEB-INF/lib folder, and make some simple settings in struts.xml. Expansion is possible.
6. Modularization
Struts2 has taken modularization as the basic idea in the architecture. There are three ways to modularize the application:
(1) Split the configuration information into multiple files
(2) Divide the self-contained application Module creation
creates new framework features for plugins (3), ie, new functionality that is not relevant to a particular application is organized into plugins to be added to multiple applications.
7. Global results and declarative exceptions
  Add global results to the application, and handle exceptions in the configuration file, so that when a specified exception occurs during processing, you can jump to a specific page, which is very practical.

Second, the advantages of Spring: (Do you think the benefits of using spring in the project?)

1. It is convenient for decoupling and simplifying development.

Through the IoC container provided by Spring, we can hand over the dependencies between objects to Spring to control, to avoid hard Excessive program coupling caused by coding. With Spring, users no longer have to write code for very low-level requirements such as single-instance mode classes, property file parsing, etc., and can focus more on upper-layer applications.

2 AOP programming support

  The AOP function provided by Spring facilitates aspect-oriented programming, and many functions that are not easy to implement with traditional OOP can be easily handled by AOP.

3 Declarative Transaction Support

  In Spring, we can be freed from the monotonous and boring transaction management code, and flexibly manage transactions in a declarative way to improve development efficiency and quality.

4 Convenient program testing

  Almost all testing work can be done in a non-container-dependent programming way. In Spring, testing is no longer an expensive operation, but something that can be done easily.

5. Convenient integration of various excellent frameworks

Spring does not exclude various excellent open source frameworks. On the contrary, Spring can reduce the difficulty of using various frameworks. Spring provides direct access to various excellent frameworks (such as Struts, Hibernate, Hession, Quartz), etc. support.

6 Reduce the difficulty of using Java EE APIs

  Spring provides a thin encapsulation layer for many difficult-to-use Java EE APIs (such as JDBC, JavaMail, remote calls, etc.). Through Spring's simple encapsulation, these Java EE APIs are difficult to use to reduce.

7 Java source code is a classic learning example

Spring's source code is exquisite in design, clear in structure, and unique in use. It reflects the master's flexible use of Java design patterns and profound knowledge of Java technology. The Spring Framework source code is undoubtedly the best-practice example of Java technology. If you want to quickly improve your Java technology level and application development level in a short period of time, learning and researching Spring source code will make you receive unexpected results.

3. The five differences between iBatis and Hibernate and the selection elements

1. iBatis features are easy to master

. Hibernate can take 3x more time to master.

2. The features of iBatis make it easier to optimize SQL

Everyone should agree on this. In addition, the SQL generated by Hibernate is really ugly. In view of the fact that some friends mentioned that SQL is not very important. I would like to emphasize my experience here that the general bottleneck of system performance is the database. So this is a very important advantage after comparing iBatis and Hibernate.

3. The feature of iBatis is that it can perform fine-grained optimization.

3.1 For example, I have a table with several or dozens of fields. I need to update one of the fields. iBatis is very simple. Execute a SQLUPDATE TABLE_A SET column_1= #column_1# WHERE id=#id# But it is more troublesome to use Hibernate. By default, Hibernate will update all fields. Of course I remember that Hibernate has an option to control saving only modified fields, but I'm not quite sure about the negative effects of this feature, so comparing iBatis and Hibernate, the advantage of iBatis is obvious.

3.2 I need to list part of the content of a table. When using iBatis, the advantage of this is that it can read a lot of data from the database and save traffic. SELECT ID, NAME FROMTABLE_WITH_A_LOT_OF_COLUMN WHERE

3.2.1 In general, Hibernate will store all fields selected. For example, there is a table above with 8 fields, one or two of which are relatively large, varchar(255)/text. Why would I choose them in the scene above?

3.2.2 With Hibernate, you can't set these two unnecessary fields to lazy load, because there are still many places that need to load the entire domain object at one time. At this time, the benefits of iBatis can be shown.

3.2.3Hibernate has another solution, which is to generate javabean/map/object[] (thanks to leelun/cjmm), but this may generate a lot of redundant classes. The map/object[] approach should be fine, I prefer this approach.

3.3 If I need to update a record (an object), if I use Hibernate, I need to select the object now, and then do the update. This is two pieces of SQL for the database. And iBatis only needs an update SQL. Reducing one interaction with the database is very important for performance improvement.

4. In terms of development

4.1 In terms of development efficiency, I think iBatis and Hibernate should be similar

to 4.2 In terms of maintainability, I think iBatis is better. Because iBatis SQL is saved to a separate file. And Hibernate may save sql/hql in java code in some cases.

5. Operational efficiency

5.1 Without considering the cache, iBatis should be a little faster than Hibernate or a lot (depending on the actual situation).

Of course, compared with Hibernate, iBatis also has major disadvantages

. 1. The support of different database types is not good. If the system you want to develop is to migrate between pairs of data, it may be better to use Hibernate. 2. The default cache support is not good, but Hibernate's cache support is actually not very good, and it is very complicated. Especially for applications with large concurrency. So I prefer to manage the cache myself.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327070427&siteId=291194637