我现在正在编写ASP.NET Web API,一切都适用于2个控制器.现在我尝试和以前完全一样,但这次我得到一个奇怪的错误:
System.InvalidOperationException:"实体类型'UserItem'需要定义主键."
那么,为什么UserItem在其他人不需要时需要主键呢?
这是我的UserItem班级:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ModulApi.Models
{
public class UserItem
{
public int matrikelnr { get; set; }
public string studiengang { get; set; }
public string user_semester { get; set; }
public string user_max_klausur { get; set; }
//Not necessary Constructor. I try to fix the primary Key error.
public UserItem()
{
this.matrikelnr = 0;
this.studiengang = "";
this.user_max_klausur = "";
this.user_semester = "";
} …Run Code Online (Sandbox Code Playgroud) 我想在我的 REST API 中实现 2 个端点:
@PostMapping("/example")
public ObjectResponse postObject(@RequestBody Example example){... //Add new Example to DB}
@PutMapping("/example")
public ObjectResponse postObject(@RequestBody Example example){...//Update existing Example}
Run Code Online (Sandbox Code Playgroud)
我的示例可能如下所示:
public class Example{
@Id
@Hidden
private String id;
private String somethingCool;
}
Run Code Online (Sandbox Code Playgroud)
我想隐藏ID,这样使用Post的用户就不会向我发送带有ID的请求。我想让它由我的 mongoDB 生成。
在另一个用例中,在 Put 期间必须发送 ID 以便识别应更新的对象。但我的 Swagger 3.0 上的 ID 字段也隐藏在这里。
如何在我的帖子中隐藏它,但在我的看跌期权中显示它?
多谢!
我现在正在使用 next.js 构建一个前端,它使用 next-auth 通过 GitHub OAuth 进行身份验证。
Next-auth 处理包括会话在内的所有身份验证,并将所有内容保存到数据库中,在我的例子中是 Postgres DB。
我现在还想通过 REST API 将我的前端连接到 Spring Boot 后端服务器,该 API 处理一些文件访问。我可以简单地将会话令牌包含到授权标头中,并将我的后端连接到 Postgres DB,并检查是否存在具有此令牌的会话。
但这种做法似乎并不正确。保护我的后端的最佳方法是什么?我的后端如何检查用户是否使用 GitHub 登录?
我得到了一串字符串,并希望按长度映射它们
Stream<String> s = Stream.of("aaaa", "a", "aaa", "a", "aaaa", "aa", "aaaaaa", "aa");
Map<Integer, Set<String> result = null;
int i = 0;
result.put(i, s.filter(x -> (x.length() == i));
Run Code Online (Sandbox Code Playgroud)
显然,这不会以这种方式工作,因为我不能多次打开流,并且我无法访问longes String以获得良好的循环.但是我怎么能做到呢?