这是我的控制器
@RequestMapping(value = "/deleteMultiple", method = RequestMethod.POST)
public ModelAndView deleteEmp(@ModelAttribute("employee") Employee emp,@RequestParam(value="Id",required=false) String Id,Model model) {
List<Employee> empList = empService.getEmpList();
List<Employee> empListById = empService.getemp_IdDetails(Id);
empList=empService.searchEmpDetails(emp);
empList.addAll(empListById);
Employee emp1=new Employee();
if(empList!=null){
model.addAttribute("delete", empList);
if(empList.isEmpty()){
model.addAttribute("message","This Employee Details are not present");
}
}
model.addAttribute("employee", emp1);
return new ModelAndView("delete","empList",empList);
}
这是我的sql
@Override
public List<Employee> getemp_IdDetails(String emp_Ids){
List<Employee> empList = new ArrayList<Employee>();
String sql="select * from EmpDetails where emp_Id IN" + " ("+emp_Ids+") ";
sql.replace("emp_Id", emp_Ids);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
empList = jdbcTemplate.query(sql, new EmployeeRowMapper());
System.out.println("empList:"+empList.size());
return empList;
}
这是我的jsp
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Drop down</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#delete").click(function(){
var d = [];
$.each($("#delete option:selected"), function(){
d.push($(this).val());
});
var s=(d.join(", "));
console.log(s);
$("#delete_empId").val(s);
console.log($("#delete_empId").val());
});
});
</script>
</head>
<body>
<div align="center">
<form:form method="post" action="${pageContext.request.contextPath}/deleteMultiple" modelAttribute="employee">
<table>
<tr>
<td>First Name :</td>
<td><form:input path="firstName" /></td>
</tr>
<tr>
<td>Last Name :</td>
<td><form:input path="lastName" /></td>
</tr>
<tr>
<td>emp_Id :</td>
<td><form:input path="emp_Id" /></td>
</tr>
<tr>
<td>email_Id :</td>
<td><form:input path="email_ID"/></td>
</tr>
<tr>
<td>phone_No :</td>
<td><form:input path="phone_No"/></td>
</tr>
<tr>
<td>City :</td>
<td><form:input path="city"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Search" /></td>
</tr>
</table>
<input type= "hidden" id="delete_empId" name="delete_empId" />
</form:form>
</div>
<div align="center">
<h2 style="color:blue">SelectBox:</h2>
<form:form method="post" action="${pageContext.request.contextPath}/deleteMultipleEmpDetails">
<select id="delete" multiple name="employees">
<c:forEach items="${empList}" var="employee">
<option value= "${employee.emp_Id}" >${employee.firstName}</option>
${msg}
</c:forEach>
</select>
<input type="submit" name="delete" value="delete">
</form:form>
</div>
<div>
<h4 style="color:red">${message}</h4>
</div>
</body>
</html>
这是我的代码我正在从jsp中重新获取值并将值传递给我的controller.So我需要用emp_Ids替换emp_Id的值。我已经知道sql中的replace函数是coorect.I我得到null指针异常。