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

    
}
相关推荐
a努力。5 分钟前
LangChain Agent消息链路全解析
java·前端·javascript
SL_staff12 分钟前
物模型是设备的数字身份证:属性、事件、服务如何决定IoT系统扩展性
java·物联网·全栈
程序员yu14 分钟前
会编网络:别被入门教程骗了,Python实用能力不在语法本身
开发语言·python·学习·算法
资深技术分享员20 分钟前
Geejing WebBuilder 日志、在线用户、系统监控,出问题时的三个第一现场
java·运维·数据库
卓怡学长23 分钟前
w202springboot基于B_S架构的图书信息管理系统
java·spring boot·spring·intellij-idea
Bruce_Liuxiaowei28 分钟前
Python 字典默认值完全指南:从 KeyError 到 defaultdict
开发语言·数据结构·python·字典
走到天涯海角31 分钟前
用springBoot写几个简单的接口
java·spring boot·intellij-idea
troy12839 分钟前
Java 技术栈全景指南:从基础到微服务的完整知识体系
java·开发语言·微服务
Escalating_xu43 分钟前
【C 语言】深入理解指针(2):数组名、数组传参、二级指针与指针数组
java·c语言·开发语言
郝学胜-神的一滴1 小时前
游戏引擎原理与实践 01:聊聊游戏引擎的前世今生
开发语言·c++·游戏引擎·产品运营·软件工程·产品经理·untiy