Java 在SpringMVC中尝试删除时返回空值
Controller.javaJava 在SpringMVC中尝试删除时返回空值,java,spring,spring-mvc,Java,Spring,Spring Mvc,Controller.java @Controller public class DashboardController { @RequestMapping(value = "/delete", method = RequestMethod.GET) public String deleteRow(@RequestParam("vehicleNo") int vehicleNo) { userService.deleteRow(vehicleNo);
@Controller
public class DashboardController {
@RequestMapping(value = "/delete", method = RequestMethod.GET)
public String deleteRow(@RequestParam("vehicleNo") int vehicleNo) {
userService.deleteRow(vehicleNo);
System.out.println("delete... " + vReg.getVehicleNo());
return ("/dashboard");
}
}
DaoImpl
public void deleteRow(Integer vehicleNo) {
String Sql = null;
Sql = "delete from vehiclereg where vehicleNo= " + vehicleNo;
jdbcTemplate.update(Sql, vehicleNo);
System.out.println("Deleted Record with vehicleNo = " + vehicleNo);
}
我认为没有必要向这个函数传递两个参数。试试这个
jdbcTemplate.update(Sql);
返回相同的值
JSP主页
<table id="myTable" border="1" cellspacing="10" >
<thead align="center" >
<tr>
<th data-priority="6">ID</th>
<th data-priority="5">Owner Name</th>
<th data-priority="4">Vehicle No</th>
<th data-priority="3">License No.</th>
<th data-priority="2">Address</th>
<th data-priority="1">Pollution Date </th>
<th data-priority="6">Action</th>
</tr>
</thead>
<c:forEach var="vreg" items="${vRegList}" varStatus="loop">
<tbody>
<tr>
<th scope="row">${loop.index+ 1}</th>
<td>${vreg.fullname}</td>
<td>${vreg.vehicleNo}</td>
<td>${vreg.licenceNo}</td>
<td>${vreg.address}</td>
<td>${vreg.date3}</td>
<td> <a class="glyphicon glyphicon-pencil" href=edit?vehicleNo=${vreg.vehicleNo}></a> |
<a class="glyphicon glyphicon-trash" onclick="return confirm('Are you sure you want to delete?')" href="delete?vehicleNo=${vreg.vehicleNo}"></a>|
<a class="glyphicon glyphicon-envelope" href="sms"></a> </td>
</tr>
</tbody>
身份证件
所有者名称
车辆编号
许可证号。
住址
污染日期
行动
${loop.index+1}
${vreg.fullname}
${vreg.vehicleNo}
${vreg.LicenseNo}
${vreg.address}
${vreg.date3}
|
|
您的问题是?首先,您最好使用
RequestMethod.DELETE
执行删除操作。在DAO中也是一个错误的代码-您将参数连接到SQL,然后调用jdbcTemplate.update
,但它已经在SQL字符串中。尝试在不带参数的情况下调用jdbcTemplate.update(Sql)
。或者您可以将其传递给jdbcTempalte,但在这种情况下,不要将它们连接到SqlSql=“delete from vehiclereg,其中vehicleNo=?”;jdbcTemplate.update(Sql,vehicleNo)代码>