Springmvc3.0 comments

Source: Internet
Author: User

Related keywords: android tutorial

Springmvc3.0 comments

1, why use annotations, what are the benefits of annotations?

SPRINGMVC3.0 is programming based on annotations, which can greatly improve development efficiency and maintenance costs. Compared to SSH (struts2+spring+hibernate) springmvc3.0, struts2.0, Spring, hinernate configuration files are written and maintained, allowing for faster development. All of this is done by programming based on annotations.

2, how to understand the annotations?

Annotations can be written on the class, or can be written on the method above, in our system, the method-based annotation is mainly used in the Controller, class-based annotations are mainly in the Controller class, Business logic Layer (SERVICEIMPL), the data layer (DAOIMPL) implementation class.

Class-based annotations, such as controller, are equivalent to invoking a singleton object in the system.

The controller of spring is singleton. This means that it will be shared by multiple request threads.

3, what are the commonly used annotations?

• @Controller

• @Service

• @Autowired

• @RequestMapping

• @RequestParam

• @ModelAttribute

• @Cacheable

• @CacheFlush

• @Resource

• @PostConstruct

• @PreDestroy

• @Repository

• @Component (not recommended)

• @Scope

• @SessionAttributes

• @InitBinder

• @Required

• @Qualifier

What are the annotations that need to be understood in our system? Here's a look at the classification, to explain:

In the controller:

Class-based annotations, @Controller

• For example

@Controller
public class Softcreatecontroller extends Simplebasecontroller {}

• OR
@Controller ("Softcreatecontroller")

• description

@Controller is responsible for registering a bean into the spring context, the bean ID defaults to the class name beginning with the lowercase letter

@Resource

• For example

@Resource
Private DataSource DataSource; Inject the bean named ' DataSource '

• OR

@Resource (name= "DataSource")
@Resource (Type=datasource.class)

• description

@Resource is found by default by the Bean's name, and if no find is performed by type without explicitly specifying the Name property for @Resource annotations, if it is labeled in the Beanfactory type, the ApplicationContext class Type, resourceloader types, applicationeventpublisher types, and Messagesource types, Spring automatically injects instances of these implementation classes without the need for additional action. The Name property does not need to be specified (or specified as "") at this time, otherwise the injection fails;

-----------------------------------------------------------

@Service annotations based on the business logic layer

• For example

@Service
public class Softcreateserviceimpl implements Isoftcreateservice {}

• OR
@Service ("Toursearchdataservice")

Public class Toursearchdataserviceimpl implements toursearchdataservice{}

• description

@Service is responsible for registering a bean into the spring context, the bean ID defaults to the class name beginning with the lowercase letter

@Repository annotations based on the data layer

• Similar to @controller, @Service, the Bean is registered with the spring context and is not described.

@Repository ("Toursearchdatadao")

Public class Toursearchdatadaoimpl extends searchhibernatedaosupport implements Toursearchdatadao {}

Related keywords: android tutorial

Springmvc3.0 comments

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.