springmvc之RequestMapping中的请求方式

2020-08-26 10:38:34 浏览数 (1)

可以使用method指定请求的方式:

代码语言:javascript复制
package com.gong.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("/springmvc")
@Controller
public class SpringmvcTest {
    private static final String SUCCESS = "success";
    
    @RequestMapping(value="testMethod",method=RequestMethod.POST)
    public String testMethod() {
        System.out.println("RequestmMapping");
        return SUCCESS;
    }
}

在jsp界面中:

代码语言:javascript复制
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="springmvc/testMethod" method="POST">
        <input type="submit" value="submit"/>
    </form>
</body>
</html>
jsp

0 人点赞