Easyui+Spring+Mybatis完整示例(后台)

Controller:

/**软件管理*/
@Controller
@RequestMapping("/deploySoftware")
public class DeploySoftwareController extends BaseController {

	@Autowired
	private DeploySoftwareService deploySoftwareService;

	/**跳转到软件信息页面 */
	@RequestMapping("/list")
	public String softwareInfoList() {
		return "/deploySoftware/deploySoftwareInfoList";
	}

	/**分页显示软件信息*/
	@RequestMapping("/getSoftwareInfoList")
	@ResponseBody
	public 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})
	@ResponseBody
	public 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})
	@ResponseBody
	public 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 {
	@Autowired
	private DeploySoftwareInfoMapper deploySoftwareInfoMapper;

	@Override
	public 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);
	}
	@Override
	public DeploySoftwareInfo getSoftwareInfoById(Integer id) {

		return deploySoftwareInfoMapper.getSoftwareInfoById(id);
	}

	@Override
	public 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;
		}
	}
	@Override
	public 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;
			}
		}
	}
	@Override
	public 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_info
 		WHERE 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_info
 		WHERE soft_name = #{softName}
 	</select>
 	<delete id="delDeploySoftwareInfo" >
 		DELETE FROM deploy_software_info
 		WHERE id IN
 		<foreach collection="list" open="(" separator="," close=")" item="item">
 			#{item}
 		</foreach>
 	</delete>
</mapper>

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-06 07:50:06

Easyui+Spring+Mybatis完整示例(后台)的相关文章

Spring+Mybatis开发示例

写下来留个纪念(^~^)大神可飘过 1,实现Spring+Mybatis+数据源的配置 2,实现枚举到数据库TINYINT类型的转换 3,slf4j日志配置方法 4,数据库增+删+改+查操作 5,实现效果界面+项目配置目录树       6,关键代码: a)控制器 package com.fresh.lyh.simple.controller; import com.fresh.lyh.simple.model.Simple; import com.fresh.lyh.simple.model.

Spring整合MyBatis完整示例

为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简单的图书管理功能,主要使用到的技术包含Spring.MyBatis.Maven.MySQL及简单MVC等.最后的运行效果如下所示: 项目结构如下: 一.新建一个基于Maven的Web项目 1.1.创建一个简单的Maven项目,项目信息如下: 1.2.修改层面信息,在项目上右键选择属性,再选择“Project

Spring集成MyBatis完整示例

为了梳理前面学习的<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>中的内容,准备做一个完整的示例完成一个简单的图书管理功能,主要使用到的技术包含Spring.MyBatis.Maven与MySQL等.最后的运行效果如下: 项目结构如下: 一.新建一个基于Maven的Web项目 1.1.创建一个简单的Maven项目,项目信息如下: 1.2.修改层面信息,在项目上右键选择属性,再选择“Project Face

Spring + iBATIS完整示例

最近研究了一下Spring + iBATIS.发现看别人的例子是一回事,自己写一个完整的应用又是另外一回事.自己受够了网上贴的一知半解的代码. iBATIS是一个持久化框架,封面了sql过程,虽然sql语句需要自己写.另外,我觉得对于初学者来说,完整的示例真的很重要,不然不知道文件是如果放置的. 所有的第三包都需要加上,spring.ibatis.-2.3.3.720.jar.sqlijdbc.jar.oscache-2.4.jar.commons-pool-1.3.jar.commons-db

Spring MVC 完整示例

在本例中,我们将使用Spring MVC框架构建一个入门级web应用程序.Spring MVC 是Spring框架最重要的的模块之一.它以强大的Spring IoC容器为基础,并充分利用容器的特性来简化它的配置. MVC框架是什么 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计模式.它主要通过分离模型.视图及控制器在应用程序中的角色将业务逻辑从界面中解耦.通常,模型负责封装应用程序数据在视图层展示.视图仅仅只是展示这些数据,不包含任何业务逻辑.控制器负责接收来自用户的

Spring+Mybatis+SpringMVC后台与前台分页展示实例(附工程)

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文实现了一个后台由Spring+Mybatis+SpringMVC组成,分页采用PageHelper,前台展示使用bootstrap-paginator来显示效果的分页实例.整个项目由maven构成.这里主要讲了分页的实例,框架怎么搭建就不再说明,主要是在这里的基础上来增加分页功能的.注意,此文是在这个基础 Spring+Mybatis+SpringMVC+Maven+MySql搭建

springmvc 项目完整示例04 与mybatis的整合

百度百科: MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis .2013年11月迁移到Github. iBATIS一词来源于“internet”和“abatis”的组合,是一个基于Java的持久层框架.iBATIS提供的持久层框架包括SQL Maps和Data Access Objects(DAO) 来源: http://baike.baidu.com/

Spring+Mybatis+SpringMVC后台与前台分页展示实例(附工程)(转)

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文实现了一个后台由Spring+Mybatis+SpringMVC组成,分页采用PageHelper,前台展示使用bootstrap-paginator来显示效果的分页实例.整个项目由maven构成.这里主要讲了分页的实例,框架怎么搭建就不再说明,主要是在这里的基础上来增加分页功能的.注意,此文是在这个基础 Spring+Mybatis+SpringMVC+Maven+MySql搭建

Spring+Mybatis+SpringMVC后台与前台分页展示实例

摘要:本文实现了一个后台由spring+Mybatis+SpringMVC组成,分页采用PageHelper,前台展示使用bootstrap-paginator来显示效果的分页实例.整个项目由maven构成.这里主要讲了分页的实例,框架怎么搭建就不再说明,主要是在这里的基础上来增加分页功能的.注意,此文是在这个基础 Spring+Mybatis+SpringMVC+Maven+MySQL搭建实例 之上来做分页的,建议文中看不懂的配置可以看看这里. 整个工程下载(旧版本,日志打印使用log4j,数