相关疑难解决方法(0)

Spring MVC中不存在必需的String参数错误

我尝试在Spring MVC中向我的控制器发出一个AJAX查询.

我的行动代码是:

@RequestMapping(value = "events/add", method = RequestMethod.POST)
public void addEvent(@RequestParam(value = "start_date") String start_date, @RequestParam(value = "end_date") String end_date, @RequestParam(value = "text") String text, @RequestParam(value = "userId") String userId){
    //some code    
}
Run Code Online (Sandbox Code Playgroud)

我的Ajax查询是:

$.ajax({
        type: "POST",
        url:url,
        contentType: "application/json",
        data:     {
                start_date:   scheduler.getEvent(id).start_date,
                end_date:  scheduler.getEvent(id).end_date,
                text: scheduler.getEvent(id).text,
                userId: userId
        },
        success:function(result){
         //here some code
        }
    });
Run Code Online (Sandbox Code Playgroud)

但是我收到了一个错误:

必需的字符串参数''start_date不存在

为什么?据我所知,我提出了它(@RequestParam(value = "start_date") String start_date

UDP
现在我给404我的类来获取数据

public class EventData {
    public String end_date;
    public String start_date;
    public String …
Run Code Online (Sandbox Code Playgroud)

java ajax spring spring-mvc

21
推荐指数
1
解决办法
8万
查看次数

标签 统计

ajax ×1

java ×1

spring ×1

spring-mvc ×1