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>