Our last article spoke of DAO Layer code:
In this article we explain the service layer and action layer;
Service Layer:
Divided into interfaces and implementation classes, we mainly look at the implementation of the class: Gysemplserviceimpl
PackageYycg.business.service.impl;Importjava.util.List;Importorg.springframework.beans.factory.annotation.Autowired;ImportYycg.business.dao.mapper.GysypmlMapperCustom;ImportYycg.business.pojo.vo.GysypmlCustom;ImportYycg.business.pojo.vo.GysypmlQueryVo;ImportYycg.business.service.GysymplService; Public classGysemplserviceimplImplementsgysymplservice{@AutowiredGysypmlMapperCustom Gysymplmappercustom; @Override PublicList<gysypmlcustom>findgysympllist (String usergysid,gysypmlqueryvo gysymplqueryvo)throwsException {//in order to prevent bugs. Here do a non-null check, if the pass in is not empty, then directly to pass in that assignment to him, if the pass in is empty//then create a newgysymplqueryvo=gysymplqueryvo!=NULL? Gysymplqueryvo:NewGysypmlqueryvo (); /*** Why do we get another one here? Because a gysymplcustom may have been passed in on the page. * So it's not empty to judge if it comes in. * * */Gysypmlcustom Gysymplcustom=Gysymplqueryvo.getgysymplcustom (); if(gysymplcustom==NULL)//if it's empty, then new one. Anyway, our goal is to set the value of Usergysid in. {Gysymplcustom=NewGysypmlcustom (); } //Set Data scope permissionsGysymplcustom.setid (USERGYSID); List<GysypmlCustom> listgygysymplcustoms=gysymplmappercustom.findgysympllist (GYSYMPLQUERYVO); returnlistgygysymplcustoms; } @Override Public intFindgysypmlcount (String usergysid,gysypmlqueryvo Gysymplqueryvo)throwsException {//in order to prevent bugs. Here do a non-null check, if the pass in is not empty, then directly to pass in that assignment to him, if the pass in is empty//then create a newgysymplqueryvo=gysymplqueryvo!=NULL? Gysymplqueryvo:NewGysypmlqueryvo (); /*** Why do we get another one here? Because a gysymplcustom may have been passed in on the page. * So it's not empty to judge if it comes in. * * */Gysypmlcustom Gysymplcustom=Gysymplqueryvo.getgysymplcustom (); if(gysymplcustom==NULL)//if it's empty, then new one. Anyway, our goal is to set the value of Usergysid in. {Gysymplcustom=NewGysypmlcustom (); } //Set Data scope permissionsGysymplcustom.setid (USERGYSID); intCount=Gysymplmappercustom.findgysypmlcount (GYSYMPLQUERYVO); returncount; }}
Then look at the action layer:
Packageyycg.business.action;Importjava.util.List;Importjavax.servlet.http.HttpSession;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.ResponseBody;ImportYycg.base.pojo.vo.ActiveUser;ImportYycg.base.pojo.vo.PageQuery;ImportYycg.base.process.context.Config;ImportYycg.base.process.result.DataGridResultInfo;ImportYycg.business.pojo.vo.GysypmlCustom;ImportYycg.business.pojo.vo.GysypmlQueryVo;ImportYycg.business.service.GysymplService, @Controller @requestmapping ("/YPML") Public classgysymplaction {@Autowired gysymplservice gysymplservice; //go to the query page@RequestMapping ("/QUERYGYSYPML") PublicString QUERYGYSYPML (model model)throwsException {return"/BUSINESS/YPML/QUERYGYSYPML"; } //Query Result set@RequestMapping ("/querygysympl_request") Public@ResponseBody datagridresultinfo querygysympl_request (HttpSession session,gysypmlqueryvo Gysypmlqueryvo,intPageintRows
throwsException {//Current user information go to the session to get it. Activeuser activeuser=(Activeuser) Session.getattribute (Config.activeuser_key); /*** At the beginning of the time can not understand, why pass the user belongs to the unit ID, subconsciously think is not should pass is the user's ID, * Later think not ah, how may be the user's ID, because it is the supplier so a big idea in the provision of goods, is a supplier of units, * So should be supplier Ah, there are many suppliers in the supply of drugs, so is the supplier's ID. * * */ //the unit to which the user belongsString Usergysid=activeuser.getsysid ();//Unit ID//total number of columns intTotal=Gysymplservice.findgysypmlcount (Usergysid, Gysypmlqueryvo); //ListPagequery pagequery=NewPagequery (); Pagequery.setpageparams (total, rows, page); //Set Paging Parametersgysypmlqueryvo.setpagequery (pagequery); //Paged Query ListList<gysypmlcustom> list=gysymplservice.findgysympllist (Usergysid, Gysypmlqueryvo); Datagridresultinfo Datagridresultinfo=NewDatagridresultinfo (); Datagridresultinfo.settotal (total); Datagridresultinfo.setrows (list); returnDatagridresultinfo; } }
Final commissioning:
I ran into two questions when I was debugging:
Mainly due to two points:
1:gysypmlmappercustom.xml The package path and name to be the same as the name of the Mapper interface:
Mapper Interface:
be identical. Otherwise direct error:
Debug results:
Debug OK.
032 Medical Project-Module III: Drug supplier Catalog Module--service layer and action layer and debug