Spring MVC 中使用 RESTFul 编程风格
1. Spring MVC 中使用 RESTFul 编程风格
@
2. RESTFul 编程风格
2.1 RESTFul 是什么
RESTFul 是 web 服务器接口 的一种设计风格。
RESTFul 定义了一组约束条件和规范,可以让 web服务器接口 更加简洁,易于理解,易于扩展,安全可靠。
RESTFUl 对一个 web 服务器接口 都规定了哪些东西 ?
- 对请求的 URL 格式有约束和规范
- 对 HTTP 的请求方式有约束和规范
- 对请求和响应的数据格式有约束和规范
- 对 HTTP 状态码有约束和规范
- 等......
REST 对请求方式的约束是这样的:
- 查询必须发送 GET 请求
- 新增必须发送 POST 请求
- 修改必须发送 PUT 请求
- 删除必须发送 DELETE 请求
REST对 URL 的约束时这样的:
- 传统的 URL : get 请求,/springmvc/getUserById?id=1
- REST风格的 URL:get 请求,/springmvc/user/1
- 传统的URL :get 请求,/springmvc/deleteUserById?id=1
- REST风格的URL:delete 请求,/springmvc/user/1
RESTFul 对 URL 的约束和规范的核心时:通过采用 :不同的请求方式 + URL 来确定 web 服务中的资源。
RESTFul 的英文全称时:Representational State Transfer(表述性状态转移),简称 REST。
表述性(Representational) 是:URL + 请求方式。
状态(State) 是 :服务器端的数据。
转移(Transfer) 是:变化。
表述性转移是指:通过 URL + 请求方式来控制服务器端数据的变化。
2.2 RESTFul风格与传统方式对比
统的 URL 与 RESTful URL 的区别是传统的 URL 是基于方法名进行资源访问和操作,而 RESTful URL 是基于资源的结构和状态进行操作的。下面是一张表格,展示两者之间的具体区别:
| 传统的 URL | RESTful URL |
|---|---|
| GET /getUserById?id=1 | GET /user/1 |
| GET /getAllUser | GET /user |
| POST /addUser | POST /user |
| POST /modifyUser | PUT /user |
| GET /deleteUserById?id=1 | DELETE /user/1 |
从上表中我们可以看出,传统的 URL是基于动作的,而 RESTful URL 是基于资源和状态的,因此 RESTful URL 更加清晰和易于理解,这也是 REST 架构风格被广泛使用的主要原因之一。
3. Spring MVC 中使用 RESTFul 编程风格(增删改查)的使用
3.1 准备工作
导入相关依赖 jar 包。


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rainbowsea</groupId>
<artifactId>springmvc-007</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!--springmvc依赖-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.1.4</version>
</dependency>
<!--logback依赖-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.3</version>
</dependency>
<!--servlet依赖-->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!--thymeleaf和spring6整合的依赖-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring6</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
</dependencies>
</project>
相关包 / 目录的创建,配置。

springmvc.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 组件扫描-->
<context:component-scan base-package="com.rainbowsea.springmvc.controller"></context:component-scan>
<!-- 视图解析器-->
<bean id="thymeleafViewResolver" class="org.thymeleaf.spring6.view.ThymeleafViewResolver">
<!--作用于视图渲染的过程中,可以设置视图渲染后输出时采用的编码字符集-->
<property name="characterEncoding" value="UTF-8"/>
<!--如果配置多个视图解析器,它来决定优先使用哪个视图解析器,它的值越小优先级越高-->
<property name="order" value="1"/>
<!--当 ThymeleafViewResolver 渲染模板时,会使用该模板引擎来解析、编译和渲染模板-->
<property name="templateEngine">
<bean class="org.thymeleaf.spring6.SpringTemplateEngine">
<!--用于指定 Thymeleaf 模板引擎使用的模板解析器。模板解析器负责根据模板位置、模板资源名称、文件编码等信息,加载模板并对其进行解析-->
<property name="templateResolver">
<bean class="org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver">
<!--设置模板文件的位置(前缀)-->
<property name="prefix" value="/WEB-INF/templates/"/>
<!--设置模板文件后缀(后缀),Thymeleaf文件扩展名不一定是html,也可以是其他,例如txt,大部分都是html-->
<property name="suffix" value=".html"/>
<!--设置模板类型,例如:HTML,TEXT,JAVASCRIPT,CSS等-->
<property name="templateMode" value="HTML"/>
<!--用于模板文件在读取和解析过程中采用的编码字符集-->
<property name="characterEncoding" value="UTF-8"/>
</bean>
</property>
</bean>
</property>
</bean>
<!-- 开启注解驱动-->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 视图控制器, 这个配置可以只写 对应 index的视图,不写对应的Controller,简化配置 -->
<mvc:view-controller path="/" view-name="index"></mvc:view-controller>
</beans>
3.2 RESTFul 风格的 “查询” 所有(RESTFul 规范 需要发送 GET请求)
RESTFul 规范中规定,如果要查询数据,需要发送 GET 请求。

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1>测试 RESTFul 编程风格</h1>
<hr>
<!--RESTFul 编程风格,查看用列表-->
<a th:href="@{/user}">查看用户列表</a> <br>
</body>
</html>
控制器 Controller:

import com.rainbowsea.springmvc.bean.User;
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 // 交给 Spring IOC 容器进行管理
public class UserController {
@RequestMapping(value = "/user", method = RequestMethod.GET)
public String getAll() {
System.out.println("正在查询所有用户信息...");
return "ok";
}
}
ok 的页面视图:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>OK页面</title>
</head>
<body>
<h1>OK !</h1>
</body>
</html>
启动服务器,测试:http://localhost:8080/springmvc



3.3 RESTFul 风格的 根据 “id 查询”( RESTFul 规范 需要发送 GET请求)
RESTFul 规范中规定,如果要查询数据,需要发送GET请求。
首页index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1>测试 RESTFul 编程风格</h1>
<hr>
<!--RESTFul 编程风格,查看用列表-->
<a th:href="@{/user}">查看用户列表</a> <br>
<!--RESTFul 风格的,根据 id 查询用户信息-->
<a th:href="@{/user/1}">查询id=1的这个用户信息</a><br>
</body>
</html>
控制器 Controller:

import com.rainbowsea.springmvc.bean.User;
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 // 交给 Spring IOC 容器进行管理
public class UserController {
//@RequestMapping(value = "/user/{占位符}",method = RequestMethod.GET)
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
public String getById(@PathVariable(value = "id") String id) {
System.out.println("正在根据用户 id 查询用户信息...用户 id 是" + id);
return "ok";
}
}
启动服务器测试:



3.4 RESTFul 风格的 “增加数据” (RESTFul 规范 需要发送 POST 请求)
RESTFul规范中规定,如果要进行保存操作,需要发送POST请求。
这里我们添加一个 User Bean 类,用于作为对象进行存储。

package com.rainbowsea.springmvc.bean;
public class User {
private String username;
private String password;
private Integer age;
public User() {
}
public User(String username, String password, Integer age) {
this.username = username;
this.password = password;
this.age = age;
}
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
", age=" + age +
'}';
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
页面编写:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1>测试 RESTFul 编程风格</h1>
<hr>
<!--RESTFul 编程风格,查看用列表-->
<a th:href="@{/user}">查看用户列表</a> <br>
<!--RESTFul 风格的,根据 id 查询用户信息-->
<a th:href="@{/user/1}">查询id=1的这个用户信息</a><br>
<!--RESTFul 风格的,新增用户信息,新增必须发送POST请求,需要使用 form 表单-->
<form th:action="@{/user}" method="post">
用户名: <input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
年龄: <input type="text" name="age"><br>
<input type="submit" value="保存">
</form>
<hr>
</body>
</html>
控制器 Controller:

启动服务器测试:


3.5 RESTFul 风格的 “修改数据” (RESTFul 规范 需要发送 PUT 请求)
RESTFul规范中规定,如果要进行保存操作,需要发送PUT请求。
如何发送PUT请求?
第一步:首先你必须是一个POST请求。
第二步:在发送POST请求的时候,提交这样的数据:_method=PUT,使用隐藏域进行配置
第三步:在web.xml文件配置SpringMVC提供的过滤器:HiddenHttpMethodFilter
注意:
<!-- 隐藏域-->
<input type="hidden" name="_method" value="put">
隐藏域的 name 必须只能是 “_method”, value是 put(大小写忽略)
第一步:首先你必须是一个POST请求。
第二步:在发送POST请求的时候,提交这样的数据:_method=PUT

<h2>修改</h2>
<!-- RESTFul 风格的,修改用户信息,修改必须发送 put 请求,要发送 put 请求,首先必须是一个 Post 请求-->
<form th:action="@{/user}" method="post">
<!-- 隐藏域-->
<input type="hidden" name="_method" value="put">
用户名: <input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
年龄: <input type="text" name="age"><br>
<input type="submit" value="修改">
</form>

第三步:在web.xml文件配置SpringMVC提供的过滤器:HiddenHttpMethodFilter
注意:该过滤器一定要在字符编码过滤器后面配置,不然,先设置的话,可能会出现获取到的请求数据是乱码

<!-- 添加一个过滤器,这个过滤器是springmvc提前写好的,直接用就行了,这个过滤器可以帮助你将请求
POST转换成PUT请求/DELETE请求-->
<!-- 同时注意: -->
<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>
页面编写:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1>测试 RESTFul 编程风格</h1>
<hr>
<!--RESTFul 编程风格,查看用列表-->
<a th:href="@{/user}">查看用户列表</a> <br>
<!--RESTFul 风格的,根据 id 查询用户信息-->
<a th:href="@{/user/1}">查询id=1的这个用户信息</a><br>
<!--RESTFul 风格的,新增用户信息,新增必须发送POST请求,需要使用 form 表单-->
<form th:action="@{/user}" method="post">
用户名: <input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
年龄: <input type="text" name="age"><br>
<input type="submit" value="保存">
</form>
<hr>
<h2>修改</h2>
<!-- RESTFul 风格的,修改用户信息,修改必须发送 put 请求,要发送 put 请求,首先必须是一个 Post 请求-->
<form th:action="@{/user}" method="post">
<!-- 隐藏域-->
<input type="hidden" name="_method" value="put">
用户名: <input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
年龄: <input type="text" name="age"><br>
<input type="submit" value="修改">
</form>
</body>
</html>
控制器 Controller:

启动服务器测试:


3.6 RESTFul 风格的 “删除数据” 数据(RESTFul 规范 需要发送 DELETE 请求)
RESTFul规范中规定,如果要进行 删除 操作,需要发送DELETE 请求。
如何发送 DELETE 请求?,和 发送 PUT 请求的三步是一样的,只需要将 value 的值改为 delete 即可
第一步:首先你必须是一个POST请求。
第二步:在发送POST请求的时候,提交这样的数据:_method=PUT,使用隐藏域进行配置
第三步:在web.xml文件配置SpringMVC提供的过滤器:HiddenHttpMethodFilter
注意:
<!-- 隐藏域-->
<input type="hidden" name="_method" value="delete">
隐藏域的 name 必须只能是 “_method”, value是 delete (大小写忽略)
页面编写:

<hr>
<h2>删除用户</h2>
<!--RESTful风格的,删除用户西悉尼-->
<!--删除必须发送 DELETE 请求,和 PUT 请求实现方式相同-->
<!--发送 DELETE 请求的前提是POST请求,并且需要通过隐藏域提交,_method="delete"-->
<a th:href="@{user/120}" onclick="del(event)">删除用户id = 120 的用户信息</a>
<form id="delForm" method="post">
<input type="hidden" name="_method" value="delete">
</form>
<script>
function del(event) {
// 获取表单
let delForm = document.getElementById("delForm");
// 给 form 的 action 赋值
delForm.action = event.target.href;
// 发送POST 请求提交表单
delForm.submit();
// 非常重要,你需要阻止超链接的默认行为
event.preventDefault();
}
</script>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1>测试 RESTFul 编程风格</h1>
<hr>
<!--RESTFul 编程风格,查看用列表-->
<a th:href="@{/user}">查看用户列表</a> <br>
<!--RESTFul 风格的,根据 id 查询用户信息-->
<a th:href="@{/user/1}">查询id=1的这个用户信息</a><br>
<!--RESTFul 风格的,新增用户信息,新增必须发送POST请求,需要使用 form 表单-->
<form th:action="@{/user}" method="post">
用户名: <input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
年龄: <input type="text" name="age"><br>
<input type="submit" value="保存">
</form>
<hr>
<h2>修改</h2>
<!-- RESTFul 风格的,修改用户信息,修改必须发送 put 请求,要发送 put 请求,首先必须是一个 Post 请求-->
<form th:action="@{/user}" method="post">
<!-- 隐藏域-->
<input type="hidden" name="_method" value="put">
用户名: <input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
年龄: <input type="text" name="age"><br>
<input type="submit" value="修改">
</form>
<hr>
<h2>删除用户</h2>
<!--RESTful风格的,删除用户西悉尼-->
<!--删除必须发送 DELETE 请求,和 PUT 请求实现方式相同-->
<!--发送 DELETE 请求的前提是POST请求,并且需要通过隐藏域提交,_method="delete"-->
<a th:href="@{user/120}" onclick="del(event)">删除用户id = 120 的用户信息</a>
<form id="delForm" method="post">
<input type="hidden" name="_method" value="delete">
</form>
<script>
function del(event) {
// 获取表单
let delForm = document.getElementById("delForm");
// 给 form 的 action 赋值
delForm.action = event.target.href;
// 发送POST 请求提交表单
delForm.submit();
// 非常重要,你需要阻止超链接的默认行为
event.preventDefault();
}
</script>
</body>
</html>
控制器 Controller:

package com.rainbowsea.springmvc.controller;
import com.rainbowsea.springmvc.bean.User;
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 // 交给 Spring IOC 容器进行管理
public class UserController {
//@RequestMapping(value = "/user/{占位符}",method = RequestMethod.GET)
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
public String getById(@PathVariable(value = "id") String id) {
System.out.println("正在根据用户 id 查询用户信息...用户 id 是" + id);
return "ok";
}
@RequestMapping(value = "/user", method = RequestMethod.GET)
public String getAll() {
System.out.println("正在查询所有用户信息...");
return "ok";
}
@RequestMapping(value = "/user", method = RequestMethod.POST)
public String save(User user) {
System.out.println("正在保存用户信息");
System.out.println(user);
return "ok";
}
@RequestMapping(value = "/user", method = RequestMethod.PUT)
public String modify(User user) {
System.out.println("正在修改用户信息" + user);
return "ok";
}
@RequestMapping(value = "/user/{id}", method = RequestMethod.DELETE)
public String del(@PathVariable(value = "id") String id) {
System.out.println("正删除用户 : " + id);
return "ok";
}
}
启动服务器测试:


4. 补充: HiddenHttpMethodFilter 过滤器源码说明
HiddenHttpMethodFilter是Spring MVC框架提供的,专门用于RESTFul编程风格。
实现原理可以通过源码查看:



通过源码可以看到,if语句中,首先判断是否为POST请求,如果是POST请求,调用request.getParameter(this.methodParam)。可以看到this.methodParam是_method,这样就要求我们在提交请求方式的时候必须采用这个格式:_method=put。获取到请求方式之后,调用了toUpperCase转换成大写了。因此前端页面中小写的put或者大写的PUT都是可以的。if语句中嵌套的if语句说的是,只有请求方式是 PUT,DELETE,PATCH的时候会创建HttpMethodRequestWrapper对象。而HttpMethodRequestWrapper对象的构造方法是这样的:

这样method就从POST变成了:PUT/DELETE/PATCH。
重点注意事项:CharacterEncodingFilter和HiddenHttpMethodFilter的顺序
细心的同学应该注意到了,在HiddenHttpMethodFilter源码中有这样一行代码:

)
大家是否还记得,字符编码过滤器执行之前不能调用 request.getParameter方法,如果提前调用了,乱码问题就无法解决了。因为request.setCharacterEncoding()方法的执行必须在所有request.getParameter()方法之前执行。因此这两个过滤器就有先后顺序的要求,在web.xml文件中,应该先配置CharacterEncodingFilter,然后再配置HiddenHttpMethodFilter。
5. 总结:
RESTFul风格与传统方式对比区别
RESTFul 风格的 “查询” 所有(RESTFul 规范 需要发送 GET请求)
RESTFul 风格的 根据 “id 查询”( RESTFul 规范 需要发送 GET请求)
RESTFul 风格的 “增加数据” (RESTFul 规范 需要发送 POST 请求)
RESTFul 风格的 “修改数据” (RESTFul 规范 需要发送 PUT 请求)
如何发送PUT请求?
第一步:首先你必须是一个POST请求。
第二步:在发送POST请求的时候,提交这样的数据:_method=PUT,使用隐藏域进行配置
第三步:在web.xml文件配置SpringMVC提供的过滤器:HiddenHttpMethodFilter**
注意:
<!-- 隐藏域-->
<input type="hidden" name="_method" value="put">
隐藏域的 name 必须只能是 “_method”, value是 put(大小写忽略)
RESTFul 风格的 “删除数据” 数据(RESTFul 规范 需要发送 DELETE 请求);如何发送 DELETE 请求?,和 发送 PUT 请求的三步是一样的,只需要将 value 的值改为 delete 即可
HiddenHttpMethodFilter 该过滤器一定要在字符编码过滤器后面配置,不然,先设置的话,可能会出现获取到的请求数据是乱码。
6. 最后:
“在这个最后的篇章中,我要表达我对每一位读者的感激之情。你们的关注和回复是我创作的动力源泉,我从你们身上吸取了无尽的灵感与勇气。我会将你们的鼓励留在心底,继续在其他的领域奋斗。感谢你们,我们总会在某个时刻再次相遇。”
Spring MVC 中使用 RESTFul 编程风格的更多相关文章
- Spring MVC中发布Restful Web服务
对于企业应用来说,数据是许多业务的命脉,软件通常是可替换的,但是多年积累的数据是永远不能替换的. 近些年来,以信息为中心的表述性状态转移(Representational State Tran ...
- Spring mvc中@RequestMapping 6个基本用法
Spring mvc中@RequestMapping 6个基本用法 spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: Java代码 @Reques ...
- Spring mvc中@RequestMapping 6个基本用法小结(转载)
小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMapping(value="/departments" ...
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
- Spring MVC中基于注解的 Controller
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响 ...
- Spring MVC 中 @ModelAttribute 注解的妙用
Spring MVC 中 @ModelAttribute 注解的妙用 Spring MVC 提供的这种基于注释的编程模型,极大的简化了 web 应用的开发.其中 @Controller 和 @Rest ...
- Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMa ...
- 转:Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 发表于3年前(2013-02-17 19:58) 阅读(11698) | 评论(1) 13人收藏此文章, 我要收藏 赞3 4 ...
- Spring MVC中@RequestMapping注解使用技巧(转)
@RequestMapping是Spring Web应用程序中最常被用到的注解之一.这个注解会将HTTP请求映射到MVC和REST控制器的处理方法上. 在这篇文章中,你将会看到@RequestMapp ...
- Spring MVC 中的基于注解的 Controller(转载)
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...
随机推荐
- rails 给数据库表里加入索引
创建迁移文件 rails g migration add_product_images_index 编写迁移文件 db/migrate/20170119093958_add_product_image ...
- 用Java 实现一个异步任务 可终止,可中断,可继续功能
在 Java 中实现一个异步任务可以使用多线程和线程池技术,同时需要考虑终止.中断和继续等功能.下面展示一个简单的示例代码,实现异步任务的终止.中断和继续等功能: import java.util.c ...
- C#语言:散修笔记
文章目录 前言 数组的几种定义方法 out 和 ref 的区别 可变参数params 静态方法与非静态方法 >❀什么时候使用静态和非静态 构造函数 >❀类中方法的重载 >❀在类中输出 ...
- IDEA+carbon.now.sh安装使用
安装 打开IDEA,选择setting-->plugins 搜索carbon.now.sh,点击安装,重启IDEA即可. 使用 选择需要生成的代码,Ctrl+A全选.然后再代码中点击右键,找到o ...
- 训练营 |【AIRIOT大学计划暑期训练营】第三期即将开营,报名从速!
培养新生力量,聚焦产业融合.为了促进物联网产业的纵深发展和创新,推进教育链.产业链与创新链的有机衔接,提高学生理论.实践和创新能力,为行业培养更多优秀人才,航天科技控股集团股份有限公司将于2023年7 ...
- Android 13 - Media框架(10)- NuPlayer::Renderer
关注公众号免费阅读全文,进入音视频开发技术分享群! 这一节我们来了解 NuPlayer Renderer 是如何工作,avsync 机制是如何运行的. 1.创建 Renderer void NuPla ...
- NOIP模拟60
T1 整除 解题思路 答案就是 n 的每一个质因数的合法的答案数相乘(证明的话就....) 但是复杂度显然不允许(虽然我们可以给指数取模水过去).. 可以用积性筛(线性筛)利用质数筛出 \(x^m\) ...
- 8.24考试总结(NOIP模拟47)[Prime·Sequence·Omeed]
时间带着明显的恶意,缓缓在我的头顶流逝. T1 Prime 解题思路 成功没有签上到... 一看数据范围 \(R-L+1\le 10^7,R\le 10^{14}\) ,这肯定是判断范围内的数字是否可 ...
- OpenCV笔记(6) Bitwise
源码: BitwiseAnd //dst = src1 & src2 public static void BitwiseAnd(InputArray src1, InputArray s ...
- mac home目录下无法mkdir目录及文件的解决方法
主要参考以下几篇文章 https://www.cnblogs.com/zhangbao3/p/12600058.html https://www.v2ex.com/t/607387 https://w ...



