这是Controller类
@RequestMapping(value = "/addToView", method = RequestMethod.POST, consumes = "application/json")
public Response addToView(@RequestBody ClassA classA){
return service1.addToview(classA);
}
这是DAO类
public Response addToview(ClassA classA){
try{
s=sf.openSession();
tx=s.beginTransaction();
String q="INSERT INTO abc(rollNo,name,english) VALUES("+classA.getRollNo()+","+classA.getName()+","+classA.getEnglish()+")";
System.out.println(q);
Query query=s.createSQLQuery(q);
query.executeUpdate();
response.setStatus(200);
response.setMessage("succesfull");
tx.commit();
}
catch (Exception e) {
System.err.println("Exception : " + e.getMessage());
response.setStatus(500);
response.setMessage("unsuccesfull");
tx.rollback();
} finally {
s.close();
}
return response;
}
这里查询正在sql控制台中执行,但是当我尝试 在代码中实现它不起作用,它给出了错误提示 无法准备声明