对于想了解调用DELETEapi在Postman上不起作用的读者,本文将提供新的信息,我们将详细介绍调用delete函数,并且为您提供关于(POST)的POSTMANAPI请求不起作用、@Contro
对于想了解调用 DELETE api 在 Postman 上不起作用的读者,本文将提供新的信息,我们将详细介绍调用delete函数,并且为您提供关于(POST) 的 POSTMAN API 请求不起作用、@Controller 文件相关 @RequestMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping、@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping、@RequestMapping详解、@RequestMapping,@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法(推荐)的有价值信息。
本文目录一览:- 调用 DELETE api 在 Postman 上不起作用(调用delete函数)
- (POST) 的 POSTMAN API 请求不起作用
- @Controller 文件相关 @RequestMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping
- @GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping、@RequestMapping详解
- @RequestMapping,@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法(推荐)
调用 DELETE api 在 Postman 上不起作用(调用delete函数)
尝试将 empID
添加到路由
[Route("api/Employee/DeleteEmployee/{empID}")]
[HttpDelete]
public string DeleteEmployee(int empID)
(POST) 的 POSTMAN API 请求不起作用
如何解决(POST) 的 POSTMAN API 请求不起作用?
我是 node.js 的新手,遇到了一些错误。我试图在 Postman 上发送一个 POST 请求,但它给了我空白,里面没有数据。而且我检查了我的数据是否有效然后我得到了,我发送的数据是有效的。有人可以推荐我吗?
这是我的索引文件(index.js):
const express = require("express");
const app = express();
const dotenv = require("dotenv");
const mongoose = require("mongoose");
//Import Routes
const authRoute = require("./routes/auth");
const postRoute = require("./routes/posts");
dotenv.config();
//connect to DB
mongoose.connect(
process.env.DB_CONNECT,{ useNewUrlParser: true,useUnifiedTopology: true,useCreateIndex: true },() => console.log("connected to DB!!")
);
//Middleware
app.use(express.json());
//Route Middlewares
app.use("/api/user",authRoute);
app.use("/api/posts",postRoute);
//PORT NUMBER
const port = process.env.PORT || 8080; // default port to listen
// start the Express server
app.listen(port,() => {
console.log(`server started at http://localhost:${port}`);
});
这是我的身份验证文件(auth.js):
const router = require("express").Router();
const User = require("../model/User");
const jwt = require("jsonwebtoken");
const bcrypt = require("bcryptjs");
const { registerValidation,loginValidation } = require("../validation");
//REGISTER
router.post("/register",async (req,res) => {
console.log("register");
//Lets validate a data before we make a user
const { error } = registerValidation(req.body);
if (error) return res.status(400).send(error.details[0].message);
//Checking if the user is already in the database
const emailExist = await User.findOne({ email: req.body.email });
if (emailExist) return res.status(400).send("Email Already Exists");
//HASH THE PASSWORD
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(req.body.password,salt);
//Create a New User
const user = new User({
name: req.body.name,email: req.body.email,password: hashedPassword,});
try {
const savedUser = await user.save();
res.send({ user: user._id });
} catch (err) {
res.status(400).send(err);
}
});
//LOGIN
router.post("/login",res) => {
//Lets validate a data before we make a user
const { error } = loginValidation(req.body);
if (error) return res.status(400).send(error.details[0].message);
//Checking if the email exists in the database
const user = await User.findOne({ email: req.body.email });
if (!user) return res.status(400).send("Email is Not Found");
//Check if password is correct
const validPass = await bcrypt.compare(req.body.password,user.password);
if (!validPass) return res.status(400).send("Invalid Password");
//Create and assign a Token
const token = jwt.sign({ _id: user._id },process.env.TOKEN_SECRET);
res.header("auth-token",token).send(token);
});
module.exports = router;
如您所见:
我无法通过 POST 请求发送数据和获取数据,数据库也已连接。
解决方法
试试console.log(req.body)
。
如果您的 req.body
为空,那么您需要在中间件(index.js 文件)中添加一个包 body-parser
。
const bodyParser = require(''body-parser'');
app.use(bodyParser.urlencoded({ extended: true }));
@Controller 文件相关 @RequestMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping
https://blog.csdn.net/magi1201/article/details/82226289(copy)
最近学习看一些代码,发现对于发送请求这件事,有的地方用@RequestMapping,有的地方用@PostMapping,为了搞清楚区别,特意查了下spring 源代码,现在特此记录下。
@GetMapping用于将HTTP get请求映射到特定处理程序的方法注解
具体来说,@GetMapping是一个组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。
@PostMapping用于将HTTP post请求映射到特定处理程序的方法注解
具体来说,@PostMapping是一个组合注解,是@RequestMapping(method = RequestMethod.POST)的缩写。
下面我们来看下@GetMapping的源码,可以对上面的两句释义给予充分的支撑。
/**
* Annotation for mapping HTTP {@code GET} requests onto specific handler
* methods.
*
* <p>Specifically, {@code @GetMapping} is a <em>composed annotation</em> that
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.GET)}.
*
*
* @author Sam Brannen
* @since 4.3
* @see PostMapping
* @see PutMapping
* @see DeleteMapping
* @see PatchMapping
* @see RequestMapping
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = RequestMethod.GET)
public @interface GetMapping {
/**
* Alias for {@link RequestMapping#name}.
*/
@AliasFor(annotation = RequestMapping.class)
String name() default "";
...
}
上面代码中,最关键的是 @RequestMapping(method = RequestMethod.GET),这行代码即说明@GetMapping就是@RequestMapping附加了请求方法。同时,可以看到@GetMapping这个注解 是spring4.3版本引入,同时引入的还有@PostMapping、@PutMapping、@DeleteMapping和@PatchMapping,一共5个注解。
所以,一般情况下用@RequestMapping(method = RequestMethod. XXXX)即可。
@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping、@RequestMapping详解
最近写项目中突然发现有人再controller层写@PostMapping,这对于经常用@RequestMapping的我来说,感到跟奇怪,网上搜寻了一些资料,特在此整合一下:
Spring4.3中引进了{@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping} 来帮助简化常用的HTTP方法的映射 并更好地表达被注解方法的语义
@GetMapping: 处理get请求,传统的RequestMapping来编写应该是@RequestMapping(value = “/get/{id}”, method = RequestMethod.GET)
新方法可以简写为:
@GetMapping("/get/{id}")
@PostMapping: 处理post请求,传统的RequestMapping来编写应该是@RequestMapping(value = “/get/{id}”,method = RequestMethod.POST)
新方法可以简写为:
@PostMapping("/get/{id}")
@PutMapping: 和PostMapping作用等同,都是用来向服务器提交信息。如果是添加信息,倾向于用@PostMapping,如果是更新信息,倾向于用@PutMapping。两者差别不是很明显。
@DeleteMapping 删除URL映射,具体没有再实践中用过,不知道好在什么地方
@PatchMapping 至今不知如何用,再什么场景下用。。。有知道的欢迎留言或私信
上面所有的mapping归根到底就是两种请求,即:post和get,Spinrg官方引进众多请求的原因个人感觉是,简化配置。post和get两者的区别如下:
首先,什么情况下是get请求呢:
直接在浏览器地址栏输入某个地址
表单默认的提交方式
什么情况下是post请求呢:
设置表单method = “post”
ajax type: ‘post’,
浏览器通过url处理的请求为get请求,如果后台限制只能用post请求会发生如下错误:
method not allowed, The specified HTTP method is not allowed for the requested resource.
1
get请求特点:
a. 请求参数会添加到请求资源路径的后面,只能添加少量参数(因为请求行只有一行,大约只能存放2K左右的数据)
b. 请求参数会显示在浏览器地址栏,路由器会记录请求地址 (极为的不安全)
c.如果传输中文,必定会乱码(原因:get请求默认编码格式为:IIO-8859-1,后台编码格式一般为:GBK或者UTF-8)
post请求的特点:
a. 请求参数添加到实体内容里面,可以添加大量的参数(也解释了为什么浏览器地址栏不能发送post请求,在地址栏里我们只能填写URL,并不能进入到Http包的实体当中)
b. 相对安全,但是,post请求不会对请求参数进行加密处理(可以使用https协议来保证数据安全)
————————————————
版权声明:本文为CSDN博主「只会debugger」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/java_xdo/article/details/88711192
@RequestMapping,@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法(推荐)

转:
@RequestMapping,@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法(推荐)
学习目标
1、一周掌握 JAVA 入门到进阶知识
2、掌握基础 C#l 窗体知识
3、手把手教你 vbs 脚本制作
4、强大的 IDEA 编程利器
5、经典少见的 面试题目技巧
@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法
- 学习目标
- 前言
- @PostMapping
- @DeleteMapping
- @PutMapping
- @GetMapping
- @RequestMapping
- 总结
前言
希望:2012 新的一年,想要的都拥有,得不到的都释怀!
@PostMapping
如图所示:
增加应该使用 POST
@DeleteMapping
如图所示:
删除应该使用 DELETE
@PutMapping
如图所示:
修改应该使用 PUT
@GetMapping
如图所示:
查询应该使用 GET
@RequestMapping
如图所示:
@GetMapping是一个组合注解 是@RequestMapping(method = RequestMethod.GET)的缩写
@DeleteMapping是一个组合注解 是@RequestMapping(method = RequestMethod.DELETE)的缩写
@PutMapping是一个组合注解 是@RequestMapping(method = RequestMethod.PUT)的缩写
@PostMapping是一个组合注解 是@RequestMapping(method = RequestMethod.POST)的缩写
总结
通过上面的介绍,我们应该学会了怎么用上述的注解了。
转:
@RequestMapping,@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法(推荐)
--Posted from Rpc
关于调用 DELETE api 在 Postman 上不起作用和调用delete函数的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于(POST) 的 POSTMAN API 请求不起作用、@Controller 文件相关 @RequestMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping、@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping、@RequestMapping详解、@RequestMapping,@GetMapping ,@PostMapping,@PutMapping,@DeleteMapping 请求的用法(推荐)的相关信息,请在本站寻找。
本文标签: