博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Day55 Axios的请求***
阅读量:801 次
发布时间:2019-03-25

本文共 1029 字,大约阅读时间需要 3 分钟。

axios介绍

  • (1)以前 vue-resource
    vue-resource是Vue.js的插件提供了使用XMLHttpRequest或JSONP进行Web请求和处理响应的服务
  • (2)现在(2.0之后) axios
    是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中
    美 [ˈprɑ:mɪs]
    axios的github:https://github.com/axios/axios

axios使用

在这里插入图片描述

  • (1)引入
  • (2)get请求
  • (3)post请求
		

  • 将{id:1} 这个json提交给后台,后面需要一个对象来接收 ,·`参数要加@RequestBody
  • RequestBody将json转换成User对象
@RestController@RequestMapping("/users")@Slf4jpublic class UserController {
@RequestMapping(path = "/find.do",method = {
RequestMethod.GET}) public Object get(Integer id){
log.info("get id "+id); User user = new User(); log.info("get user "+user); user.setId(id); user.setUsername("jack"+id); return user; } @RequestMapping(path = "/find2.do",method = {
RequestMethod.POST}) public Object post(@RequestBody User u){
//{id:1} log.info("post id "+u.getId()); User user = new User(); user.setId(u.getId()); user.setUsername("jack"+u.getId()); return user; }}

转载地址:http://zxsyk.baihongyu.com/

你可能感兴趣的文章