对于Thymeleaf中的每个循环,不重新调整结果

时间:2019-04-05 17:30:01

标签: java sql hibernate spring-boot thymeleaf

我以前曾经使用过这种方法来过滤一系列对象,所以我不知道为什么这种方法不起作用。该表中应显示三个结果,但我没有找到结果。在控制器功能中,如果我调试它,我会看到它正在注册contactList ...,所以不确定为什么它没有在表中填充。我一直收到此未绑定的错误:Bean名称“ contactList [0]”的BindingResult和普通目标对象都不能用作请求属性。我不确定如何绑定它。

这是未填充的表。整个HTML页面以CarrierAppointment作为对象运行。

<table class="table table-striped" data-toggle="table" data-show-toggle="true" data-classes="table-no-bordered" data-striped="true" data-search="true"  data-show-columns="true" >
    <thead>
    <th>Contact Type</th>
    <th>Contact Name</th>
    <th>Contact's Email</th>
    <th>Contact's Phone</th>
    <th th:if="${role.isCarrierAdmin}" class="text-right"><button type="submit" name="addCommercialContact" class="btn btn-default" ><span class="fa fa-plus"></span></button></th>
    </thead>
    <tbody>
    <tr th:each="contact,stat : *{contactList}">
        <td> <select class="form-control" th:field="*{contactList[__${stat.index}__].contactType}">
            <option value="Account Manager">Account Manager</option>
            <option value="Marketing Manager">Marketing Manager</option>
            <option value="Underwriter">Underwriter</option>
        </select></td>
        <td> <input type="text" class="form-control" th:field="*{contactList[__${stat.index}__].contactName}"/></td>
        <td> <input type="text" class="form-control" th:field="*{contactList[__${stat.index}__].contactEmail}"/></td>
        <td><input type="text" class="form-control" th:field="*{contactList[__${stat.index}__].contactPhone}"/></td>
        <td> <input type="hidden" class="form-control" th:field="*{contactList[__${stat.index}__].contactTable}" th:value="Commercial Lines"/></td>
        <td class="text-right" th:if="${role.isCarrierAdmin}"> <button type="submit" name="removeContact" th:value="${stat.index}" class="btn btn-danger"><span class="fa fa-trash"></span></button></td>
    </tr>

    </tbody>
</table>

这是控制器功能:

       @RequestMapping(value="/carrierAppointment/details/{id}")
public String viewDetails(Model model,@PathVariable("id")CarrierAppointment carrierAppointment){
    String username= SecurityContextHolder.getContext().getAuthentication().getName();
    Role role=roleRepository.findByUsernameContainingIgnoreCaseAndActive(username,true);
    Document newDoc=new Document();

    List<CarrierContact> contactList = new ArrayList<>();
    CarrierContact contact = new CarrierContact();
    contactList.add(contact);

    model.addAttribute("contact",contact);
    model.addAttribute("role",role);
    model.addAttribute("newDocument",newDoc);
    model.addAttribute("docs",documentRepository.findByCarrierAppointment(carrierAppointment));
    model.addAttribute("carrier",carrierAppointment);
    model.addAttribute("contactList",contactList);
    return "carrierAppointments/carrierDetails";
}

联系方式

@Entity
@Table(name="CarrierContact")
public class Contact {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="contactId")
    private Long id;
    private String contactType;
    private String contactName;
    private String contactEmail;
    private String contactPhone;
    private Long carrier;
    private String contactTable;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContactType() {
        return contactType;
    }

    public void setContactType(String contactType) {
        this.contactType = contactType;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getContactEmail() {
        return contactEmail;
    }

    public void setContactEmail(String contactEmail) {
        this.contactEmail = contactEmail;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

//    public CarrierAppointment getCarrier() {
//        return carrier;
//    }
//
//    public void setCarrier(CarrierAppointment carrier) {
//        this.carrier = carrier;
//    }
//
    public Long getCarrier() {
        return carrier;
    }

    public void setCarrier(Long carrier) {
        this.carrier = carrier;
    }

    public String getContactTable() {
        return contactTable;
    }

承运人预约模式:

@Entity
@Table(name="CarrierAppointment")
@EntityListeners(AuditingEntityListener.class)
public class CarrierAppointment {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CarrierAppointmentId")
    private Long id;
    private String parentCompanyCarrier;
    private String writingCompany;
    private String masterAgencyCode;
    private String serviceCenterCode;
    private String affiliateSubcode;
    private String clMarketingContact;
    private String plMarketingContact;
    private String clUnderwriterContact;
    private String plUnderwriterContact;
    private String plAccountManager;
    private String clAccountManager;
    private String supportDesk;
    private String licensingDept;
    private String custServiceDept;
    private String loginPasswordRequirements;
    private String quotingWebsite;
    private String states;
    private String appetite;
    private String affiliateUseOfLogo;
    private String premiumVolumeRequirementForAffiliateSubcode;
    private String notes;
    private String knownForPersonal;
    private String knownForCommercial;
    private String linesOfBusiness;
    @CreatedDate
    private LocalDateTime createdDate;
    @LastModifiedDate
    private LocalDateTime lastModifiedDate;
    private Boolean carrierDownloads;

    @OneToMany(
            cascade = CascadeType.ALL
    )
    @JoinColumn(name = "carrier")
    private List<Contact> contactList= new ArrayList<>();

    public List<Contact> getContactList() {
        return contactList;
    }

    public void setContactList(List<Contact> contactList) {
        this.contactList = contactList;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getParentCompanyCarrier() {
        return parentCompanyCarrier;
    }

    public void setParentCompanyCarrier(String parentCompanyCarrier) {
        this.parentCompanyCarrier = parentCompanyCarrier;
    }

0 个答案:

没有答案