Spring MVC @ Keyword Summary

Source: Internet
Author: User
Tags html tags

First, class-Related:

@Controller is used to label the control layer component;

@Service is used to label business layer components;

@Repository is used to annotate the data Access component, the DAO component;

@Component refers to components, when the component is not good to classify, we can use this annotation to annotate;

@WebService specify that this class be published as a webservice on the class.


@Documented
@Retention (Retentionpolicy.runtime)
@Target (Elementtype.method)

Second, function Related:

@Transactional (rollbackfor = exception.class, value = "TransactionManager")

Declare this service all methods require transaction management. Each business method opens a transaction at the beginning.

Spring defaults to a transaction rollback for the run-time exception (runtimeexception). This exception is unchecked, and will not be rolled back if you encounter a checked accident.

Rollbackfor = Exception.class, let checked exceptions also roll back.


@Override: Methods to override the parent class


@SearchUserMethod (name = "Loadvipuser")

@AddPointsMethod


There are many warnings in Java compilation, many are safe, but every time a compilation has many warnings affecting our filtering and modification of the error, we can add @SuppressWarnings ("XXXX") to the code to solve.

@SuppressWarnings ("unused"): suppress warnings relative to unused code

@SuppressWarnings ("Unchecked"): Suppress warnings relative to unchecked operations

@SuppressWarnings ("Rawtypes"): Suppress warnings relative to un-specific types if using generics on class params


@Invisible

@Scheduled (cron = "0 0/1 * * * *") : Perform timed tasks;


@InitBinder

In Springmvc, types such as date,double are defined in the bean, and the date and double cannot be bound without any processing.

The solution is to use the @initbinder tag provided by spring MVC.


@RequestMapping

Requestmapping is a note used to process request address mappings, which can be used on classes or methods.

Used on a class, the method that represents all the response requests in the class is the address as the parent path.

The requestmapping annotation has six attributes:

Value: Specifies the actual address of the request, which can be specified as URI Template mode (described later);

Method: Specifies the method type of the request, get, POST, put, delete, and so on;

Consumes: Specifies the submitted content type (CONTENT-TYPE) of the processing request, such as Application/json, text/html;

Produces: Specifies the type of content returned, which is returned only if the specified type is included in the (Accept) type in the request header;

Params: Specifies that the request must contain certain parameter values to be processed by the method;

Headers: Specifies that some specified header value must be included in the request in order for the method to process requests;


@ResponseBody

The annotation is used to write the object returned by the Controller method to the body data area of the response object after the appropriate httpmessageconverter is converted to the specified format;

Time to use: The returned data is not a page of HTML tags, but other data in some format (such as JSON, XML, etc.);


Third, member variables related to:

@Autowired: Spring provides, import Package:o Rg.springframework.beans.factory.annotation.Autowired, the default first by Bytype injection, if found more than one bean, then, in accordance with the ByName method, if there are more than, then reported an exception.

@Resource: Java EE provides, the default by ByName automatic injection, you need to import javax.annotation.Resource.

@Value: Gets the configuration values in the properties file.


Third, class-Related:

@Controller is used to label the control layer component;

@Service is used to label business layer components;

@Repository is used to annotate the data Access component, the DAO component;

@Component refers to components, when the component is not good to classify, we can use this annotation to annotate;

@WebService specify that this class be published as a webservice on the class.


@Documented
@Retention (Retentionpolicy.runtime)
@Target (Elementtype.method)

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.