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