SSM learning framework (a) ---- SSM framework Introduction

table of Contents

About a framework .SSM

1.1 Spring

1.2 SpringMVC

1.3 MyBatis

Two .MVC mode

2.1 mvc mode

2.1.1 MVC Application examples

2.2 SSM and SSH difference in the MVC pattern

Three .RESTful

 3.1 Use regulations

3.2 SpringMVC implement RESTful style


About a framework .SSM

SSM (Spring + SpringMVC + MyBatis) frame by the Spring, MyBatis complete integration of the two frames (SPRINGMVC is part of Spring). Standard MVC pattern.

MVC the Spring : forward and view management responsible for the request.

the Spring         : achieve business object management.

the mybatis       : As a data object persistence engine.

1.1 Spring

  1. Spring is an open source, to simplify application development framework for enterprise application development.
  2. Spring's purpose: the essence of spring is the object management software, namely, such as creating objects and relationships between objects maintenance.
  3. Spring is the core idea IOC (Inversion of Control) and AOP (Aspect Oriented Programming) , that no longer require the programmer to explicitly `new` an object, but to the Spring framework to help you to get everything done.

1.2 SpringMVC

Spring MVC part of the follow-up product of the Spring Framework, Spring Web Flow has been integrated in the inside, it's Spring features native support, so development becomes very simple specification.

  1. spring MVC: MVC architecture is based on a simplified web application development framework (Spring part of the frame), by implementing Model (model) -View (view) -Controller (controller) mode the data well, business and to show the separation. View Manager and is responsible for forwarding requests .
  2. Spring MVC can help us to develop more concise Web layer, and it is a natural integration with Spring Framework.
  3. Under Spring MVC we generally back-end project is divided into Service layer (business process), Dao layer (database operation), Entity (also can be called pojo) layer (entity classes), Controller (also called web) layer (control layer, return data to the front page).

Spring simply works as follows: 

1.3 MyBatis

MyBatis is a Java-based persistence framework, MyBatis eliminates almost all of the retrieved manually set parameters and JDBC code and the result set. MyBatis using simple XML or annotation for the original mapping and configuration, interface and Java POJOs ( plain Old Java objects, ordinary Java objects) to database records in.


Two .MVC mode

2.1 mvc mode

MVC full name Model View Controller, the model (model) - view (view) - Abbreviation controller (Controller), and a software design model, with a service logic, data, a method of separating tissue interface display code, business logic to gather a member which, while improving and customization interfaces and user interaction does not need to rewrite the business logic.

  1. M: model (model) is a model representation of the business rules, to be returned to neutral data model, regardless of the model with the data format, such a model can provide data for a plurality of views, since the code is applied to write-once only Model a plurality of views may be reused, thus reducing repetitive code.
  2. V: view (view) means users see and interact with the interface, one of the benefits of MVC is that it can handle a lot of different views for the application. In fact, no real view processing occurs, it is only as a data output mode and allows the user manipulation.
  3. C: controller (controller) refers to the controller accepts user input and calls the model and view to the completion of the needs of users, the controller itself does not output anything and do anything. It just receives the request and calls the member decides which model to process the request, and then decide which view to display the returned data.

The relationship between the three as follows:

2.1.1 MVC Application examples

The most typical MVC is jsp + servlet + javabean mode:

  • JavaBean as a model, either as encapsulated service data to the data model, but also as a business model to include the business logic operation of the application. After which, the data model is used to store or transfer the service data, and the service logic model update request is received over the transmission controller model, processing logic to perform a particular service, and then returns the appropriate execution result.
  • JSP as the presentation layer, is responsible for providing a page to show users the data, provided the appropriate form (Form) to a user's request, and at the appropriate time (click the button) makes a request to the controller to request the model is updated.
  • Serlvet as a controller for receiving a request submitted by a user, and the data acquisition request, the data model is converted to the desired business model, and then calls the appropriate method for updating service business models, while selected according to the results of operations return of view.

2.2 SSM and SSH difference in the MVC pattern

SSH: usually refers to Struts2 to make the controller (controller), the component layers of management spring, hibernate responsible for the persistence layer.

SSM: it refers to the controller SpringMVC do (controller), the component layers of management Spring, MyBatis responsible for the persistence layer.

Common:

1.Spring dependency injection DI component layers to manage

2. Using Aspect Oriented Programming AOP manage things, logs, and other privileges.

difference:

Different mechanisms of interaction and 1.Struts2 SpringMVC controller (Controller) control the view and model

2.Struts2 is the Action class level, SpringMVC method level is easier to implement RESTful style


Three .RESTful

 Restfule style is a style of software architecture, rather than the standard, but provides a design principles and constraints . Mainly applied to the software client and server interaction. It is based on the http protocol. Aims to improve the scalability of the system, to reduce the coupling between the application framework to facilitate distributed processing program. Based on this style of software can be more simple, more structured and easier to implement caching mechanism.

In resultful style, a user requests a URL url using the same manner and with the request: get / post / delete / put on the processing method, etc. to distinguish the request. This allows front-end developers backstage separate development in the former no confusion on the resources requested address to form a unified interface.

Features:

  1. Each url represents a resource.
  2. Between client and server, pass this some kind of presentation layer resources.
  3. The client through the four http verb, server resources to operate. Conversion layer to achieve performance state.

 3.1 Use regulations

In the http protocol, the verb indicates the operation mode of the four: GET / Post / put / Delete, they respectively correspond to the four basic operations.

RESTful operation
Method CRUD  
POST create、delete、update

GET, corresponding to the select: the query from the server, the server can distinguish parameters requested by way of the query.
POST, corresponds to Create: create a new resource in a server, call the insert operation.
PUT, the corresponding update: Update the resource server, calling the update operation.

DELETE, DELETE operations correspond, delete the resource from the server, call delete statements.

GET read
PUT update、create
DELETE delete

3.2 SpringMVC implement RESTful style

 Spring MVc provides the following support for resstful applications. Use @RequestMapping specify the type of action to deal with templates and url http request request. The use @PathVariable request url template variable to the processing method parameter. Reception use AJAX, a request put, delete operation on the client.

Format is as follows:

@RequestMapping(value="/{id}",method=RequestMethod.GET)
@RequestMapping(value="/{id}",method=RequestMethod.POST)
@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
@RequestMapping(value="/{id}",method=RequestMethod.PUT)

E.g:

@RequestMapping(
value="/queryQuByTypeIdAndChaID/{questionTypeId}/{chapterId}",
method=RequestMethod.GET,
produces="text/html;charset=UTF-8"
)
public void queryQuByTypeIdAndChaID(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable String questionTypeId, 
@PathVariable String chapterId){
//具体实现代码
}	

Common Mistakes 3.3RESTful design

RESTful common two errors

RESTful version control

 

 

 

 

 

发布了26 篇原创文章 · 获赞 27 · 访问量 6872

Guess you like

Origin blog.csdn.net/qq_40705355/article/details/94127749