【发布时间】:2021-12-24 11:07:36
【问题描述】:
我一直在使用声纳来测试我的代码质量,但我无法用我的代码解决漏洞问题,它说我应该使用 Dto 或 pojo 类而不是实体类,但仍然无法解决它我不知道如何转换我的实体上课。 这是我的实体类:
@Entity
public class Mission implements Serializable {
private static final long serialVersionUID = -5369734855993305723L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
private String description;
@ManyToOne
private Departement departement;
@OneToMany(mappedBy="mission")
private List<Timesheet> timesheets;
public Mission() {
super();
}
public Mission(String name, String description){
this.name = name;
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Departement getDepartement() {
return departement;
}
public void setDepartement(Departement departement) {
this.departement = departement;
}
public List<Timesheet> getTimesheets() {
return timesheets;
}
public void setTimesheets(List<Timesheet> timesheets) {
this.timesheets = timesheets;
}
这是我遇到问题的 Restcontroller 方法:
@PostMapping("/ajouterMission")
@ResponseBody
public int ajouterMission(@RequestBody Mission mission) {
itimesheetservice.ajouterMission(mission);
try {
logger.info("in ajouter Mission");
logger.debug("Je vais commencer l'ajout");
itimesheetservice.ajouterMission(mission);
logger.info("out ajouter Mission");
return mission.getId();
}
catch (Exception e) { logger.error("Erreur dans ajouterMission() : " , e); }
return mission.getId();
}
这是有关声纳漏洞问题的屏幕截图以获取更多详细信息:enter image description here
【问题讨论】:
-
您在创建 DTO 时遇到了什么具体问题?
-
我已经创建了 DTO 但声纳仍然将其视为一个实体,如果您有任何建议如何将我的实体转换为 DTO 类以及如何在控制器上使用它
-
this is the rule description,请参阅“合规解决方案”部分...,在“更大的项目”上完成此操作:google.com/search?q=java+mapping+framework+comparison
-
您的
@Post/Get/.../RequestMapping仍然有参数,这些参数(类)被注释为@Entity,这是规则实际上在抱怨的。 ..a DTO 是一个类,它看起来[有点 - 非常] 像实体 ..并且具有相似的名称,但控制器和服务必须转换它们(来回)
标签: java spring spring-boot sonarqube sonarqube-scan