當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Easyui+Spring+Mybatis完整示例(后台)
生活随笔
收集整理的這篇文章主要介紹了
Easyui+Spring+Mybatis完整示例(后台)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Controller:
/**軟件管理*/ @Controller @RequestMapping("/deploySoftware") public class DeploySoftwareController extends BaseController {@Autowiredprivate DeploySoftwareService deploySoftwareService;/**跳轉到軟件信息頁面 */@RequestMapping("/list")public String softwareInfoList() {return "/deploySoftware/deploySoftwareInfoList";}/**分頁顯示軟件信息*/@RequestMapping("/getSoftwareInfoList")@ResponseBodypublic Pagination getSoftwareInfoList(DataGridModel model,String softName) {int pageNo = model.getPage();int pageSize = model.getRows();return deploySoftwareService.getSoftwareInfoList(softName,pageNo, pageSize);}/** 跳轉到軟件信息修改界面*/@RequestMapping("/toEditSoftwareInfo/{id}")public String toEditSoftwareInfo(@PathVariable("id")Integer id,Model model) {DeploySoftwareInfo deploySoftwareInfo = deploySoftwareService.getSoftwareInfoById(id);model.addAttribute("deploySoftwareInfo", deploySoftwareInfo);return "/deploySoftware/editSoftwareInfo";}/**修改|新增軟件信息*/@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) {//修改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 {//新增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";}}/** 通過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: /*** 軟件管理service* date: 2015-8-19 下午3:52:45*/ @Service @Transactional public class DeploySoftwareServiceImpl implements DeploySoftwareService {@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();DeploySoftwareInfo dInfoTemp = deploySoftwareInfoMapper.getSoftwareInfoById(deploySoftwareInfo.getId());if (softName.equals(dInfoTemp.getSoftName())) {//不修改程序名deploySoftwareInfoMapper.updateSoftwareInfo(deploySoftwareInfo);msg.setType(Type.success);msg.setContent("success");return msg;}else {//修改程序名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: /*** 軟件信息相關數據查詢接口* 2015年2月12日*/ @Repository("deploySoftwareInfoMapper") public interface DeploySoftwareInfoMapper {/** 分頁查詢軟件信息 */PageList<DeploySoftwareInfo> getSoftwareInfoList(@Param("likeSoftName")String likeSoftName,PageBounds pb);/**根據id查詢軟件信息*/DeploySoftwareInfo getSoftwareInfoById(@Param("id")Integer id);/**增加軟件信息*/int addSoftwareInfo(DeploySoftwareInfo deploySoftwareInfo);/** 修改軟件信息*/boolean updateSoftwareInfo(DeploySoftwareInfo deploySoftwareInfo);/** 查找有無相同程序名*/int hasExists(@Param("softName")String softName);/** 根據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"> <!-- 軟件信息數據查詢相關 --> <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"/><!-- 關聯軟件詳情集合 --><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_infoWHERE id = #{id}</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) FROM deploy_software_infoWHERE soft_name = #{softName}</select><delete id="delDeploySoftwareInfo" >DELETE FROM deploy_software_infoWHERE id IN<foreach collection="list" open="(" separator="," close=")" item="item">#{item}</foreach></delete> </mapper>總結
以上是生活随笔為你收集整理的Easyui+Spring+Mybatis完整示例(后台)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 银行柜员网申计算机水平要求高吗,银行网申
- 下一篇: Flink随笔(1)