天天看點

spring-boot使用ajax,後端反應報錯,一直接收不到ajax發來的資料

前端ajax的url寫的dis,後端controller類@RequestMapping的value上沒有寫,但是在方法上寫了@RequestMapping("/dis"),一直報錯,無意間将類上面寫成@RequestMapping("/dis"),搜尋欄出現ajax發送的資料。

最後将前端的url改成cam/dis

後端改為

@RequestMapping("/cam")
@Controller
@ResponseBody
public class DisplayController  {
    /*
        通路位址localhost:8080/Dis
        params為檔案夾路徑
        cut為圖檔所在檔案夾
    * */
    @RequestMapping("/dis")
    public ArrayList<String> SendPicturePath(Path path) {
        ArrayList<String> fileList = new ArrayList<String>();
        //将圖檔所在檔案夾資訊送過去,切割成相對路徑
        GetPicturePath getPicture =new GetPicturePath(path.getCut());
        //建立檔案夾的位置  path.getParams().split(path.getCut())[0]
        fileList = getPicture.getFiles(path.getParams());
        return fileList;
    }
}
           

就達到前後端互通資料了

繼續閱讀