SPRINGMVC Learning Series-PostScript open Project Opensessioninview

Source: Internet
Author: User

In the example project of the series Springmvc Learning Series (12), there was no opensessioninview to configure the project because the Opensessioninview would have a certain impact on performance. In the configuration of the mapping file, such as: Account.hbm.xml for the account login system when the query is convenient, so in the mapping role, the direct use of lazy= "false", and in the role Map permissions Authority also directly adopted lazy= " False ", it is convenient to log in, but when the account list is made aware that even if the account's role information is not displayed in the list or a bunch of unnecessary query statements are generated to query the roles and permissions information, the lazy=" false "is changed to lazy=" true " (The default is lazy= "true"), then the problem is:

First, in the login query need to find the corresponding account, it is necessary in the code to the account corresponding role and role corresponding to the authority load out, this is also reasonable.

Second, if I want to do a user list, for example, for the administrator to display the role of the account information, then in the corresponding serivce to write a return list<account> method and in the method loop to get the List<account The > object and loads the role of item and then returns, so that the same method cannot be called even though the same result type is returned by the service method that is called by the account list that does not display the role information (although the query conditions are the same). Cause just the interface to show different information of the same object will be more to write a bunch of code (and not much meaning, not easy to maintain), then the Opensessioninview please come out.

For opensessioninview Spring is available in 2 ways, namely:Opensessioninviewfilter and Opensessioninviewinterceptor , because the sample project is based on the Spring MVC framework, we use the opensessioninviewinterceptor as the Interceptor, In fact, the configuration is very simple to add in the Springservlet-config.xml configuration file, as follows:

<!--configurable Filter-<mvc:interceptors> <!--turn on Opensessioninview---<bean class= "ORG.SPR Ingframework.orm.hibernate4.support.OpenSessionInViewInterceptor "> <property name=" sessionfactory "ref=" s Essionfactory "/> </bean> <!--custom permission interception verification, if not defined mvc:mapping path will intercept all URL requests--< ; Bean class= "Com.website.hpuxiaoyoulu.web.auth.AuthInterceptor" ></bean> </mvc:interceptors>

Where <property name= "Sessionfactory" ref= "Sessionfactory" /> is the configuration file in the Springcontext-config.xml configuration file, you can refer to the configuration files of the sample project.

In addition , this opensessioninviewinterceptor is written for Spring 3. After X and the Mvc:annotation-driven is configured in the configuration file, the configuration in this project is in springservlet-config.xml :

<!--default annotation map Support--<mvc:annotation-driven validator= "validator" conversion-service= "Conversion-service"/& Gt

Well, now Opensessioninview has been configured to complete, you can remove lazy= "false", enjoy opensessioninview convenient bar.


SPRINGMVC Learning Series-PostScript open Project Opensessioninview

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.