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 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 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:
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} DELETE FROM deploy_software_info WHERE id IN #{item}