Easyui + Spring + Mybatis complete example (background)
Controller:
/** Software management */@ Controller @ RequestMapping (/deploySoftware) public class DeploySoftwareController extends BaseController {@ Autowiredprivate DeploySoftwareService deploySoftwareService; /** jump to the software information page */@ RequestMapping (/list) public String softwareInfoList () {return/deploySoftware/deploySoftwareInfoList ;} /** display the software information by page */@ RequestMapping (/getSoftwareInfoList) @ ResponseBodypublic Pagination getSoftwareInfoList (Response R IdModel model, String softName) {int pageNo = model. getPage (); int pageSize = model. getRows (); return deploySoftwareService. getSoftwareInfoList (softName, pageNo, pageSize);}/** jump to the Software Information Modification page */@ RequestMapping (/toEditSoftwareInfo/{id}) public String toEditSoftwareInfo (@ PathVariable (id) integer id, Model model) {DeploySoftwareInfo deploySoftwareInfo = deploySoftwareService. getSoftwareInfoById (id); model. addAtt Ribute (deploySoftwareInfo, deploySoftwareInfo); return/deploySoftware/editSoftwareInfo;}/** modify | add software information */@ RequestMapping (value =/editSoftwareInfo, method = {RequestMethod. POST, RequestMethod. GET}) @ ResponseBodypublic String editSoftwareInfo (DeploySoftwareInfo deploySoftwareInfo, HttpServletRequest request) {Message message = new Message (); Integer id = deploySoftwareInfo. getId (); try {if (id! = Null) {// modify DeploySoftwareInfo updateDeploySoftwareInfo = new DeploySoftwareInfo (); updateDeploySoftwareInfo. setId (id); updateDeploySoftwareInfo. setSoftName (StringUtils. trim (deploySoftwareInfo. getSoftName (); updateDeploySoftwareInfo. setInstallPath (StringUtils. trim (deploySoftwareInfo. getInstallPath (); updateDeploySoftwareInfo. setSoftDesc (deploySoftwareInfo. getSoftDesc (); message = deploySoftwareService. updateSoftwareInfo (updateDeploySoftwareInfo);} else {// added DeploySoftwareInfo addDeploySoftwareInfo = new DeploySoftwareInfo (); addDeploySoftwareInfo. setSoftName (StringUtils. trim (deploySoftwareInfo. getSoftName (); addDeploySoftwareInfo. setInstallPath (StringUtils. trim (deploySoftwareInfo. getInstallPath (); addDeploySoftwareInfo. setSoftDesc (deploySoftwareInfo. getSoftDesc (); message = deploySoftwareService. addSoftwareInfo (addDeploySoftwareInfo);} return message. getContent ();} catch (Exception e) {e. printStackTrace (); return Error ;}}/** use id to delete software information */@ RequestMapping (value = delDeploySoftwareInfo/{ids}, method = {RequestMethod. POST, RequestMethod. GET}) @ ResponseBodypublic String delDeploySoftwareInfo (@ PathVariable (ids) List ids) {try {deploySoftwareService. delDeploySoftwareInfo (ids); return success;} catch (Exception e) {e. printStackTrace (); return error ;}}}Service:
/*** Software management service ** date: 3:52:45 */@ Service @ Transactionalpublic class implements extends {@ Autowiredprivate extends DeploySoftwareInfoMapper; @ Overridepublic Pagination getSoftwareInfoList (String softName, int pageNo, int pageSize) {String likeSoftName = null; if (softName! = Null) {likeSoftName = % + softName + %;} PageBounds pb = new PageBounds (pageNo, pageSize, null, true); PageList
List = deploySoftwareInfoMapper. getSoftwareInfoList (likeSoftName, pb); return new Pagination (pageNo, pageSize, list. getPaginator (). getTotalCount (), list) ;}@ Overridepublic DeploySoftwareInfo getSoftwareInfoById (Integer id) {return deploySoftwareInfoMapper. getSoftwareInfoById (id) ;}@ Overridepublic Message addSoftwareInfo (DeploySoftwareInfo deploySoftwareInfo) {Message msg = new Message (); String softName = deploySoftwareInfo. getSoftName (); boolean hasExists = deploySoftwareInfoMapper. hasExists (softName)> 0; if (hasExists) {msg. setType (Type. error); msg. setContent (softName Repeat); return msg;} else {deploySoftwareInfoMapper. addSoftwareInfo (deploySoftwareInfo); msg. setType (Type. success); msg. setContent (success); return msg ;}@ Overridepublic Message updateSoftwareInfo (DeploySoftwareInfo deploySoftwareInfo) {Message msg = new Message (); String softName = deploySoftwareInfo. getSoftName (); DeploySoftwareInfo dInfoTemp = deploySoftwareInfoMapper. getSoftwareInfoById (deploySoftwareInfo. getId (); if (softName. equals (dInfoTemp. getSoftName () {// do not modify the program name deploySoftwareInfoMapper. updateSoftwareInfo (deploySoftwareInfo); msg. setType (Type. success); msg. setContent (success); return msg;} else {// modify the program name boolean hasExists = deploySoftwareInfoMapper. hasExists (softName)> 0; if (hasExists) {msg. setType (Type. error); msg. setContent (softName Repeat); return msg;} else {deploySoftwareInfoMapper. updateSoftwareInfo (deploySoftwareInfo); msg. setType (Type. success); msg. setContent (success); return msg ;}}@ Overridepublic void delDeploySoftwareInfo (List ids) {deploySoftwareInfoMapper. delDeploySoftwareInfo (ids );}}
Mapper:
/*** Software information-related data query interface * February 12, 2015 */@ Repository (deploySoftwareInfoMapper) public interface DeploySoftwareInfoMapper {/** query software information by page */PageList
GetSoftwareInfoList (@ Param (likeSoftName) String likeSoftName, PageBounds pb);/** query software information by id */DeploySoftwareInfo getSoftwareInfoById (@ Param (id) Integer id ); /** add software information */int addSoftwareInfo (DeploySoftwareInfo deploySoftwareInfo);/** modify software information */boolean updateSoftwareInfo (DeploySoftwareInfo deploySoftwareInfo ); /** search for the same program name */int hasExists (@ Param (softName) String softName);/** Delete the program by id */void delDeploySoftwareInfo (List ids );}
XML:
SELECT * FROM deploy_software_info WHERE 1 = 1AND soft_name like # {likeSoftName}
SELECT * FROM deploy_software_info WHERE id = # {id}
Insert into deploy_software_info (soft_name, install_path, soft_desc) VALUES (# {softName}, # {installPath}, # {softDesc })
UPDATE deploy_software_info SET soft_name =#{ softName}, install_path =#{ installPath}, soft_desc =#{ softDesc} WHERE id =#{ id}
SELECT count (1) FROM deploy_software_info WHERE soft_name =#{ softName}
Delete from deploy_software_info WHERE id IN
# {Item}