- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 postman 中创建 POST 或 GET 请求时遇到问题。我有一个 Controller ,它应该保存一个新项目或从数据库接收所有项目。如果我尝试将项目保存在数据库中实现 CommandLineRunner 的类中,则一切正常。有关更多额外详细信息,我将代码放在下面:
这是项目类:
@Entity
@Table(name = "project")
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "proj_id")
private int projectId;
@Column(name = "project_name")
private String projectName;
@Column(name = "dg_number")
private int dgNumber;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "variant_gate_relation",
joinColumns = {@JoinColumn(name = "proj_id")},
inverseJoinColumns = {@JoinColumn(name = "gate_id")}
)
private Set<Gate> gates = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "variant_threshold_relation",
joinColumns = @JoinColumn(name = "proj_id"),
inverseJoinColumns = @JoinColumn(name = "threshold_id"))
private Set<Threshold> thresholds = new HashSet<>();
public Project() {
}
public Project(String projectName, int dgNumber, Set<Gate> gates, Set<Threshold> thresholds){
this.projectName = projectName;
this.dgNumber = dgNumber;
this.gates = gates;
this.thresholds = thresholds;
}
Controller
@RestController
@RequestMapping(ProjectController.PROJECT_URL)
public class ProjectController {
public static final String PROJECT_URL = "/cidashboard/projects";
@Autowired
private final ProjectService projectService;
public ProjectController(ProjectService projectService) {
this.projectService = projectService;
}
@GetMapping
public List<Project> getAllProjects(){
return projectService.findAllProjects();
}
@GetMapping("/{id}")
public Project getProjectById(@PathVariable int id) {
return projectService.findProjectById(id);
}
@PostMapping
// @Consumes(MediaType.APPLICATION_JSON_VALUE)
public Project saveProject(@RequestBody Project newProj) {
return projectService.saveProject(newProj);
}
}
这是我的 CommandLineRunner
@Component
public class Test implements CommandLineRunner {
private final ProjectRepository projectRepository;
private final GateRepository gateRepository;
private final ThresholdRepository thresholdRepository;
public Test(ProjectRepository projectRepository, GateRepository gateRepository, ThresholdRepository thresholdRepository) {
this.projectRepository = projectRepository;
this.gateRepository = gateRepository;
this.thresholdRepository = thresholdRepository;
}
@Override
public void run(String... args) throws Exception {
Gate gate1 = new Gate("gate5", 23);
gateRepository.save(gate1);
Threshold threshold1 = new Threshold(101, "threshold5");
thresholdRepository.save(threshold1);
Set<Gate> gates = new HashSet<>();
gates.add(gate1);
Set<Threshold> thresholds = new HashSet<>();
thresholds.add(threshold1);
Project project1 = new Project("project1", 20, gates, thresholds);
projectRepository.save(project1);
List<Project> allProjectsFromDatabase = projectRepository.findAll();
System.out.println("List of all projects from database : ");
for (Project project : allProjectsFromDatabase) {
System.out.println(project.toString());
}
System.out.println("---------------------------------------------");
List<Gate> allGatesFromDatabase = gateRepository.findAll();
for (Gate gate : allGatesFromDatabase) {
System.out.println(gate);
}
}
}
我的控制台输出是:
1 project1 201 gate5 23.0 threshold5 101
我尝试执行 postman 的此请求:
{
"projectName": "project2",
"dgnumber": 1,
"gates": {
"gateType" : "gate2",
"gateValue" : 13
},
"thresholds": {
"thresholdType" : "threshold2",
"thresholdValue" : 22
}
}
我收到以下输出:
{
"projectId": 3,
"projectName": "project2",
"dgnumber": 1
}
并且在数据库中仅在项目表中保存了数据,在门表、阈值表、variant_gate_relation和variant_threshold_relation中没有保存任何内容
最佳答案
在 CommandLineRunner
中,您可以在保存项目之前执行此操作。
Gate gate1 = new Gate("gate5", 23);
gateRepository.save(gate1);
Threshold threshold1 = new Threshold(101, "threshold5");
thresholdRepository.save(threshold1);
Set<Gate> gates = new HashSet<>();
gates.add(gate1);
Set<Threshold> thresholds = new HashSet<>();
thresholds.add(threshold1);
您也应该在从端点保存时复制这一点(gateRepository.save()
和 thresholdRepository.save()
与此处相关)。
关于java - Postman 请求不起作用 - Rest APi 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530940/
我在 postman 的预请求脚本中有以下代码——它给了我当前日期。我宁愿想要昨天的日期(current_timestamp - 1 天)。 var current_timestamp = new D
Postman Pro 可以向多个 Free Postman 用户共享无限制的请求吗? 我正在考虑设置一个 Pro 帐户作为中央请求收集存储,然后 Free Postman 用户只需克隆/读取它即可。
有可能在 postman 内部使用数组变量吗? 例如在请求正文中: { "myData" : {{arrayVariable}} } 在数据文件中: { "arrayVariable"
我有一个 postman 集合,我想将一组三个 API 调用链接在一起,并使用 runner 函数提供数据文件。可以说他们是:/prepareUpload/upload/confirmUpload并且
如何从另一个 GET API 的预请求脚本选项卡调用 POST API 请求(登录 API 具有带用户名和密码字段的请求正文),该 API 在其请求 url 中使用来自上述 API 正文的 token
当前,可以从global和environment范围以及预请求脚本中的通用variable设置和获取变量。但是,文档尚不清楚,是否可以通过编程方式设置collection作用域变量。 例如 pm.en
我正在使用 postman (v7.7.3),当我上传文件以将正文作为表单数据发送时,我收到了以下警告。 “此文件不在您的工作目录中。与您共享此请求的队友将无法使用此文件。为了使协作更容易,您可以在“
standalone Postman client在哪里?对于 Windows,离线工作时保存集合吗? 为了澄清,我想找到禁用在线同步时 Postman 默认保存集合文件的位置。我不试图 export
我之前使用过 Postman Chrome 扩展以及 Postman Interceptor Extension在 Postman 中捕获 Chrome 发出的 HTTP 请求。 但是,现在 Post
在 Postman 中单击保存的请求后,我得到的 View 如下所示: 要查看正文,我需要单击“正文”。 这不是什么大问题,除非我要处理 20 个左右的请求,并在每个请求的正文中查找特定的内容,如果能
我正在查看 Postman 快捷方式面板,但没有看到在请求正文中注释部分代码的快捷方式,复制和粘贴非常烦人 发表评论。 最佳答案 根据快捷方式面板Ctrl +/打开快捷方式面板但我不小心在请求正文中这
是否可以在我的 postman 测试用例中访问响应大小的值? 虽然我能够看到响应大小以及状态代码和响应时间(我可以在使用responseCode.code和responseTime的测试用例中使用这两
我正在尝试使用 Windows native Postman 应用程序 (V4.8.0) 将简单的 Get 命令发布到我在本地主机上运行的服务,但它们失败了。 postman 控制台显示 Error:
Newman 帮助指定集合、环境和全局变量可以作为路径或 URL 传递。我可以看到如何从 Postman 获取收藏 URL(通过转到“共享”>“收藏链接”)。 如何在 Postman 中获取 Envi
我们正在扩展到一个大型微服务构建,并通过 postman 完成更多测试(现场验证、错误测试等)。好奇...您的团队如何组织大量 API 的集合? (按 API、按测试类型、按发布等)从一个团队传递到另
Postman 对我来说是一个了不起的工具,但我对使用变量有一些疑问。在我的收藏中,我有 4 个选项卡/请求。 首先是获取用于其他三个的 token ( token 在 15 分钟后过期,因此我必须经
由于所有 Postman 集合基本上都是 .json 文件,因此很难通过代码审查工具审查在 Postman 中编写的代码。 目前我继续在GitHub上查看这样的.json文件,但是不太方便。 例如,这
我正在尝试使用 Newman 自动化 postman 测试.授权有问题。授权 bearer token 发生变化并且是动态的。有谁知道如何自动执行此操作? 最佳答案 Postman 有变量这个很好的特
Postman 允许使用 pre-defined variables 生成随机虚拟数据,例如,这个将被随机公司名称替换: {{$randomCompanyName}} 多次使用预定义变量会在每个请
我正在使用一个开放的 API。 但我只使用了 API 提供的响应中的一小部分数据。当我使用具有不同参数的 API 进行测试以查看响应时。 我不想每次发送请求时都看到整个 API 响应,我只想看到我感兴
我是一名优秀的程序员,十分优秀!