Spring MVC and MyBatis face questions

Source: Internet
Author: User

The SPRINGMVC framework has some of these features:

1, it is based on component technology, all of the application objects, regardless of the controller and view, or business objects and so on are Java components. and tightly integrated with other infrastructure provided by spring.

2. Do not rely on the servlet API (although the target is, but it does depend on the servlet when it is implemented)

3, can use any kind of view technology, and not only limited to JSP

4. Support the mapping strategy of various request resources

5, it should be easy to expand

SPRINGMVC Workflow:

1. The user sends the request to the front controller Dispatcherservlet

2. Dispatcherservlet received a request to call the Handlermapping processor mapper.

3. The processor mapper locates the specific processor according to the request URL, and the Processor object and processor interceptor (if any) are returned to Dispatcherservlet.

4. Dispatcherservlet calls the processor via the Handleradapter processor adapter

5. Execute processor (Controller, also known as back-end controller).

6. Controller execution complete return Modelandview

7. Handleradapter returns the controller execution result Modelandview to Dispatcherservlet

8. Dispatcherservlet Pass Modelandview to Viewreslover view parser

9. Viewreslover return to the specific view after parsing

Dispatcherservlet View is rendered (the model data is populated into the view).

Dispatcherservlet Response Users

If you have used Struts2, what are the differences between SPRINGMVC and struts?

1. The entrance to the SPRINGMVC is a servlet, the front-end controller, and the STRUTS2 entry is a filter filter.

2. Springmvc is based on method development (a URL corresponding to a method), request parameters passed to the parameter of the method, can be designed as a single case or multiple examples (recommended singleton), Struts2 is based on class development, Pass-through parameters are properties of the class and can only be designed as multiple examples.

3. Struts uses the value stack to store the request and response data through OGNL Access data, SPRINGMVC through the parameter parser is to parse the request content, and to assign a value to the method parameter, the data and view is encapsulated into Modelandview object, Finally, the model data in Modelandview is transferred to the page through the reques domain. The JSP view parser uses Jstl by default.

SSM pros and cons, used scenes?

1. MyBatis and Hibernate are different, It's not exactly an ORM framework, because MyBatis requires programmers to write their own SQL statements, but mybatis can flexibly configure SQL statements to run with XML or annotations, and generate Java Objects and SQL statement mappings to the final executed SQL. Finally, the results of SQL execution are remapped to generate Java objects.

2. MyBatis learning threshold is low, easy to learn, the programmer directly write the original ecological SQL, can strictly control the performance of SQL execution, flexibility, is very suitable for the relational data model requirements of software development, such as Internet software, enterprise operations software, etc., because such software requirements change frequently, But demand changes require a rapid output. However, the premise of flexibility is that MyBatis can not do database independence, if you need to implement software that supports a variety of databases, you need to customize multiple sets of SQL mapping files, a lot of work.

3. Hibernate object/Relational mapping is strong, database independence is good, for the relational model of high-demand software (such as the need for fixed custom software) if Hibernate development can save a lot of code, improve efficiency. But hibernate's learning threshold is high, the threshold is higher, and how to design the O/R mapping, how to trade off between performance and object models, and how to use hibernate with great experience and ability.

4. In short, in accordance with the needs of users in a limited resource environment as long as the maintenance and extensibility of a good software architecture is a good architecture, so the framework only suitable is the best.

mybatis::

1. MyBatis configuration

2. Sqlmapconfig.xml, this file is configured as a global configuration file for the MyBatis, with information such as the MyBatis runtime environment.

3. The Mapper.xml file is a SQL mapping file that is configured with SQL statements that manipulate the database. This file needs to be loaded in Sqlmapconfig.xml.

4. Construct MyBatis as a session factory with configuration information such as Sqlsessionfactory environment

5. The session factory creates a sqlsession that is a session, and the operational database needs to be done through sqlsession.

6. MyBatis the bottom layer customizes the Executor actuator interface operation database, the executor interface has two implementations, one is the basic executor, the other is the cache executor.

7. Mapped statement is also mybatis a lower-level package object that wraps mybatis configuration information and SQL mapping information. One SQL in the Mapper.xml file corresponds to a mapped statement object, and the SQL ID is the ID of the mapped statement.

8. Mapped statement defines SQL execution input parameters, including HashMap, base type, pojo,executor through Mapped statement to map the input Java objects into SQL before executing SQL. The input parameter mapping is the parameter set for PreparedStatement in JDBC programming.

9. Mapped statement defines SQL execution output, including HashMap, base type, pojo,executor through Mapped statement to map output results to Java objects after executing SQL. The output mapping process is equivalent to the parsing process of the results in JDBC programming.

Spring MVC and MyBatis face questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.