Rest:系统希望以非常简洁的URL地址来发请求;

怎样表示对一个资源的增删改查用请求方式来区分

/getBook?id=1   :查询图书

/deleteBook?id=1:删除1号图书

/updateBook?id=1:更新1号图书

/addBook     :添加图书


Rest推荐;

 url地址这么起名;  /资源名/资源标识符

/book/1          :GET-----查询1号图书

/book/1          :PUT------更新1号图书

/book/1          :DELETE-----删除1号图书

/book               :POST-----添加图书

系统的URL地址就这么来设计即可;

     简洁的URL提交请求,以请求方式区分对资源操作;


问题:从页面上只能发起两种请求,GET、POST;

其他的请求方式没法使用;


发起图书的增删改查请求;使用Rest风格的URL地址;





注意:高版本Tomcat;Rest支持有点问题

解决方法



index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><a href="book/1">查询图书</a><br/><br/><form action="book" method="post"><input type="submit" value="添加1号图书"/>
</form><br/><!-- 发送DELETE请求 -->
<form action="book/1" method="post"><input name="_method" value="delete"/><input type="submit" value="删除1号图书"/>
</form><br/><!-- 发送PUT请求 -->
<form action="book/1" method="post"><input name="_method" value="put"/><input type="submit" value="更新1号图书"/>
</form><br/></body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--suppress ALL -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>3.SpringMVC_rest</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><!-- The front controller of this Spring Web application, responsible for handling all application requests --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><!-- Map all requests to the DispatcherServlet for handling --><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><filter><filter-name>HiddenHttpMethodFilter</filter-name><filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class></filter><filter-mapping><filter-name>HiddenHttpMethodFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>

springmvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><context:component-scan base-package="com.atguigu"></context:component-scan><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"></property><property name="suffix" value=".jsp"></property></bean></beans>

BookController.java

package com.atguigu.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.RequestMethod;@Controller
public class BookController {/*** 处理查询图书请求* @param id* @return*/@RequestMapping(value="/book/{bid}",method=RequestMethod.GET)public String getBook(@PathVariable("bid")Integer id) {System.out.println("查询到了"+id+"号图书");return "success";}/*** 图书删除* @param id* @return*/@RequestMapping(value="/book/{bid}",method=RequestMethod.DELETE)public String deleteBook(@PathVariable("bid")Integer id) {System.out.println("删除了"+id+"号图书");return "success";}/*** 图书更新* @return*/@RequestMapping(value="/book/{bid}",method=RequestMethod.PUT)public String updateBook(@PathVariable("bid")Integer id) {System.out.println("更新了"+id+"号图书");return "success";}@RequestMapping(value="/book",method=RequestMethod.POST)public String addBook() {System.out.println("添加了新的图书");return "success";}
}

success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><h1>你成功了,6666</h1>
</body>
</html>

Rest风格的URL地址约束||高版本Tomcat;Rest支持有点问题相关推荐

  1. Maven编译项目时报错:不再支持源选项 5。请使用 6 或更高版本。 不再支持目标选项 1.5。请使用 1.6 或更高版本。

    在使用Maven编译项目时报错: 不再支持源选项 5.请使用 6 或更高版本. 不再支持目标选项 1.5.请使用 1.6 或更高版本. 在项目pom.xml文件中增加maven编译的jdk版本设置,m ...

  2. CentOS通过yum安装高版本gcc

    目录 一.问题 二.解决方案 三.devtoolset对应gcc的版本 四.安装 五.激活gcc版本 一.问题 在某些应用场景中,需要高版本的gcc支持,编译gcc耗时耗力,这里介绍一种简便的方法. ...

  3. 在Chrome、Firefox等高版本浏览器中实现低延迟播放海康、大华RTSP

    一.背景 现在到处是摄像头的时代,随着带宽的不断提速和智能手机的普及催生出火热的网络直播行业,新冠病毒的大流行又使网络视频会议系统成为商务会议的必然选择,因此RTSP实时视频流播放及处理不再局限于安防 ...

  4. intellisense_SQL Server IntelliSense的使用和故障排除–适用于SQL Server 2012或更高版本

    intellisense 什么是IntelliSense? (What is IntelliSense?) SQL Server Management Studio的IntelliSense是SQL ...

  5. Tomcat、Servlet、JSP、EL和JDK版本对照以及各版本Tomcat下载

    1.Tomcat.Servlet.JSP.EL和JDK版本对照 Servlet最佳版本 JSP最佳版本 EL最佳版本 WebSocket最佳版本 JASPIC最佳版本 Tomcat版本 最新小版本 支 ...

  6. tomcat高版本之URL解析异常解决

    IllegalArgumentException 一.项目场景: 例如:由于Apache的tomcat的版本升级,遵循RFC 7230 and RFC 3986规范解析请求地址.同时添加了对于http ...

  7. 显示服务器图片url,服务器上图片的url地址

    服务器上图片的url地址 内容精选 换一换 分析并识别用户上传的图像内容是否有敏感内容(如涉及政治人物.暴恐元素.涉黄内容等),并将识别结果返回给用户.在使用图像内容审核之前需要您完成服务申请和认证鉴 ...

  8. 图片url显示服务器,服务器上图片的url地址

    服务器上图片的url地址 内容精选 换一换 将图片导入图片索引库,该图片可以是同一区域OBS桶内的图片或请求消息体里的图片,只有导入图片索引库的图片方可被搜索到.添加或搜索的图片存储在OBS的桶中时, ...

  9. 高版本Chrome兼容window.showModalDialog办法

    高版本Chrome兼容window.showModalDialog办法 方式一:回调 兼容方式: 由于showmodaldialog 不属于W3C标准,在新版本浏览器中不再受支持,我们需要使用wind ...

最新文章

  1. oracle 取系统当前年份_oracle查询以当前年份为准的近些年数据
  2. 三数之和(三数不重复)
  3. gorm存指针数据_gormt: gormt 是一个数据库映射工具,可以将 mysql 数据库自动生成 golang sturct 结构...
  4. html+form+multipartform-data,表单 – 如何处理node.js中的multipart / form-data
  5. IT公司笔试题总结(三)
  6. linux 追加多行文件,linux多行文件信息追加
  7. jquery 清空表单
  8. android 自定义text,android – 使用自定义textSize实现自定义TextView
  9. EfficientNet细节
  10. 22款Android App传藏后门用广告耗手机电量
  11. 自定义获取焦点的TextView
  12. win7 下安装python用的dlib库
  13. 小狗扫地机器人与石头_养宠物不卫生?石头扫地机器人和戴森,你都用对了吗?...
  14. 产品经理面试问题及答案大全《一》
  15. 如何在Excel 2007中创建数据透视表
  16. 使用procexp.exe查看线程
  17. Java进阶之FileUpload完成上传
  18. 2021年了,对话系统凉透了吗?
  19. 【ansible】如何将ansible jinja2的双花括号转义?
  20. 移动端自动化测试appium(6)--搭建模拟器和真机环境

热门文章

  1. 混合开发的坑(7) ---输入文本时,键盘遮挡
  2. 根据名字,获取线程,进程。
  3. @Override的错误
  4. Android接口和框架学习
  5. WinCE系统声音定制
  6. 基于WINCE6.0下载multiple XIP镜像文件
  7. Eboot 中给nandflash分区实现
  8. 【OF框架】使用OF.WinService项目,添加定时服务,进行创建启动停止删除服务操作...
  9. 图像理解之物体检测object detection,模型rcnn/fastrcnn/fasterrcnn原理及概念
  10. 类的属性、类的方法、类的内置方法