customJquery.js
var jsonURL=window.rootContext+'/get/all/information';
$table.DataTable({
lengthMenu: [[7,15,30,-1],['show 1 week','show 15 days','show 1 month','show All record']],
pageLength:30,
ajax:{
url: jsonURL,
dataSrc: ''
},
columns:[
{
data: 'id'
},
{
data: 'day'
},
{
data: 'month'
},
{
data: 'year'
},
{
data: 'eventName'
},
{
data: 'eventDescription'
},
{
data:'id',
mRender: function (data,type,row) {
var str='';
str+='<a href="'+window.rootContext+'/update/'+data+'/day/month/year">Update</a>'
return str;
}
}
]
});
AdminController.java
@RequestMapping(value = "/update/{id}/{day}/{month}/{year}")
public ModelAndView forwardUpdatePage(@PathVariable("id") int id, @PathVariable("day") String day, @PathVariable("month") String month, @PathVariable("year") String year) {
ModelAndView modelAndView = new ModelAndView("admin/index");
modelAndView.addObject("id",id);
modelAndView.addObject("day", day);
modelAndView.addObject("month", month);
modelAndView.addObject("year", year);
modelAndView.addObject("title", "Update Event");
modelAndView.addObject("userClickUpdateIcon", true);
return modelAndView;
}
如何使用ajax从jsp文件到Controller
类获取id,day,month,eventName和eventDescription的值。
我试图在控制器类中获取datatable的所有列值。我不知道如何在spring控制器类中使用@RequestParam
方法获取所有值。
答案 0 :(得分:0)
您可以执行以下操作
Java脚本代码:
var first_name=$("#first_name").val().trim();
var last_name=$("#last_name").val().trim();
var phone_no=$("#phone_no").val().trim();
$.ajax({
type:'POST',
url:'../signUp',
data:{firstName:first_name,lastName:last_name,phoneNo:phone_no},
cache:false,
success:function(response){
if(response=="SUCCESS"){
alert("Send Successfully.");
}else{
alert("Contact Admin");
}
},
error:function(){
console.log("Error in ajax of signUp");
}
});
Spring Controller:
@RequestMapping(method={RequestMethod.POST}, value={"/signUp"})
@ResponseBody public String signUp(SignUpPojo signupObj){
String userInfo="User Details : "+ signupObj.toString();
return "SUCCESS";
}
确保POJO具有您需要的正确字段。