基礎資料管理
修改
basic.jsp頁面修改"修改"連結的位址
進入BasicDataController中的basicUpdate方法中,此方法不用調整
@RequestMapping("/basicUpdate")
public String basicUpdate(Integer id,Model m){
basicService.getUpdateInfo(id,m);
return "basic/basicUpdate";
}
然後就如service中的getUpdateInfo方法
@Override
public void getUpdateInfo(Integer id, Model m) {
BasicDataExample example = new BasicDataExample();
example.createCriteria().andParentIdIsNull();
// 查詢所有的父類型
List<BasicData> parents = basicDataMapper.selectByExample(example );
m.addAttribute("parents", parents);
if(id != null && id > 0){
// 表示是更新資料,根據id查詢出對應的資料資訊
BasicData data = basicDataMapper.selectByPrimaryKey(id);
m.addAttribute("basic", data);
}
}
進入basicUpdate.jsp頁面回寫資料
<form action="/basic/saveOrUpdate">
<ul class="forminfo">
<input type="hidden" name="baseId" value="${basic.baseId }">
<li><label>基礎資料</label>
<input name="baseName" type="text" value="${basic.baseName }"
class="dfinput" />
<i>基礎資料不能超過30個字元</i>
</li>
<li><label>描述</label>
<input name="baseDesc" type="text" value="${basic.baseDesc }"
class="dfinput" />
</li>
<li><label>所屬類型</label>
<div class="vocation">
<select class="select1" name="parentId">
<option value="0">--本身就是大類--</option>
<c:forEach items="${ parents}" var="parent">
<option value="${parent.baseId }" ${parent.baseId eq basic.parentId?"selected":"" }>
${parent.baseName }
</option>
</c:forEach>
</select>
</div>
<i></i>
</li>
<li><label> </label>
<input name="" type="submit"
class="btn" value="确認儲存" /></li>
</ul>
</form>
送出後controller中代碼,
@RequestMapping("/saveOrUpdate")
public String saveOrUpdate(BasicData bd){
if(bd.getParentId()==0){
bd.setParentId(null);
}
if(bd.getBaseId()!=null && bd.getBaseId() > 0){
// 表示更新資料
basicService.updateBasicData(bd);
}else{
// 表示添加資料
basicService.addBasicData(bd);
}
return "redirect:/basic/query";
}
通路測試
修改功能沒問題,驗證可自行加上~
删除
basic.jsp删除菜單按鈕修改位址
控制器處理請求方法
@RequestMapping("/delete")
public String delete(Integer id){
basicService.deleteBasicData(id);
return "redirect:/basic/query";
}
service實作方法
@Override
public void deleteBasicData(int id) {
basicDataMapper.deleteByPrimaryKey(id);
}
注意删除基礎資料的時候如果删除的也類别資料,我們需要一并将對應的具體資料也給删除掉,是以要修改下deleteByPrimaryKey的sql語句
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from t_basicdata
where base_id = #{baseId,jdbcType=INTEGER}
or parent_id = #{baseId,jdbcType=INTEGER}
</delete>
測試