Java EE SSH Framework baseaction extraction and other aspects of code optimization

Source: Internet
Author: User

For design references to previous entity classes my previous blog: http://blog.csdn.net/u013082989/article/details/50983650

The project file has been put on GitHub and you are welcome to Follow,star.Address:Https://github.com/lawlite19/SmartEducation
One: Extract Baseaction (1) First say the use of modeldriven, such as user login, I want to get interface input user account usernum and user password password, you can declare in the action class and implement the Get, set method, Corresponds to the Name property of the interface input, and then you can get(You can also declare a user user object in the action, which corresponds to the attribute write User.usernum,user.password to the interface input)
Useafter Modeldriven, the Name property in the interface corresponds to the property of the object

You can declare an object model directly in the class and get the properties of the object by using the Model.get () method.




(2) Extract the Baseaction class, first of all why to extract, because we in each action to define the corresponding object model, we can extract out declared as generics, by reflection to get the type of the object.
There is a service interface object that may be reused in each action, and we also declare the interface object used in Baseaction as the protected type (just a few days ago, a second-interview C + +, a review of the relationship between classes), You can get the service interface object of the parent class as long as you inherit baseaction.


Two: Call code optimization on the DAO layer(1) because before we in the Basedao the public to increase, delete, change, check out the code, you can refer to my blog after the note: http://blog.csdn.net/u013082989/article/details/ 50964133 And because our service layer is often called toAdd, delete, change, check, so the service layer again to write again, and then to call the DAO layer, so repeat (of course, no problem), we now put the business Layer service and the DAO layer together, the Basedao renamed to Daosupport, Service layer inherits Daosupport can

The DAO layer is not needed.

Querying the database directly at the service layer through the GetSession () method(GetSession is in Daosupport, declared as protected type, can be obtained in subclasses)
(2) After the optimized diagram:


Java EE SSH Framework baseaction extraction and other aspects of code optimization

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.