当我试图在spring mvc中删除时返回null值

时间:2017-11-24 07:18:18

标签: 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);
        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);
}

2 个答案:

答案 0 :(得分:0)

我认为不需要将2个参数传递给此函数。试试这个...

jdbcTemplate.update(Sql);

答案 1 :(得分:0)

返回相同的值,

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>