SSH Framework Integration Implementation Java Three Layer architecture instance (i)

Source: Internet
Author: User

The HTML foreground sends the request code:

1 <TR>2     <TD>Select a time to collect a dispatch</TD>3     <TD>4         <inputtype= "text"name= "Taketimeid"class= "Easyui-combobox"Required= "true"5 data-options= "url: '". /.. /taketime_findall.action ',6 Valuefield: ' id ', TextField: ' Name ' " />7     </TD>8 </TR>

Taketimeaction Code:

1@Namespace ("/")2@ParentPackage ("Json-default")3 @Controller4@Scope ("Prototype")5  Public classTakeTimeAction2extendsBaseaction<taketime> {6 @Autowired7     PrivateTakeTimeService2 Taketimeservice;8@Action (value= "Taketime_findall", results={@Result (name= "Success", type= "JSON")})9      PublicString FindAll () {Ten         //Call the business layer and query all the time of the delivery OneList<taketime> Taketime =Taketimeservice.findall (); A         //Press-in value stack return - Actioncontext.getcontext (). Getvaluestack (). push (Taketime); -         returnSUCCESS; the     } -}

Extract the action public class Baseaction code:

1  Public Abstract classBaseaction<t>extendsActionsupportImplements2Modeldriven<t> {3     //model-driven4     protectedT model;5 @Override6      PublicT Getmodel () {7         returnmodel;8     }9     //constructor completes model instantiationTen      Publicbaseaction () { One         //constructs a subclass action object that gets the generic type of the inherited parent A         //Areaaction extends Baseaction<area> -         //baseaction<area> -Type Genericsuperclass = This. GetClass (). Getgenericsuperclass (); the         //gets the first generic parameter of the type -Parameterizedtype Parameterizedtype =(Parameterizedtype) Genericsuperclass; -Class<t> Modelclass = (class<t>) Parameterizedtype -. getactualtypearguments () [0]; +         Try { -Model =modelclass.newinstance (); +}Catch(Instantiationexception |illegalaccessexception e) { A e.printstacktrace (); atSYSTEM.OUT.PRINTLN ("Model construction failed ..."); -         } -     } -     //receive paging query parameters -     protected intpage; -     protected introws; in      Public voidSetpage (intpage) { -          This. page =page; to     } +      Public voidSetrows (introws) { -          This. rows =rows; the     } *     //The method of pressing the value stack into the data of paged query results $     protected voidPushpagedatatovaluestack (page<t>pagedata) {Panax Notoginsengmap<string, object> result =NewHashmap<string, object>(); -Result.put ("Total", Pagedata.gettotalelements ()); theResult.put ("Rows", Pagedata.getcontent ()); + Actioncontext.getcontext (). Getvaluestack (). push (result); A     } the}

Time-of-delivery interface Taketimeservice code:

1  Public Interface TakeTimeService2 {2     // check all delivery times 3     List<taketime> findAll (); 4 }

The Receive-send interface implements the class Taketimeserviceimpl code:

1 @Service2 @Transactional3  Public classTakeTimeServiceImpl2ImplementsTakeTimeService2 {4 @Autowired5     PrivateTakeTimeRepository2 taketimerepository;6 @Override7      PublicList<taketime>FindAll () {8         returnTaketimerepository.findall ();9     }Ten}

DAO Layer Taketimerepository Code:

1  Public Interface extends Jparepository<taketime, integer> {}

SSH Framework Integration Implementation Java Three Layer architecture instance (i)

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.