码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【java、springMVC】REST风格


    描述访问网络资源的格式

    传统风格:http://localhost/user/saveUser

    rest风格:http://localhost/user

    优点

    1.隐藏资源访问行为(用行为动作区分操作)

    2.书写简化

    注解解释

    @RequestMapping

    7221e8eaedad4814bb5cb714489081c9.jpg

    @PathVariable 

    7d28e647304543e5813abd6f596e41f6.jpg

    @RestController 

    2bc589c176e54c3f94b4f48c6aba528f.jpg

    简化开发注解 

    94a559cb000e48d8b72838a49983973b.jpg

    入门案例(最基础,有不合理)

    1. @RequestMapping(value = "/users", method = RequestMethod.POST)
    2. @ResponseBody
    3. public String save(@RequestBody User user) {
    4. System.out.println("user save " + user);
    5. return "{'module':'user save'}";
    6. }
    7. @RequestMapping(value = "/users/{id}", method = RequestMethod.DELETE)
    8. @ResponseBody
    9. public String delete(@PathVariable Integer id) {
    10. System.out.println("user delete " + id);
    11. return "{'module':'user delete'}";
    12. }
    13. @RequestMapping(value = "/users", method = RequestMethod.PUT)
    14. @ResponseBody
    15. public String update(@RequestBody User user) {
    16. System.out.println("user update " + user);
    17. return "{'module':'user update'}";
    18. }
    19. @RequestMapping(value = "/users/{id}",method = RequestMethod.GET)
    20. @ResponseBody
    21. public String getById(@PathVariable Integer id) {
    22. System.out.println("user getById " + id);
    23. return "{'module':'user getById'}";
    24. }
    25. @RequestMapping(value = "/users",method = RequestMethod.GET)
    26. @ResponseBody
    27. public String getAll() {
    28. System.out.println("user getAll ");
    29. return "{'module':'user getAll'}";
    30. }

    快速开发

    1. package org.example.controller;/*
    2. * @Auther:huangzhiyang
    3. * @Date:2023/10/7
    4. * @Description:
    5. */
    6. import org.example.domain.Book;
    7. import org.springframework.web.bind.annotation.*;
    8. @RestController
    9. @RequestMapping("/book")
    10. public class BookController {
    11. @PostMapping
    12. public String save(@RequestBody Book book) {
    13. System.out.println("book save "+book);
    14. return "{'info':'springmvc'}";
    15. }
    16. @DeleteMapping("/{id}")
    17. public String delete( @PathVariable String id) {
    18. System.out.println("book delete"+id);
    19. return "{'info':'springmvc'}";
    20. }
    21. @PutMapping
    22. public String update(@RequestBody Book book) {
    23. System.out.println("book update");
    24. return "{'info':'springmvc'}";
    25. }
    26. }

  • 相关阅读:
    TinTin Web3 动态精选:以太坊基金会推出 EELS、Arbitrum Stylus 上线
    冥想第五百四十四天
    Rule-Engine-Starter V1.0.0
    MATLAB/Simulink 与Gazebo联合仿真
    驱动开发day8
    LeetCode155:最小栈,最简单的中等难度题,时间击败100%,内存也低于官方
    docker(3) dockerCompose
    MATLAB中deg2rad和rad2deg函数的使用
    阿里面试(持续更新)
    【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
  • 原文地址:https://blog.csdn.net/David_Hzy/article/details/133688679
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号