首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpelEvaluationException: EL1008E:在Thymeleaf应用程序中

SpelEvaluationException: EL1008E:在Thymeleaf应用程序中
EN

Stack Overflow用户
提问于 2018-01-14 09:55:22
回答 2查看 1K关注 0票数 0

我有一个基本的SpringBoot应用程序。使用Spring初始化器、嵌入式Tomcat、Thymeleaf模板引擎和包作为可执行的JAR文件。

我有这门课

代码语言:javascript
复制
@Entity
@Table(name="t_tdk_device")
@DiscriminatorValue("tdk")
public class TdkDevice extends Device {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    public TdkDevice() {
        super();
    }

    public TdkDevice(String deviceKey, String devicePAC) {
        super(deviceKey, devicePAC);
    }

    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<DeviceDriver> driverDevices = new HashSet<>();

    public Set<DeviceDriver> getDriverDevices() {
        return driverDevices;
    }

    public void setDriverDevices(Set<DeviceDriver> driverDevices) {
        this.driverDevices = driverDevices;
    }

}

另一个班

代码语言:javascript
复制
@Entity
@Table(name = "t_device_driver")
public class DeviceDriver implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public DeviceDriver() {

    }

    public DeviceDriver (Device device, Driver driver) {
        this.device = device;
        this.driver = driver;
    }


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "device_id")
    private Device device;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "driver_id")
    private Driver driver;

    public Device getDevice() {
        return device;
    }

    public void setDevice(Device device) {
        this.device = device;
    }

    public Driver getDriver() {
        return driver;
    }

    public void setDriver(Driver driver) {
        this.driver = driver;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((device == null) ? 0 : device.hashCode());
        result = prime * result + ((driver == null) ? 0 : driver.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        DeviceDriver other = (DeviceDriver) obj;
        if (device == null) {
            if (other.device != null)
                return false;
        } else if (!device.equals(other.device))
            return false;
        if (driver == null) {
            if (other.driver != null)
                return false;
        } else if (!driver.equals(other.driver))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "DeviceDriver [device=" + device + ", driver=" + driver + "]";
    }
}

还有这另一个

代码语言:javascript
复制
@Entity
@Table(name="t_driver")
@DiscriminatorValue("Driver")
public class Driver extends Guardian implements Serializable  {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public Driver() {
        super();
    }

    public Driver (User user) {
        super(user);
    }

    public Driver (User user, String trailerCode) {
        super(user);
        this.trailerCode=trailerCode;
    }

    @Column(name = "trailer_code")
    private String trailerCode;

    @OneToMany(mappedBy = "driver", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<DeviceDriver> driverDevices = new HashSet<>();


    public Set<DeviceDriver> getDriverDevices() {
        return driverDevices;
    }

    public void setDriverDevices(Set<DeviceDriver> driverDevices) {
        this.driverDevices = driverDevices;
    }

    public String getTrailerCode() {
        return trailerCode;
    }

    public void setTrailerCode(String trailerCode) {
        this.trailerCode = trailerCode;
    }

}

然后,我想从driverDevices中提取所有的驱动程序,但是当我这样做时,我想要从thymeleaf模板中提取这些驱动程序:

代码语言:javascript
复制
<select id="selectCompanyElementId"  >
                                            <option value="0">select</option>
                                            <option th:each="driver : ${device.driverDevices.driver}" 
                                                    th:value="${driver.id}" 
                                                    th:text="${driver.firstName}">
                                             </option>
                                    </select>

我发现了一个错误:

代码语言:javascript
复制
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'driver' cannot be found on object of type 'org.hibernate.collection.internal.PersistentSet' - maybe not public?
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-01-15 08:59:02

必须在集合上使用each循环。类似于:

代码语言:javascript
复制
<option th:each="dd : ${device.driverDevices}" 
        th:value="${dd.driver.id}" 
        th:text="${dd.driver.firstName}">
</option>
票数 0
EN

Stack Overflow用户

发布于 2018-01-14 11:35:19

正如我所看到的,设备类中的driver字段是一个对象,而不是集合。它应该是一个Set<Driver>为您的情况。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48248419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档