我有一个对象:“ MisraMessages”,看起来像这样:
@Entity
@Table(name = "misra_messages")
public class MisraMessages {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "misra_id")
private int misraMessagesId;
@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "build_id")
private Build buildId;
@Column(name = "file_name")
private String fileName;
@Column(name = "file_path")
private String filePath;
@Column(name = "message_number")
private String messageNumber;
@Column(name = "message_severity")
private String messageSeverity;
@Column(name = "guideline_number")
private String guidelineNumber;
@Column(name = "guideline_name")
private String guidelineName;
我希望有一个复选框,其中包含上面的字段。基于我要选择的字段,我要创建一个表。我不知道我写的是不是一种好方法,但是我尝试了一下……我的问题是即使没有,我也会收到“复选框已选中”的信息。
<form action="#" th:action="@{/cidashboard/filter/result}" method="post">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="build" value="build">
<label class="form-check-label">Build</label>
</div>
............................
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="guidelineType" value="guidelineType">
<label class="form-check-label">Guideline Type</label>
</div>
<input type="submit" value="Submit" />
</form>
这是我的控制器。我只尝试了一个复选框。
@GetMapping("cidashboard/filter")
public String tableFilterInformation(Model model) {
String guidelineType= "";
model.addAttribute("guidelineType", guidelineType);
return "filterTable";
}
@PostMapping("cidashboard/filter/result")
public String getTableFilterInformationResult(@ModelAttribute("guidelineType") String checkboxGuidelineType) {
if(checkboxGuidelineType != null)
{
System.out.println("checkbox is checked");
}
else
{
System.out.println("checkbox is not checked");
}
return "filterTableResult";
}