REST:是一种互联网软件架构的规范
Representational state transfer:资源在网络中以某种表现形式进行状态转移
- 资源:互联网上的一个实体(文本 图片 歌曲......)每一个网络上的实体,都是通过URI进行唯一标识
- 表现形式(表现层):资源的信息载体种形式(文本 json串 xml文档 ......)
- 状态转移(状态转化):
Restful 架构:基于REST原则实现
程序中要针对所有url进行规范化
http://localhost:8095/XXX/xxx?param=value&parma=value
具体实现:
xml文件
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 初始化参数: 在DispatcherServlet中完成Spring容器的加载 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
web前端vue
sendInfo(){
//axios发请求
this.$axios.post('http://localhost:8095/Springmvc_Restful/test/1/abc')
.then(res=>{
console.log(res.data);
})
.catch(err=>{
console.log(err)
})
Controller.java
@RequestMapping(value="test/{id}/{uname}",method={RequestMethod.POST})
@ResponseBody
public String test(@PathVariable int id,@PathVariable String uname ){
System.out.println(id);
System.out.println(uname);
return "{\"result\":\"success\"}";
}