上次我们实现了生产厂家的修改,这次我们再实现生产厂家的删除
删除我们分两种情况,一种是删除一条,一种是删除多条,我们都实现
我们首先在FactoryMapper.xml中设置删除配置语句:
<!-- 删除一条 --><delete id="deleteById" parameterType="string"> delete from factory_c where FACTORY_ID=#{id}</delete> <!-- 删除多条(一维字符串数组的形式) --><delete id="delete" parameterType="string"> delete from factory_c where FACTORY_ID in <foreach collection="array" item="id" open="(" close=")" separator=","> #{id} </foreach></delete>
然后我们来写dao层
由于我们的FactoryDaoImpl继承了BaseDaoimpl,所以里面有如下两个方法:
public void deleteById(Serializable id) { this.getSqlSession().delete(ns + ".deleteById", id);}public void delete(Serializable[] ids) { this.getSqlSession().delete(ns + ".delete", ids);}
我们就无需在FactoryDaoImpl里面写删除方法了
我们来看Service层
在FactoryService中加入如下两个方法的实现
@Overridepublic void delete(Serializable[] ids) { factoryDao.delete(ids);}@Overridepublic void deleteById(Serializable id) { factoryDao.deleteById(id);}
接下来看我们的Controller层
在FactoryController中编写有关delete的方法
//删除一个@RequestMapping("/basicinfo/factory/deleteById.action")public String deleteById(String id){ factoryService.deleteById(id); return "redirect:/basicinfo/factory/list.action";} //删除多条@RequestMapping("/basicinfo/factory/delete.action")public String delete(@RequestParam("id") String[] ids){ factoryService.delete(ids); return "redirect:/basicinfo/factory/list.action";}
我们还剩下删除的前台界面入口
我们在WEB-INF/pages/baseinfo/factory/jFactoryList.jsp中添加删除一个和删除多个的按钮:
<li id="delete"><a href="#" onclick="formSubmit('deleteById.action','_self');this.blur();">删除</a></li><li id="delete"><a href="#" onclick="formSubmit('delete.action','_self');this.blur();">删除N</a></li>
接下来我们重启服务器进行测试
首先点击“删除”来删除一条信息
删除成功!
然后点击“删除N”,然后选择多个进行删除
删除成功!
接下来我们来编写查看某个生产厂家的详细信息的代码
首先我们的FactoryMapper.xml之前我们已经写好了一个查询一个厂家的配置语句:
<!-- 查询一个 --><select id="get" parameterType="string" resultMap="factoryRM"> select * from factory_c where factory_id=#{id}</select>然后我们的dao层由于继承了BaseDaoImpl,所以自然包含了下面这个方法public T get(Serializable id) { return this.getSqlSession().selectOne(ns + ".get", id);}
Service层我们之前也写过相关方法
@Overridepublic Factory get(Serializable id) { return factoryDao.get(id);}
接下来我们在Controller层编写有关查看的方法
//查看@RequestMapping("/basicinfo/factory/toview.action")public String toview(String id,Model model){ Factory obj=factoryService.get(id); model.addAttribute("obj",obj); return "/baseinfo/factory/jFactoryView.jsp";}
最后,我们编写一下jFactoryView.jsp查看界面
<%@ page language="java" pageEncoding="UTF-8"%><%@ include file="../../base.jsp"%><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>查看厂家信息</title></head><body> <form method="post"> <div id="menubar"> <div id="middleMenubar"> <div id="innerMenubar"> <div id="navMenubar"> <ul> <li id="back"><a href="list.action">返回</a></li> </ul> </div> </div> </div> </div> <div class="textbox" id="centerTextbox"> <div class="textbox-header"> <div class="textbox-inner-header"> <div class="textbox-title"> 查看生产厂家信息 </div> </div> </div> <div> <div> <table class="commonTable" cellspacing="1"> <tr> <td class="columnTitle_mustbe">厂家名称:</td> <td class="tableContent">${obj.fullName }</td> <td class="columnTitle_mustbe">简称:</td> <td class="tableContent">${obj.factoryName }</td> </tr> <tr> <td class="columnTitle_mustbe">联系人:</td> <td class="tableContent">${obj.contacts }</td> <td class="columnTitle_mustbe">电话:</td> <td class="tableContent">${obj.phone }</td> </tr> <tr> <td class="columnTitle_mustbe">手机:</td> <td class="tableContent">${obj.mobile }</td> <td class="columnTitle_mustbe">传真:</td> <td class="tableContent">${obj.fax }</td> </tr> <tr> <td class="columnTitle_mustbe">检验员:</td> <td class="tableContent">${obj.inspector }</td> <td class="columnTitle_mustbe">排序号:</td> <td class="tableContent">${obj.orderNo }</td> </tr> <tr> <td class="columnTitle_mustbe">备注:</td> <td class="tableContent">${obj.cnote }</td> </tr> </table> </div> </div> </form></body></html>
我们之前在列表jFactoryList.jsp界面中有“查看”按钮:
<li id="view"><a href="#" onclick="formSubmit('toview.action','_self');this.blur();">查看</a></li>
重启服务器测试
点击查询
查询结果
转载请注明出处:http://blog.csdn.net/acmman/article/details/48318689
版权声明:本文为博主原创文章,未经博主允许不得转载。
- 1楼hgz0209昨天 18:30
- 这是黑马的项目吧?
- Re: u013517797昨天 21:44
- 回复hgz0209n是,某智的