Each of the spring pack and spring jar with a common annotations

The role of each jar package 1.spring
Oriented Programming org.springframework.aop-3.0.0.RELEASE -------------------- Spring, there is provided the AOP (for programming section) realized
when org.springframework.asm-3.0.0.RELEASE -------------------- Spring asm separate program, encounter Spring2.5.6 packet needs asmJar .3.0 began offering his own independent asmJar
org.springframework.aspects-3.0.0.RELEASE ---------------- provide the Spring AspectJ integration framework \
org.springframework.beans- 3.0.0.RELEASE ------------------ base SpringIoC (DI) to achieve
org.springframework.context.support-3.0.0.RELEASE ------ extended support --Spring-context for MVC aspects
org.springframework.context-3.0.0.RELEASE ---------------- Spring provides extended service functions on the basis of IoC it also offers a number of enterprise-class support services, such as mail service, task scheduling, JNDI positioning, EJB integration, remote access, the cache layer framework and package a variety of views, etc.
org.springframework.core-3.0.0.RELEASE-- ----------------- Spring3.0 core Kit
org.springframework.expression-3.0.0.RELEASE ------------- Spring expression language
org.springframework.instrument.tomcat-3.0.0.RELEASE ------ Spring3.0 integration of the Tomcat connection pool
org.springframework.instrument-3.0.0.RELEASE ------------- Spring3.0 to the server proxy interface
org.springframework.jdbc-3.0.0.RELEASE ------------------- simple package of JDBC
org.springframework.jms-3.0.0.RELEASE --------------- ----- simple package simplifies the use of the JMS API made
org.springframework.orm-3.0.0.RELEASE -------------------- integration with third party ORM framework, such as hibernate, ibatis, jdo, and spring JPA implementation
org.springframework.oxm-3.0.0.RELEASE -------------------- spring Object of / XMl mapping support that allows switching back and forth between Java and XML
the org.springframework.test-3.0.0.RELEASE -------------------- on Junit and other tests simple encapsulation of the frame
org.springframework.transaction-3.0.0.RELEASE ------------- consistent declarative and programmatic transaction management as JDBC, Hibernate, JDO, JPA, etc. provided
org.springframework.web. portlet-3.0.0.RELEASE ------------- SpringMVC enhanced
org.springframework.web.servlet-3.0.0.RELEASE ------------- on JEE6.0Servlet3.0 support
org.springframework.web.struts-3.0.0.RELEASE -------------- Struts integration time support
org.springframework.web-3.0.0. tools under RELEASE -------------------- SpringWeb package

commonly used annotation 2.spring of
using Spring MVC annotations and their usage and other relevant knowledge to implement the controller function.
    Before use Struts2 MVC implementation notes, by means of this plug-struts2-convention, we now use Spring comes with spring-webmvc components to achieve the same function, but easier than the previous. In addition, eliminating the need for integration of the two factors of instability caused by the framework.
    For the Spring MVC framework, I mainly talk about its usual annotation, combined with some examples will be described to facilitate that we can quickly understand.
    A, Spring MVC common narrative as
    @Controller
    In the above definition of the class, the class showed the controller, returns the string with the redirect: XXX
    @RequestMapping
    this annotation class or method above, setting the access address URL. It has two attributes, value, an access path, method specified mode designation request, the request class RequestMethod manner, all defined as constants, it uses the default GET request.
    @RequestParam
    specified request Request parameter, defined in the process parameters, corresponding to the conventional request.getParameter ().
    @PathVariable
    get access URL path variable, this is Spring MVC 3.0 framework before adding features, URL access path based RESTful style.
    @ModelAttribute
global type of approach, a set of URL access paths, each will perform, the method returns the result stored in the module session.
    @Service
    class defined above, annotated classes specified business logic component, without specifying the Bean ID, then the default naming, i.e., the first class name lowercase. Before SSH2, elephants had @Repository Dao assembly used, the present embodiment only the business layer, so only @Service annotations.
    @Autowired
    IoC automatic injection feature, replacing the previous set of writing, SSH2, has already begun to use.
    @Qualifier
    of the same class have different interfaces to achieve specified a specific category.
    @ResponseBody
    same method defined on, Ajax call statement, the specified method returns a value of Ajax callback function result. This is Spring MVC 3.0 Framework adds a new feature.
    @InitBinder
    initialization data is associated with the type of conversion, the incoming parameters into custom type, or custom processing parameters.
    Second, the example  
    @RequestMapping class name defined above, corresponding to the URL specified other access paths are all parent path within this controller. If a method is defined in the annotation @RequestMapping above, the path is relative to the parent, which is a sub-path. If you do not define the value value, according to the parent access path will be the default execution. However, please note that the default access method can be only one.
    For UserController list method REST URL to access http: // localhost: 8080 / ssm3 / user, and it also receives the GET and POST requests. Further, Spring MVC 3.0 there is a very flexible characteristic parameters can be custom methods. Take a look at the list method, I set two parameters, a Model, a User object. Model is used to render the data, generated by the page. Equivalent request.setAttribute, you can understand, but can not just think, Model and another ModelMap, are passed as parameters of the model view, their scope is request. In addition, you can also define HttpServletRequest, HttpServletResponse so a variety of parameters.
If a class should define additional resource access how to do it? Consider the following RoleController
    On the global path defined RoleController / role, this way, the role for and associated resources will begin / role, such as creating roles / role / new; edit character / role / edit / {id} and so on.
    The method of FIG edit the {id} wording is RESTful URL style, together with @PathVariable be achieved with this function. It represents the requested URL, the variable values may be dynamically passed as a parameter. For example: http: // localhost: 8080 / ssm3 / role / edit / 1, Further, in addition to a number in the string can also be a multi-define several variables: / role / edit / {id } / {type }and many more.
    The return value of each method, in fact corresponds to a result page, This and struts2-convention this plugin is very similar. This example uses FreeMarker template engine as the presentation layer, the page of the suffix .html, in addition to standard HTML, fill the rest of the data page, the condition judgment and the like, should be used FreeMarker instruction.
    For the save method returns a value written representation is redirected, equivalent to the implementation http: // localhost: 8080 / ssm3 / role, and this corresponds to the URL is actually RoleController this class inside the list method. If you want to put parameters and the like, must be consistent with REST resources defined path can.

    @ResponseBody used to identify the Ajax method call, the above method, uses @RequestParam notes, its role is and request.getParameter ( "name") the same. Spring MVC framework supports several returns format, for example: String / JSON / XML, and so on. But this return value string format is the easiest one way, and the use of JavaScript is also very easy to resolve. Please call when the page using jQuery's $ .ajax () to define this natively, such an approach will not go wrong, and very flexible, but also several other ways ultimately called to complete the request.
      
    For with the same set of access rules URL, if needs to obtain the same data is used @ModelAttribute comment. To RoleController for example, the meaning of the notes and the method above, is equivalent in it all the access paths are calling this method of writing: module.addAttribute ( "allRoles", roleService.getRoles ()). That is, whether it is access to create or edit, will perform preperList, will receive allRoles this List.
      
    Sign up custom type editor, Spring MVC, for the time type, the framework will not automatically help you convert bind, you need to define the property editor. In addition, the process can also escape to some special characters, can be placed in a method @InitBinder be annotated. If all of the Controller will need to register the same property editor, you can achieve WebBindingInitializer interface to define a global property editor.
    Third, deployed in a web container
    you want to let the Spring MVC framework to help us complete the work, you need to configure it in a Web container.
      
    DispatcherServlet is the core of Spring MVC, the request is forwarded to deal with all the core controller. Elephants have been in the second article in this series will describe the process structure Spring MVC in detail, if not impressed, then please go and see.
    Spring MVC has a default rule, after the Web container starts, will automatically find /WEB-INF/<servlet-name>.xml Spring this type of profile. If you want to customize the configuration file path, according to the above wording to specify contextConfiglocation this property, the elephant using maven to build the project, so this servlet-context.xml configuration file in the resource directory.
    Four, MVC configuration of
    Spring MVC 3.0 on the use and configuration made greater improvement, in addition to providing annotations to simplify the development of controllers outside, in the configuration file above have also been simplified.
      
    Spring MVC annotation-based configuration is the top two lines, there is a more simplified configuration was written just write this sentence: <mvc: annotation-driven / > on it, Spring is automatically activated when registering the above two bean . Why elephants here to display the registered two bean it? Because, when we actually use, in general, use the default way our system can not meet the requirements or business. For example interceptors, such as data validation, such as the return message format conversion and more customizations. They all need to be configured in both bean inside. Because this case is used as an introductory tutorial, so these things do not add to the mix.
    DefaultAnnotationHandlerMapping This class is all marked @RequestMapping annotated Controller class, are placed in a HandlerMapping object, when there is a request, it is carried out in this object to find out if there is a path matching, AnnotationMethodHandlerAdapter is to manage all @RequestMapping comment Methods.

Reprinted from: http://www.oschina.net/code/snippet_1165954_23354

                        <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count">1</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/wangcunhuazi">
                    <img src="https://profile.csdnimg.cn/D/4/F/3_wangcunhuazi" class="avatar_pic" username="wangcunhuazi">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/2x/7.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/wangcunhuazi" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">平凡的华仔</a></span>
                                            </div>
                    <div class="text"><span>发布了72 篇原创文章</span> · <span>获赞 29</span> · <span>访问量 130万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://bbs.csdn.net/topics/395530431" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-messageboard">他的留言板
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    
Released four original articles · won praise 0 · Views 133

Guess you like

Origin blog.csdn.net/qq_44813090/article/details/104097510