我无法从弹簧靴中控制器的标头中拿出一个值
我已经在Spring Boot中构建了一个具有表单的Web应用程序,除了从其从标头用户名中插入的表单中插入的表单中的值。这是控制器中的代码:
@PostMapping("/BilantErr/")
public String postIndex(@RequestParam(name = "cui") String cui, @RequestParam(name = "an_raportare") String anRaportare,
@RequestParam(name = "perioada") String perioada,
@RequestHeader("iv-user") String operator, @RequestParam(name = "motivatie") String motivatie, Model model) {
String page = "";
//String operator = "serban";
try {
if (repository.insert(cui, anRaportare, operator, motivatie, perioada) == true) {
page = "success";
} else {
page = "error";
}
} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(BilantErr.class);
}
return page;
}
我遇到的错误是:已解决[org.springframework.web.bind.missingrequestheaderexception:不存在参数类型字符串的必需请求标题'iv-user'不存在]代码>
问题可能是什么?已经在JSF中构建了一个应用程序,可以使用户从标题中带走,我必须用Spring应用程序替换它。我在做什么错?谢谢
I have built a web application in Spring Boot that has a form and besides the values from the form that it inserts in the database it takes from the header the username. This is the code from the Controller:
@PostMapping("/BilantErr/")
public String postIndex(@RequestParam(name = "cui") String cui, @RequestParam(name = "an_raportare") String anRaportare,
@RequestParam(name = "perioada") String perioada,
@RequestHeader("iv-user") String operator, @RequestParam(name = "motivatie") String motivatie, Model model) {
String page = "";
//String operator = "serban";
try {
if (repository.insert(cui, anRaportare, operator, motivatie, perioada) == true) {
page = "success";
} else {
page = "error";
}
} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(BilantErr.class);
}
return page;
}
The error that I am getting is : Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'iv-user' for method parameter type String is not present]
What may be the problem ? There is an application already built in JSF that works and takes the user from the header and I have to replace it with a Spring app. What am I doing wrong ? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
缺少requestheaderexception
表示HTTP请求不包含“ IV-user”标头。您必须先看看您的请求。您可以通过以下代码段来阅读HTTP请求的所有标题:MissingRequestHeaderException
means the HTTP request doesn't contain a "iv-user" header. You must have a look to your request first. You can read all headers of the HTTP request by following code snippet:需要“ iv-user”请求标题,但似乎在收到的请求中似乎不存在。您可以修复您的请求或使标题可选:
@requestheader(value =“ iv-user”,必需= false)
The request header "iv-user" is required but does not seem to be present in the request you receive. You could fix your request or make the header optional:
@RequestHeader(value = "iv-user", required = false)