java - 错误 404:ajax 无法连接到 @requestmapping
问题描述
我的 ajax 无法连接到这里,当我看到 F12->Network->Headers 我看到 requestUrl 有双“/web”:http://localhost:8080/create_user_web_war_exploded/web/web/done 但我的删除页面只有 1“ /web" 在链接 @RequestMapping(value = "/web/delete",method = RequestMethod.GET)。我认为在我的网站上出现错误 404,因为所有其他页面的链接都是“/'project_name'/'Request value'”
//My controller
@RestController
@RequestMapping(value = "/web/done")
public class UserController {
@Autowired
private IUserService userService;
@DeleteMapping
public String delete( @RequestBody UserDTO model,@PathVariable("id") long id){
ModelAndView mav = new ModelAndView("web/done");
userService.deleteUser(model.getId());
return "done";
}
}
//My ajax
function deleteUser(data) {
console.log("hihi");
console.log("done");
$.ajax({
type: 'DELETE',
url: 'web/done',
data: data,
/*dataType:'json',*/
/*contentType:'application/json',*/
success: function () {
console.log("done");
},
}).done(function (response) {
alert("Job done!!!!");
}).fail(function (xhr, status, error) {
alert(xhr.responseText);
});
解决方案
控制器的主要映射是“/web/done”,但在主要方法上,您只调用“web/done”而没有第一个 /。尝试在 Ajax 上添加 /
推荐阅读
- r - 从 ggplots 列表中自动组装拼凑图
- javascript - 用于检查文本中的 SSML 标签的 Javascript 包
- javascript - D3 设置后添加节点位置
- reactjs - 页面刷新时antd表单字段中不显示数据?
- pandas - 将高数据框转换为宽数据框熊猫
- javascript - 三反斜杠“\\\”是什么意思?
- ansible - 带有_items列表的Ansible过滤器
- ruby-on-rails - 使用 collection_select 通过 has_many 和 belongs_to 关联在预订中保存两个类的 ID 保存时会抛出错误“必须存在”
- wso2 - 使用本地 API 端点处理消息处理器问题
- c# - Windows 窗体组合框:在项目选择后显示自定义对象