我的行动如下
@RequestMapping(value = "info_pure", method = RequestMethod.GET)
public ModelAndView GetInfo(String ser_name, String[] p_input_week_days, int p_input_month_day) {
ModelAndView mav = new ModelAndView(JspView.PureInfoAup);
String aaa = request.getParameter("p_input_week_days");
我通过jquery ajax向此操作发送get请求。
var myarray = ['Element 1', 'Element 2', 'Element 3'];
var dataobject = {
ser_name: p_ser_name.trim(), p_input_week_days: myarray, p_input_month_day: p_month_day
};
$.ajax({
url: '../info_pure',
data: dataobject,
type: 'GET',
success: function(data) { /// go forward
但是当请求发送时给我一个错误。它说我的数组参数为空
这是我在firebug上的结果
答案 0 :(得分:1)
使用Spring MVC @RequestParam注释。
@RequestMapping(value = "info_pure", method = RequestMethod.GET)
public ModelAndView GetInfo(@RequestParam("p_input_week_days[]") String[] days) {
String[] aaa = days;
答案 1 :(得分:0)
我使用Google Gson库解决了这个问题。
像这样更新您的控制器方法
@RequestMapping(value = "info_pure", method = RequestMethod.GET)
public ModelAndView GetInfo(String ser_name, String p_input_week_days, int p_input_month_day) {
Gson gson=new Gson();
String[] weeks=gson.fromJson(p_input_week_days, String[].class);
// ....
像这样更新你的Ajax调用
var myarray = ['Element 1', 'Element 2', 'Element 3'];
var dataobject = {
ser_name: p_ser_name.trim(), p_input_week_days: JSON.stringify(myarray), p_input_month_day: p_month_day
};
$.ajax({
url: '../info_pure',
data: dataobject,
type: 'GET',
success: function(data) { /// go forward