What is for springMVC? Role?

For springMVC layer is a web MVC framework, is used to replace the servlet (processing | respond to the request, access to the form parameter, form validation, etc.).

Why use springMVC?

Basically, the framework is designed to simplify programming by making it easier to get form parameters, respond to requests, and so on, compared to servlets.

Describe the underlying spring MVC execution flow (how it works)

! [Spring MVC interview] (https://p6-tt.byteimg.com/origin/pgc-image/7a1adc38f03c4075902e986742f02983?from=pc)

What are some common annotations used in Spring MVC?

@Controller

Identify this class as a controller

@RequestMapping

Bind a URI to the controller method

@ResponseBody

Convert the Java object into JSON and send it to the client

@RequestBody

Turn the JSON requested by the client into a Java object

@RequestParam

Do a name mapping when the form parameter and method parameter names do not match

@PathVarible

Used to get parameters in the URI, such as the value of 1 in user/1

New RESTFUL style API

@RestController

@Controller+ @ResponseBody

@GetMapping

@DeleteMapping

@PostMapping

@PutMapping

Other annotations

@SessionAttribute

What model data is declared to be stored in session

@CookieValue

Get the cookie value

@ModelAttribute

Store the method return value into the model

@HeaderValue

Gets the value in the request header

What’s the difference between SpringMVC and Strus2?

1. Different entrances:

The springMVC entry is a Servlet. The struts2 entry is filter.

2. Different life cycles:

Spring MVC Controller is singleton. So you can’t use member variables to get parameters. So high efficiency.

Struts Actions are multi-example. So you can use member variables to get parameters. So it’s inefficient.

How to implement RESTful services in Spring MVC

1. Import jackson2 package

2. Turn on annotation-driven MVC :annotation-driven/

Json interaction = @requestBody @responseBody

How does Spring MVC return JSON data

Precede the handler with the @responseBody annotation

or

Use @restController on the controller

What is an interceptor? What’s the use? How does Spring MVC define interceptors?

what:

An object similar to filter, used for pre-processing and post-processing processors (controllers).

how:

The new class

Implement HandlerInterceptor

Override three methods

preHandler

postHandler

afterCompletion

Configure interceptors in springMVC.xml

2. How to do form data verification in Spring MVC?

Environment set up

1. Configure a Validator in springMVC. XML

2,<mvc:annotation-driven validator=”validator”/>;

Add a verification rule to an Entity

@NotEmpty

@Length

.

Use BindingResult immediately after entity to receive error messages.

test(User user,BindingResult rs)

Due to the limited space, all the documents are put in the PDF file, there is a need to like + attention, I can get the private letter