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

    
}
相关推荐
CoderIsArt9 小时前
C#中UI 线程与 Dispatcher
开发语言·ui·c#
微尘寒风9 小时前
【Git】的安装和使用
java·git
y = xⁿ10 小时前
DeepSeek Harness 学习日记:关于Agent接口,工具调用的底层实现
android·java·学习
侧耳倾听11111 小时前
jwt使用简介
java·jwt
顶点多余11 小时前
那些在算法中适合巩固的知识点---1
java·前端·算法
AI人工智能+电脑小能手11 小时前
大白话说Java设计模式-46-责任链模式(业务实战篇)
java·设计模式·责任链模式·风控校验·servlet filter·spring interceptor·链式处理
jay神11 小时前
【计算机毕业设计】基于SpringBoot的程序教学辅助系统
java·前端·vue.js·spring boot·后端·毕业设计·课程设计
AI情绪识别开源12 小时前
检信 ALLEMOTION OS 加密打包可执行程序 — 全面测试报告版本: v1.3功能测试 / 性能测试 /
开发语言·数据结构·人工智能·功能测试
2601_9620664912 小时前
【Sql Server】Update中的From语句,以及常见更新操作方式
android·java·数据库