System Management Module _ Department Management _ Improve _ Extract Add and modify common code in JSP pages _ in the display Layer extraction baseaction_ Merge service layer and DAO layer

Source: Internet
Author: User

System Management Module _ Department Management _ Improvement 1: Extract the common code from the JSP page to add and modify

Commons.jspf

<%@ Pagelanguage= "Java"Import= "java.util.*"pageencoding= "UTF-8"%><%@ taglibprefix= "S"URI= "/struts-tags" %>    <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />    <Scriptlanguage= "JavaScript"src= "${pagecontext.request.contextpath}/script/jquery.js"></Script>    <Scriptlanguage= "JavaScript"src= "${pagecontext.request.contextpath}/script/pagecommon.js"CharSet= "Utf-8"></Script>    <Scriptlanguage= "JavaScript"src= "${pagecontext.request.contextpath}/script/pageutils.js"CharSet= "Utf-8"></Script>    <Linktype= "Text/css"rel= "stylesheet"href= "${pagecontext.request.contextpath}/style/blue/pagecommon.css" />    <Scripttype= "Text/javascript">    </Script>

Insert in Page

list.jsp, savelist.jsp

System Management Module _ Department Management _ Improvement 2: Extracting baseaction in the display layer

The two action inside to declare service to do business operations, all to implement the Modeldriven interface, the future action will also implement the interface to encapsulate the parameters

We do this

Baseaction.java

 Public Abstract classBaseaction<t>extendsActionsupportImplementsModeldriven<t> {    //==================modeldriven's support ==========================    protectedT model;  Publicbaseaction () {Try {            //get the real type of model by reflectionParameterizedtype pt = (parameterizedtype) This. GetClass (). Getgenericsuperclass (); Class<T> clazz = (class<t>) pt.getactualtypearguments () [0];//the True type of the first parameter//creating an instance of a model by reflection |Model =clazz.newinstance (); } Catch(Exception e) {Throw NewRuntimeException (e); }    }     PublicT Getmodel () {returnmodel; }    //declaration of the ==================service instance ==========================//There is an implementation class for the interface, you want to use it to create, using @resource injection@ResourceprotectedDepartmentservice Departmentservice; //use the Service in action, annotate @resource, and add annotations on the Roleserviceimpl class @service@Resourceprotectedroleservice RoleService;}

System Management Module _ Department Management _ Improvement 3: Merge service layer with DAO layer (transaction management issues are resolved later)

Roleaction calls Roleservice-->roleserviceimpl,roleserviceimpl and calls Roledao-->roledaoimpl

View + Service + Dao

View + Service (formerly service+ original DAO)

All interfaces are marked with this, which means obsolete, no longer recommended

DAO The interface implementation class also does this

No longer call DAO, put

Departmentserviceimpl.java and Roleserviceimpl.java call the DAO method to comment out the

put Basedao.java, Basedaoimpl renamed to Daosupport.java, Daosupportimpl.java

inheriting Daosupport, you don't have to write these public methods yourself.

System Management Module _ Department Management _ Improve _ Extract Add and modify common code in JSP pages _ in the display Layer extraction baseaction_ Merge service layer and DAO layer

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.