1. @Controller

Identifies a class that is the Spring MVC Controller handler used to create objects that handle HTTP requests.



2.@RestController

If you use @restController instead of @Controller, you don’t need to configure @responseBody. By default, you return JSON.



3.@Service

For annotating business layer components, in other words, adding you have an annotated way to inject this class into the Spring configuration



4.@Autowired

Used to assemble beans, either on fields or methods.

The dependent object must exist by default. To allow null values, you can set its required property to false, for example: @autowired (required=false)



5.@RequestMapping

Class definition: Provides preliminary request mapping information relative to the WEB application root directory.

Method: Provides further breakdown mapping information relative to the URL at the class definition.



6.@RequestParam

Used to map the request parameter area data to the parameters of the functional processing method

For example,

This id is used to receive the value of the parameter ID passed from the interface, or if the name of the parameter passed from the interface is different from the one you received

Course_id is the parameter passed by the interface, and ID is the parameter name of the mapping course_id



7.@ModelAttribute

There are three kinds of use places:

1, mark in the method.

Tags on methods are executed before each @requestMapping method, and if there is a return value, that return value is automatically added to ModelMap.

(1) In the return method:

When ModelAttribute is set to value, the value returned by the method is stored in Model with the value as the key and the value received by the parameter as the value. AddAttribute (“user_name”, name); If @modelAttribute does not have a custom value

model.addAttribute(“name”, name);

(2) In the method that does not return:

Manual model.add methods are required

We create a request method under the current class:

Enter the access address in the browser and add parameters:

http://localhost:8081/api/test/mod?name= I’m dishes & age = 12

The final output is as follows:

2. Mark the parameters of the method.

Marking the parameters of the method injects the parameters passed by the client into the specified object by name, and the object is automatically added to ModelMap for easy use by the View layer. We add a method to the above class as follows

Enter the access address in the browser and add parameters:

http://localhost:8081/api/test/mod2?name= I’m dishes & age = 12

Final output:

As you can see from the results, the @ModelAttribute annotation used in method parameters is actually a way to take parameters and automatically put them into Model objects for easy use.

8.@Cacheable

Used to mark cached queries. Can be used in a method or class to indicate that the method is cache-enabled when the tag is on a method and that all the methods in that class are cache-enabled.

The list of parameters

For example, @cacheable (value=”UserCache”) indicates that when a method marked with this annotation is called, the logic is added by default to fetch the result from the cache. If there is no data in the cache, the user-written query logic is performed, and the result is placed in the cache when the query succeeds.

Caching is always in the form of key-value, so key is the method parameter (ID), value is the result of the query, and the namespace UserCache is defined in Spring *.xml.



9.@CacheEvict

The method used to mark the cache to be emptied. When this method is called, the cache is emptied. @ CacheEvict UserCache (value = “”)

The list of parameters



10.@Resource Assembly sequence:

1. If both name and type are specified, a unique matching bean from the Spring context will be found and assembled. If no matching bean is found, an exception will be thrown

2. If name is specified, the bean whose name (ID) matches is searched from the context for assembly, and an exception is thrown if no bean is found

3. If type is specified, an exception will be raised if a unique bean whose type matches is found in the context

4. If neither name nor type is specified, the assembly will be carried out in byName mode automatically. If there is no match, the system backs up to a primitive type for matching. If there is a match, automatic assembly is performed.





11.@PreDestroy

The @predestroy modified method runs when the server uninstalls the Servlet and is called only once by the server, similar to the destroy() method of the Servlet. Methods modified by @predestroy run after destroy(), before the Servlet is completely uninstalled



12.@Repository

Used to annotate data access components, known as DAO components



13.@Component

This annotation refers to components in general, and can be used to annotate components when they are difficult to categorize



14.@Scope

To configure the scope of the Spring bean, which identifies the scope of the bean.

The default value is singleton

1. Singleton: singleton pattern, with only one instance globally

Prototype: A new instance is generated each time a Bean is fetched

3. Request: Request indicates that a new bean is generated for each HTTP request and is valid only in the current HTTP Request

Session: The session scope means that a new bean is generated for each HTTP request and is valid only for the current HTTP session

5. Global Session: only useful in Portal applications. Create a Bean instance for each Global HTTP session.



15.@SessionAttributes

By default, Spring MVC stores the data in the model into the Request domain. When a request ends, the data is invalidated. If you want to use it across pages. So you need to use sessions. The @sessionAttributes annotation causes a copy of the data in the model to be stored in the session domain

Parameters:

1. Names: This is an array of strings. It should contain the name of the data to be stored in the session.

2. Types: According to the specified parameter types, parameters of corresponding types in the model are stored in session

Value: is the same as names.



16.@Required

Applies to the setter method for bean properties and indicates that the affected bean properties must be populated at configuration time in the XML configuration file. Otherwise, the container will be thrown a BeanInitializationException anomalies.



17@Qualifier

When you create multiple beans of the same type and want to assemble only one of them with a property, you can use the @Qualifier annotation and the @AutoWired annotation to eliminate confusion by specifying which actual bean will be assembled.


The last

Welcome to pay attention to my public number [programmer chasing wind], the article will be updated in it, sorting out the data will be placed in it.