Easyui+spring+mybatis Complete Example (background)

Source: Internet
Author: User

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";} /** page displays software information */@RequestMapping ("/getsoftwareinfolist") @ResponseBodypublic pagination Getsoftwareinfolist ( Datagridmodel model,string softname) {int pageno = Model.getpage (); int pageSize = Model.getrows (); return Deploysoftwareservice.getsoftwareinfolist (Softname,pageno, pageSize);} /** Jump to Software Information modification interface */@RequestMapping ("/toeditsoftwareinfo/{id}") Public String Toeditsoftwareinfo (@PathVariable ("id") Integer Id,model Model) {Deploysoftwareinfo Deploysoftwareinfo = Deploysoftwareservice.getsoftwareinfobyid (ID); Model.addattribute ("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 UPDA Tedeploysoftwareinfo = 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 {//new 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";}} /** Remove software information by ID */@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:2015-8-19 pm 3:52:45 */@Service @transactionalpublic class Deploysoftwareserviceimpl implements D Eploysoftwareservice {@Autowiredprivate deploysoftwareinfomapper 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<deploysoftwareinfo> 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 ();D eploysoftwareinfo 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 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 {/* * Paging query Software information */pagelist<deploysoftwareinfo> getsoftwareinfolist (@Param ("Likesoftname") String Likesoftname, PageBounds pb);/** query Software Information */deploysoftwareinfo Getsoftwareinfobyid (@Param ("id") Integer ID);/** add software information */int Addsoftwareinfo (Deploysoftwareinfo deploysoftwareinfo);/** Modify software Information */boolean Updatesoftwareinfo (DeploySoftwareInfo Deploysoftwareinfo);/** find the same program name */int hasexists (@Param ("Softname") String softname);/** Remove program by ID */void Deldeploysoftwareinfo (List IDs);}
Xml:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.1//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" ><!-- Software information data query related--><mapper namespace= "Com.dnion.platform.dao.mybatis.DeploySoftwareInfoMapper" ><resultmap Type= "Deploysoftwareinfo" id= "Deploysoftwareinforesult" ><id column= "id" jdbctype= "INTEGER" property= "id"/ ><result column= "Soft_name" jdbctype= "VARCHAR" property= "Softname"/><result column= "Install_path" jdbctype= "varchar" property= "InstallPath"/><result column= "Soft_desc" jdbctype= "varchar" property= "SOFTDESC" /><!--associated Software details collection--><collection property= "Deploysoftwaredetaillist" oftype= "deploysoftwaredetail" column = "id" ><id column= "id" jdbctype= "integer" property= "id"/><result column= "sw_id" jdbctype= "integer" Property= "Swid"/><result column= "Version_code" jdbctype= "VARCHAR" property= "Versioncode"/><result Column= "Release_date" jdbctype= "VARCHAR" properTy= "ReleaseDate"/><result column= "package_name" jdbctype= "VARCHAR" property= "PackageName"/><result Column= "Package_size" jdbctype= "INTEGER" property= "packagesize"/><result column= "Package_md5" jdbcType= " varchar "property=" packageMD5 "/><result column=" major_files "jdbctype=" varchar "property=" majorfiles "/> <result column= "Release_note" jdbctype= "VARCHAR" property= "Releasenote"/></collection></resultmap ><select id= "getsoftwareinfolist" resultmap= "Deploysoftwareinforesult" >select *FROM deploy_software_info WHERE 1=1<if test= "Likesoftname! = null" >and soft_name like #{likesoftname}</if> </select> <select Id= "Getsoftwareinfobyid" resultmap= "Deploysoftwareinforesult" > select * from deploy_software_info WHERE id = #{id} &l t;/select> <insert id= "Addsoftwareinfo" parametertype= "Deploysoftwareinfo" usegeneratedkeys= "true" keyproperty= "id" > INSERT into Deploy_software_info (SOFT_NAME,INSTALL_PATH,SOFT_DESC)VALUES (#{softname},#{installpath},#{softdesc}) </insert> <update id= "Updatesoftwareinfo" parametertype= " Deploysoftwareinfo "> UPDATE deploy_software_info SET soft_name = #{softname}, Install_path = #{installpath},soft_ desc = #{softdesc} WHERE id = #{id} </update> <select id= "hasexists" resulttype= "INTEGER" > select COUNT (1) FRO M deploy_software_info WHERE soft_name = #{softname} </select> <delete id= "deldeploysoftwareinfo" > Delete FR OM deploy_software_info WHERE ID in <foreach collection= "list" open= "(" separator= "," close= ")" item= "Item" > #{item } </foreach> </delete></mapper>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Easyui+spring+mybatis Complete Example (background)

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.