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

    
}
相关推荐
Chengbei118 分钟前
JsOwl|AI 赋能 JS 敏感信息扫描器,AST + 正则、source‑map 源码还原、登录态爬虫输出交互式 HTML 报告
开发语言·javascript·网络·人工智能·爬虫·网络安全·自动化
David猪大卫10 分钟前
【C++修炼】string类:string类的模拟实现
c语言·开发语言·数据结构·c++·经验分享·笔记·学习
geovindu12 分钟前
rust: Iterator Pattern
开发语言·后端·设计模式·rust·行为模式·迭代器模
SDWAN_Cheap37 分钟前
深度解析什么是CDN加速:从原理到实践的技术拆解
开发语言·cdn加速
鬼手点金38 分钟前
模型即 Agent:当模型本身成为产品
开发语言·前端·人工智能·python·机器学习
SunnyDays10111 小时前
如何使用 Java 提取 PPT 中的文字:整份文档、指定幻灯片与表格内容
java·powerpoint
毕设单片机1 小时前
springboot志愿服务平台的设计与实现 36731
java·spring boot·mysql·志愿服务平台
染指11101 小时前
147.Agent-LangGraph归并函数
开发语言·人工智能·python·langchain·agents
IT_Octopus1 小时前
【零基础入门 LLM 开发 · Day 15】:LangChain 注册工具——告别手写 JSON Schema
java·langchain·json