spring,spring Mvc,mybatis Common annotations

Source: Internet
Author: User

Article Source: https://www.cnblogs.com/hello-tl/p/9209063.html

0. In spring,soring MVC, the common annotations in Mybistis are
<!--to scan annotations on classes in the specified package, commonly used annotations are:   -
<!--@Controller declaring the action component --
<!--@Service Declare the Service component @Service ("Xxxservice")--
<!--@Repository declaring DAO components --
<!--@Component Refer to components when they are not well categorized.
<!--@RequestMapping ("/menu") request Map--
<!--@Resource for injection, which is installed by name by default, @Resource (name= "Beanname") --
<!--@Autowired for injection, (spring supplied) by default by type --
<!--@Transactional (Rollbackfor={exception.class}) transaction Management--
<!--@ResponseBody returns the content or object as the HTTP response body, and calls the adapter transform object that is appropriate for Httpmessageconverter, writes the output stream --
<!--@Scope ("prototype") to set the scope of the bean--
1. @Controller declaring the Action component
Package Com.web.controller;import org.springframework.stereotype.controller;//Controller claims controllers @Controller public class TestController {    /**     * Code body */     }
2. @Service declaring the Service component @Service ("Xxxservice")
@Service ("Testservice")public class Testserviceimpl implements Itestservice {}
3. @Repository declaring DAO components
Package com.web.dao;import org.springframework.stereotype.repository;//declares DAO@Repositorypublic interface Itestdao {   /**     * Code body */     }
4. @Component refer to components when they are not well categorized.

5. @RequestMapping ("/menu") Request mapping
Package Com.web.controller;import Org.springframework.stereotype.controller;import org.springframework.web.bind.annotation.RequestMapping; @Controller
Request Mapping @RequestMapping ("test")public class testcontroller{
Request Mapping
@RequestMapping ("index")public String getprovince () { return "attempt address"; }}
6. @Resource for injection, (provided by the Java EE) by default assembly by name, @Resource (name= "Beanname")
Package Com.web.service.impl;import Org.springframework.stereotype.service;import Javax.annotation.Resource;
Import com.web.dao.testdao;//declares the Service @Service ("Testservice") public class Testserviceimpl implements Itestservice { c11/>//@Resource injected @Resource private Itestdao Testdao;}
7. @Autowired for Injection, (Spring provided) default assembly by type
Package Com.web.controller;import Org.springframework.stereotype.controller;import com.web.service.itestservice;/ /Controller Declaration Controllers @controllerpublic class TestController {    //autowired usage    @Autowired    Private Itestservice Testservice;}
8. @Transactional (Rollbackfor={exception.class})
Package Com.web.service.impl;import Org.springframework.stereotype.service;import Javax.annotation.Resource; Import Com.web.dao.testDao;
Import org.springframework.transaction.annotation.Transactional;




@Resource private Itestdao Testdao;
@Override
Add transaction processing
@Transactional (Rollbackfor={exception.class})
public int addtest (Testmodel testmodel) {
Return Testdao.addtest (Testmodel);
}
}
9. @ResponseBody returns the content or object as an HTTP response body and invokes the adapter transform object that is appropriate for httpmessageconverter, writing to the output stream
Package Com.web.controller;import Org.springframework.stereotype.controller;import org.springframework.web.bind.annotation.RequestMapping; @Controller//Request Map @requestmapping ("Test") public class testcontroller{        //Request map    @RequestMapping ("index")    //write output    @ResponseBody public    String Getprovince () {        return  "input content such as JSON XML string";    }}
[Email protected] ("prototype") sets the scope of the bean
Article Source: https://www.cnblogs.com/hello-tl/p/9209063.html

spring,spring Mvc,mybatis Common annotations

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.