SpringMVC Restful风格

在controller的类上添加@RestController注解

java 复制代码
package com.xiaoya.controller;

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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
public class TestController {
    @RequestMapping("/hello/{name}")
    @ResponseBody
    public String hello(@PathVariable String name){
        return "hello "+name;
    }
}

在方法的参数前面标上@PathVariable注解,然后路径中使用{name}就可以解析变量

启动tomcat,访问http://localhost:8080/springmvc1_war_exploded/hello/2

相关推荐
码事漫谈15 分钟前
当单库日增 4.5TB,异构实时同步还能稳得住吗?
后端
IT_陈寒2 小时前
SpringBoot自动配置的坑,这次真踩疼我了
前端·人工智能·后端
shengjk12 小时前
AI Engineering 五代演进史:Prompt、RAG、Agent 到 Graph 的架构革命
后端
子兮曰3 小时前
AI 浏览器 Agent 的安全困局:当自动化工具可以偷走你的登录态
前端·人工智能·后端
妙码生花3 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(四十八):菜单规则管理实现
前端·后端·ai编程
XuCoder3 小时前
Redis 持久化:RDB 与 AOF
后端
Conan在掘金3 小时前
鸿蒙 7.0 智能体框架 2.0:意图即服务根因——从 InsightIntentExecutor 到 HMAF 2.0 Skill 演进
后端
掘金者阿豪3 小时前
折腾电科金仓 Docker 部署的一晚上:角色登录失败、远程连接失败,这几个坑终于踩完了
后端
lichenyang4533 小时前
从图片创作到本地可复现的 AIGC 全栈闭环:AIGC Creative Studio 实践复盘
前端·后端
倒流时光三十年3 小时前
第三阶段 26 · highlight 高亮(返回命中片段)
后端·python·django