控制器内:
public ModelAndView addPosition() {
Map<String, Object> map = new HashMap<String, Object>();
return new ModelAndView("admin/positionAdd",map);
}
public String savePosition(HttpServletRequest request) throws IOException {
String post_type = request.getParameter("post_type");
String post_code = request.getParameter("post_code");
String post_name = request.getParameter("post_name");
String post_duties = request.getParameter("post_duties");
String parent_id = request.getParameter("parent_id");
String check_state = request.getParameter("check_state");
String check_note = request.getParameter("check_note");
String state = request.getParameter("state");
Position position = new Position();
position.setId(Common.returnUUID());
position.setPost_type(post_type);
position.setPost_code(post_code);
position.setPost_name(post_name);
position.setPost_duties(post_duties);
position.setParent_id(parent_id);
position.setCheck_state(check_state);
position.setCheck_note(check_note);
position.setState(state);
positionService.insert(position);
return "redirect:positionList.do";
}
@RequestMapping("admin/editPosition.do")
public ModelAndView editPosition(ModelMap modelMap, String id) {
Position position = (Position) positionService.selectByID(id);
modelMap.put("p", position);
return new ModelAndView("admin/positionEdit", modelMap);
}
public String editPosition(@ModelAttribute("Position") Position position)
throws IOException {
positionService.update(position);
return "redirect:positionList.do"; }
public String deletePosition(String id) {
Position position = new Position();
position.setId(id);
positionService.delete(position);
return "redirect:positionList.do";
}
public String positionList(HttpSession session,
HttpServletRequest request,HttpServletResponse response) {
String post_type = request.getParameter("post_type");
@SuppressWarnings("unchecked")
List<Position> pList = this.positionService.selectList(post_type);
StringBuffer sb= new StringBuffer();
sb.append("<tr id = 'select'>");
for (Position position : pList) {
sb.append("<td> <input type='checkbox' id='position' name='position' value ='"+position.getPost_code()+"'>"
+position.getPost_name()+ "</td>");
}
sb.append("</tr>");
try {
response.getWriter().println(sb.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
JSP页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<form name="form1" id="myform" method="post" action="doAddPosition.do">
<table border="0" width="400">
<tr>
<td width="100">职位类别:</td>
<td width="300"><select name="post_type" id="post_type" onChange="changeCK()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select></td>
</tr>
<tr>
<td width="100">岗位编码:</td>
<td width="300"><input type="text" name="post_code" /></td>
</tr>
<tr>
<td width="100">岗位名称:</td>
<td width="300"><input type="text" name="post_name" /></td>
</tr>
<tr>
<td width="100">岗位职责:</td>
<td width="300"><input type="text" name="post_duties" /></td>
</tr>
<tr>
<td width="100">父岗位id:</td>
<td width="300"><input type="text" name="parent_id" /></td>
</tr>
<tr>
<td width="100">审核备注:</td>
<td width="300"><input type="text" name="check_note" /></td>
<tr>
<td width="100">状态:</td>
<td width="300"><select name="state" id="state">
<option value="1">有效</option>
<option value="2">无效</option>
</select>
</td>
</tr>
</table>
<div id="scope" style="display:none">
<table>
<tr id = "select"><td>请选择</td></tr>
</table>
<button type="button" onClick="setVals()">确定</button>
</div>
<div style="margin-top:20px;">
<input type="submit" value="保存" />
<button type="button" onclick="window.location='./positionList.do'">返回</button>
</div>
</form>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
修改企业岗位 function changeBoxes(action) { var oForm = document.forms["myForm1"]; var oCheckBox = oForm.college; for(var i=0;i<oCheckBox.length;i++) //遍历每一个选项 if(action<0) //反选 oCheckBox[i].checked = !oCheckBox[i].checked; else //action为1是则全选,为0时则全不选 oCheckBox[i].checked = action; }
<form name="form1" method="post" action="doEditPosition.do">
<input type="hidden" name="id" name="id" value="${p.id}">
<table border="1" width="400">
<tr>
<td width="100">职位类别:</td>
<td width="300"><input type="text" name="post_type"
value="${p.post_type}">
</td>
</tr>
<tr>
<td width="100">岗位编码:</td>
<td width="300"><input type="text" name="post_code"
value="${p.post_code}">
</td>
</tr>
<tr>
<td width="100">岗位名称:</td>
<td width="300"><input type="text" name="post_name"
value="${p.post_name}">
</td>
</tr>
<tr>
<td width="100">岗位职责:</td>
<td width="300"><input type="text" name="post_duties"
value="${p.post_duties}" />
</td>
</tr>
<tr>
<td width="100">父岗位id:</td>
<td width="300"><input type="text" name="parent_id"
value="${p.parent_id}" />
</td>
</tr>
<tr>
<td width="100">审核备注:</td>
<td width="300"><input type="text" name="check_note"
value="${p.check_note}" />
</td>
</tr>
<tr>
<td width="100">状态:</td>
<td width="300"><input type="text" name="state"
value="${p.state}" />
</td>
</tr>
</table>
<div style="margin-top:20px;">
<input type="submit" value="保存" />
<button type="button" onclick="window.location='./positionList.do'">返回</button>
</div>
</form>