javaee springMVC Rest风格和Ant风格

jsp

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



<!-- rest风格 -->
<a href="users/add5/1/zhangsan">添加5</a>

<!-- ant风格-->
<a href="users/aa/add6">添加6</a>

</body>
</html>

java

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";
    }

    
}
相关推荐
Java牛马3 小时前
SpringBoot Starter 依赖相关总结
java·spring·springboot·starter·自动装配·依赖
丰锋ff3 小时前
基于 Qt 的智能门禁系统(二)
开发语言·qt
吴声子夜歌3 小时前
Java面试——Spring Cloud原理及应用(二)
java·spring cloud·面试
fpcc3 小时前
跟我学C++中级篇——编译期的条件选择
开发语言·c++
SomeB1oody3 小时前
【RustyML入门】6.3. 并行归约
开发语言·后端·机器学习·rust·教程
东小西4 小时前
【SAA实战】第 1 篇:ReactAgent 入门——先撸个"会调工具的助手"跑起来
java·人工智能·spring
mqiqe4 小时前
AgentScope Java 2.0 协议集成全景解析:A2A、AG-UI、Agent Protocol 三大开放协议实战指南
java·开发语言·ui
lzhdim5 小时前
12、JavaScript常见的内存泄露问题 - JavaScript学习系列文章
开发语言·前端·javascript·学习·ecmascript
脉动数据行情5 小时前
Java 实现台股 TWSE/TPEx 行情采集(个股 + K 线)
java·开发语言·twse·tpex·台股
爱学习的小邓同学5 小时前
Golang --- (1)第一个Golang程序
开发语言·后端·golang