gpt4 book ai didi

javascript - 如何进行bean验证

转载 作者:太空宇宙 更新时间:2023-11-04 11:07:38 27 4
gpt4 key购买 nike

这是我用于 bean 验证的代码示例。但是案例在提交的表单中,错误消息未显示

//controller class
@RequestMapping(value= "/offer.create", method=RequestMethod.POST)
public String doActions(@Valid @ModelAttribute ("offers") Offer offer, BindingResult result,
@RequestParam String action, Map<String, Object> map,
HttpServletRequest request){

//

if(result.hasErrors()) {
/*map.put("offers", offerservice.getAlloffers());
map.put("Offer", new Offer());
map.put("SeasonTypes", new SeasonTypes());
map.put("timeBased", new TimeBased());
map.put("seasons", offerservice.getAllSeasons());*/
System.out.println("inside the error section!!");
// System.out.println(merchantService.getAllMerchant().size());
System.out.println("The error "+result);

return "create-offer";



}

//----------------------------------------------------------------------------------------这是jsp表单

<div class="panel-group accordion" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default red box">
<div class="panel-heading" role="tab" id="heading-1">

<h4 class="panel-title">Single Image</h4>


</div>

<div class="panel-body">
<p>Upload or drag and drop image of your choice</p>
<div class="row">
<div class="col-md-12" style="margin-bottom:20px;width:100%;">
<form action="upload.image1" class="dropzone dropzone-mini" style="width:145px;" method="post" enctype="multipart/form-data"></form>
</div>
</div>


<form:form action="offer.create" method="POST" commandName="Offer" id="formID" enctype="multipart/form-data">

<div class="form-group">
<label for="exampleInputEmail1"> Merchant Name</label>
<form:input path="offerHeading" class="form-control normtxtin" />
<form:errors path="offers.*" cssClass="text-warning"></form:errors>
</div>

<div class="form-group">
<label for="exampleInputEmail1"> Heading</label>
<form:input path="offerSubheading" class="form-control normtxtin" />
<form:errors path="offers.*" cssClass="text-warning"></form:errors>
</div>

<div class="form-group">
<label for="exampleInputEmail1">Description</label>
<form:textarea path="offerDescription" rows="5" cols="30" class="form-control normtxtin"/>
</div>

<div class="form-group">
<label for="exampleInputEmail1">Issue Date</label>
<form:input path="issueDateTime" type="date" class="form-control normtxtin" placeholder="Select date"/>
</div>

<div class="form-group">
<label for="exampleInputEmail1">Expiration Date</label>
<form:input path="expiryDate" type="date" class="form-control normtxtin" placeholder="Select date"/>
</div>

<div class="form-group">
<label for="exampleInputEmail1">Offer Discount</label>
<form:input path="offerDiscount" class="form-control normtxtin" placeholder="offer Discount for the Entire offer"/>
</div>

<div class="form-group">
<label for="exampleInputEmail1">Allocated points </label>
<form:input path="offerPrice" class="form-control normtxtin" />
</div>

<div class="form-group">
<label for="exampleInputEmail1">Offer Price</label>
<form:input path="pointsAllocated" class="form-control normtxtin" />
</div>

<div class="form-group">
<label for="exampleInputEmail1">offer Claim Limit</label>
<form:input path="offerClaimLimit" class="form-control normtxtin" />
</div>

<div class="form-group">
<label for="exampleInputEmail1">Available Branches</label>

<form:input path="offerAvailableBranches" class="form-control normtxtin" placeholder="Add branches seperated by a ',' Ex: galle, colombo, Kandy" />
</div>

<div class="col-md-6"></div>
<div class="col-md-6">
<button type="submit" class="btn btn-primary" style="width:100%;font-size:16px;padding:10px;" name="action" value="Add">Create Offer</button>
</div>
</form:form>
</div>
</div>

这是模型类

public class Offer implements java.io.Serializable {

private long offerid;
private Merchant merchant;
private MerchantUser merchantUserByAddedByRef;
private MerchantUser merchantUserByLastModifiedByRef;
private String issueDateTime;
private BigDecimal pointsAllocated;
private String expiryDate;
private String offerHeading;
@NotEmpty
private String offerSubheading;
@NotEmpty
private String offerDescription;
private String offerFilterTypes;
private String videoUrl;

这是message.property文件

NotEmpty.Offer.offerSubheading = Heading field can't be Empty!
NotEmpty.Offer.offerDescription = Heading field can't be Empty!

在jsp页面中,单击按钮后将出现相关表单。在进行验证后,如果有错误,它会重定向到jsp页面,那么这里不应该有该表单。因为该表单仅在单击按钮后才会出现。因此无法显示错误消息

以下图片是.jsp View .jsp page view before press single image button after click that single image button

最佳答案

我终于完成了我的工作问题是 @ModelAttribute ("offers") ---> Offers 和 commandName="Offer"彼此不匹配:)

关于javascript - 如何进行bean验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46336418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com