javaee springMVC Rest风格和Ant风格

jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!h2>




<a href="users/add5/1/zhangsan">添加5a>


<a href="users/aa/add6">添加6a>

body>
html>

java

package com.test.controller;

import com.test.pojo.Users;
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;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/users")
public class UsersController {

    

    //方式4
    @RequestMapping("/add5/{id}/{name}")
    public String add5(@PathVariable(value="id") int id,@PathVariable(value="name") String name)
    {
        System.out.println(id);

        System.out.println(name);

        return "success";
    }

    //方法5
    /*
       **:匹配任意路径
       * :匹配任意字符 0个或任意个
       ?:匹配一个任意字符
     */
    @RequestMapping("/**/?dd6")
    public String add6()
    {
        return "success";
    }

    
}

你可能感兴趣的:(Mac开发,java-ee,java,开发语言)