基本要点
1、定义
根据百度百科的定义,RESTFUL是一种网络应用程序的设计风格和开发方式
2、传统方式与Restful风格的区别
在我们学习restful风格之前,我们请求接口,都是使用http://localhost:8080/controller?method=add这种方式携带接口所需要的参数
而调用restful风格的接口时,我们可以改成http://localhost:8080/controller/add这种类型
3、如何使用Restful风格
我们通过一个代码demo来了解一下它的使用方法
首先,我们设置当前module为web项目,在web.xml中配置一下DispatcherServlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatc

本文介绍了RESTful风格的网络应用程序设计,对比了它与传统HTTP请求方式的区别,并通过一个SpringMVC的代码示例展示了如何配置和使用RESTful接口。通过不同的请求方法(GET、POST等)实现接口复用,强调了RESTful接口的简洁性和代码复用性。此外,还讨论了解决POST请求中文乱码问题的方法,并提及了使用CharacterEncodingFilter过滤器的重要性。
最低0.47元/天 解锁文章
186

被折叠的 条评论
为什么被折叠?



