簡體   English   中英

找不到HTTP / 1.1 404-JSON Spring MVC

[英]HTTP/1.1 404 Not Found - JSON Spring MVC

我寫了1個webapp,我嘗試將1個JSON發送到服務器並將其保存到MySQL中。 我有這個問題:

POST http://localhost:8080/jsonspringhibernateexample/addclass [HTTP/1.1 404 Not Found 910ms]

這是我的控制器(用於向Mysql添加一個類):

@Controller
public class ClassController {

    @Autowired
    private ClassService classService;
    @RequestMapping(value ="/index",method = RequestMethod.GET)
    public String getIndex(ModelMap map){
        map.put("listClass",classService.getListClass());
        map.put("studentClass", new Class());
        return "class";
    }
    @RequestMapping(value ="/addclass", method = RequestMethod.POST)
    public String addClass(@RequestBody Class studentClass){
        classService.addClass(studentClass);
        return "index";
    }
}

這是我的jQuery來調用控制器:

$("#addclass").click(function(e){
    $.ajax({
        url:"addclass",
        type: "post",
        contentType: 'application/json',
        data: JSON.stringify({className:$("#input").val(),listStudent:null}),
    }).done(function(){
        $("#listclass").appent("<option>"+$("#input").val()+"</option>");
    });
});

當我單擊“ #addclass”按鈕時,該類已添加,但控制器未返回index.jsp,這給我帶來了麻煩。 為什么會出現該錯誤? 而我該如何解決呢? 謝謝!

@RequestMapping(value="/jsonspringhibernateexample")類之前是否有@RequestMapping(value="/jsonspringhibernateexample") 否則嘗試刪除headers = {"Content-type=application/json"} ,也許content-type是錯誤的(但我不確定)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM