首页 > 其他分享 >Spring MVC指南

Spring MVC指南

时间:2023-04-05 10:23:18浏览次数:29  
标签:指南 HTTP RequestMapping Spring argument value MVC path method

@RestController

It is a convenience syntax for @Controller and @ResponseBody together,This indicates that the class is a controller,and that all the methods in the marked class will return a JSON response.

@ResponseBody

The @ResponseBody is a utility annotation that tells Spring to automatically seriarlize return value(s) of this classes methods into HTTP responses.When building a JSON endpoint,this is an amazing way to "magically" convert your objects into JSON for easier consumption. if we use the @RestController annotation on our class,we don't need this annotation at all,because @RestController inherits from it.

@RequestMapping(method = RequestMethod.GET,value = "/path")

The @RequestMapping(method = RequestMethod.GET,value = "path") annotation specifies a method in the controller that should be reponsible for serving the HTTP request to the given path,or endpoint,Spring handles the mechaincal details of how this is achieved for you. You simply specify the method and path parameters on the annotation and Spring will route the requests into the correct action methods.If you don't specify a method value,it will default to GET.

@GetMapping(value = "/path")

An abbreviated form of @RequestMapping specifically for HTTP GET requests,which only takes an optional value argument,no method argument.The read in CRUD.

@PostMapping(value = "/path")

An abbreviated form of @RequestMapping specifically for HTTP POST requests,which only takes an optional value argument,no method argument.The create in CRUD.

@PutMapping(value = "/path")

An abbreviated form of @RequestMapping specifically for HTTP PUT requests,which only takes an optional value argument,no method argument.The update in CRUD.

@DeleteMapping(value = "/path")

An abbreviated form of @RequestMapping specifically for HTTP DELETE requests,which only takes an optional value argument,no method argument.The delete in CRUD.

@RequestParam(value = "/path")

Naturally,the methods handling the requests might take parameters.To help you with binding the HTTP parameters into the action method arguments,you can use the @RequestParam(value="name",defaultValue="World") annotation.Spring will parse the request parameters and put the appropriate ones into your method arguments.

标签:指南,HTTP,RequestMapping,Spring,argument,value,MVC,path,method
From: https://www.cnblogs.com/ashet/p/17288893.html

相关文章

  • 性能环境之Jenkins+Maven自动化部署SpringBoot压测环境(Docker篇)
    前言在上文性能环境之Jenkins+Maven自动化部署SpringBoot压测环境(实战篇)中我们介绍了常规部署流程,本文将在上文的基础上扩展Jenkins+Maven+Docker自动化部署我们的压测环境。关于DockerDocker在这里有什么用?Docker,是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到......
  • spring IOC的理解
    springIOC的理解.  (1)没有IoC的程序中,面向对象的编程,对象的创建和对象之间的依赖关系硬编码到程序中,有程序本身控制;引入DI,对象的创建和对象之间的依赖关系交由第三方——Spring容器来控制。IoC的本质是获取依赖对象的方式翻转了。(2)IoC、DI、Spring容器区别:IoC:控制翻转,......
  • 前端项目代码阅读指南
    0.把项目运行起来,如果npm总是报错,并且项目年代久远,直接放弃,找一个能跑起来的看。1.看package.json,了解项目中用到了哪些依赖,这些依赖一般都是怎么使用的,项目结构大概什么样子2.看目录,猜一下每个目录下的文件都是干什么的3.看入口文件,一般是index.js,或者app.js,了解全局......
  • CodeMirror 基础配置指南
    CodeMirror基础配置指南需求背景在线编辑项目引入列表页面加载页面内容在线编辑页面在线编辑内容保存需求背景这里为什么会用到在线编辑功能呢?有这样的一个文件管理系统,实时上传js、css、html、shtml、txt等格式文件及文件夹,但是有时候发现上传的文件内容上有不对的地方,如果按传统......
  • SpringBoot 配置类解析
    作者:LiWanghongSpringBoot作为Java领域非常流行的开源框架,集成了大量常用的第三方库配置,SpringBoot应用中这些第三方库几乎可以是零配置的开箱即用,大部分的SpringBoot应用都只需要非常少量的配置代码,开发者能够更加专注于业务逻辑。SpringBoot上手快,但是如果你的项目中业务场......
  • 一个简单SpringMVC的实现
    之前学习时候,是使用老师的自定义的一个SpringMVC模式,今天突然好奇,官方的SpringMVC架构咋弄,于是带着好奇的心去实现完成它其实这个模式也比较简单1:首先,我们创建一个maven,web的网页项目,JDK选择1.8版本   2:在创建完之后,鼠标右键点击main目录,同时选择java和resource包按回车......
  • Spring——springboot启动源码分析
    摘要主要介绍的有关于Spring的Spring的事务注解原理和实战(SpringFramework)一、什么是事务的传播?简单的理解就是多个事务方法相互调用时,事务如何在这些方法间传播。:举个栗子,方法A是一个事务的方法,方法A执行过程中调用了方法B,那么方法B有无事务以及方法B对事务的要求不同都会对......
  • 软件测试报告需要包括哪些内容?测试人员收藏这份必备指南!!!
    软件测试报告是软件开发生命周期的重要组成部分,是测试人员编写的文档,用于记录测试的过程和结果,对发现的问题和缺陷进行分析,为纠正软件的存在的质量问题提供依据,同时为软件验收和交付打下基础。软件测试报告通常包括以下内容:1、项目背景:介绍测试报告的编写目的、测试系统名......
  • SpringCloud——SpringCloud Alibaba Sentinel原理与实战
    摘要在微服务架构中,我们将系统拆分成了很多服务单元,各单元的应用间通过服务注册与订阅的方式互相依赖。由于每个单元都在不同的进程中运行,依赖通过远程调用的方式执行,这样就有可能因为网络原因或是依赖服务自身问题出现调用故障或延迟而这些问题会直接导致调用方的对外服务也出现延......
  • SpringCloud——SpringCloud Sleuth原理与实战
    摘要SpringCloudEureka是SpringCloudNetflix微服务套件中的一部分,它基于NetflixEureka做了二次封装,主要负责完成微服务架构中的服务治理功能。SpringCloud通过为Eureka增加了SpringBoot风格的自动化配置,我们只需通过简单引入依赖和注解配置就能让SpringBoot构建的微服务......