html的rest风格访问,sprimgmvc实现rest风格,返回总是405,但是接口又访问到了咋整?...

问题描述

看了 rest风格的增删改查 视屏后,我照着视屏中的内容实现rest风格的接口,但是雷丰阳在视屏里,表单中调用完接口后是能正确转发到其他界面的,但是我就一直是405,我的接口中的语句输出了,也就是接口访问到了,但是网页跳转不了,get/post/put/delete 四种请求方式只有get能正确跳转网页(四种返回的都是一样的地址),请问怎么解决呢??

相关代码web.xml<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

index.html

springDispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/springmvc-config.xml

1

springDispatcherServlet

/

default

/index.html

HiddenHttpMethodFilter

org.springframework.web.filter.HiddenHttpMethodFilter

HiddenHttpMethodFilter

/*

springmvc-config.xml<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

RestController.javapackage controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

/**

* @author Surrin1999

*/

@Controller

@RequestMapping("/part1")

public class RestController {

@RequestMapping(value = "/book/{id}", method = RequestMethod.POST)

public String addBook(@PathVariable String id) {

System.out.println("正在增加图书..." + "id:" + id);

return "/success.html";

}

@RequestMapping(value = "/book/{id}", method = RequestMethod.DELETE)

public String deleteBook(@PathVariable String id) {

System.out.println("正在删除图书..." + "id:" + id);

return "/success.html";

}

@RequestMapping(value = "/book/{id}/{name}", method = RequestMethod.PUT)

public String updateBook(@PathVariable String id, @PathVariable String name) {

System.out.println("正在更新图书..." + "id:" + id + ",name:" + name);

return "/success.html";

}

@RequestMapping(value = "/book/{id}", method = RequestMethod.GET)

public String selectBook(@PathVariable String id) {

System.out.println("正在查找图书..." + "id:" + id);

return "/success.html";

}

}form.html

Title

包结构图

bVcR9Vq

测试图片

bVcR9UR

bVcR9UU

bVcR9UV上图中的警告信息如下20-May-2021 22:31:31.632 警告 [http-nio-8080-exec-5] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'DELETE' not supported]

2021-5-21 更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值