Spring MVC + SPRING DATA JPA:无法使用 jstl 从 jsp 中的可联合实体读取 属性
Spring MVC + SPRING DATA JPA: unable to read property from jointable entity in jsp using jstl
我在持久层使用 spring mvc 和 spring data jpa 开发 liferay 7 portlet。
数据保存在专用数据库中。
我的pom
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.realt</groupId>
<artifactId>trasparenza</artifactId>
<packaging>war</packaging>
<name>trasparenza Portlet</name>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<liferay.impl.version>2.3.0</liferay.impl.version> <!-- liferay kernel & implementation are different than liferay version starting from liferay 7 -->
<spring.version>4.3.6.RELEASE</spring.version>
<hibernate-validator-version>5.3.0.Final</hibernate-validator-version>
<servlet.version>3.1.0</servlet.version>
<portlet.version>2.0</portlet.version>
</properties>
<profiles>
<profile>
<id>internal-profile</id>
<properties>
<liferay.version>7.0-ga3</liferay.version>
<liferay.maven.plugin.version>7.0-ga3</liferay.maven.plugin.version>
<liferay.auto.deploy.dir>c:/liferay-ce-portal-7.0-ga3/deploy</liferay.auto.deploy.dir>
<liferay.app.server.deploy.dir>c:/liferay-ce-portal-7.0-ga3/tomcat-8.0.32/webapps</liferay.app.server.deploy.dir>
<liferay.app.server.lib.global.dir>c:/liferay-ce-portal-7.0-ga3/tomcat-8.0.32/lib/ext</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>c:/liferay-ce-portal-7.0-ga3/tomcat-8.0.32/webapps/ROOT</liferay.app.server.portal.dir>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Ingalls-RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- liferay 7 -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.impl</artifactId>
<version>${liferay.impl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>${liferay.impl.version}</version>
<scope>provided</scope>
</dependency>
<!-- Servlet and JSR -->
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>${portlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>-->
<!-- spring data jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.RELEASE</version>
</dependency>
<!-- JPA Provider (Hibernate) -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.6.Final</version>
</dependency>
<!-- DataSource (HikariCP) -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- end spring data jpa -->
<!-- thymeleaf and dialects -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212.jre7</version>
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava-collections -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-collections</artifactId>
<version>r03</version>
</dependency>
</dependencies>
<build>
<finalName>trasparenza</finalName>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>7.0.0-m2</version>
<!--
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>build-css</goal>
</goals>
</execution>
</executions>
-->
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginType>portlet</pluginType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.6</version>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
我与连接中的额外列存在多对多关系 table。
实体 A
@Entity
@Table(name = "procedimento")
public class Procedimento {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "procedimento_seq")
@SequenceGenerator(name = "procedimento_seq", sequenceName = "procedimento_id_seq", allocationSize = 1)
private Integer id;
@OneToMany(mappedBy = "procedimento", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ProcedimentoAzienda> aziendeProcedimento;
@Transient
private List<ProcedimentoAzienda> elencoRTIAziendeAggiudicatarie;
@Transient
private List<ProcedimentoAzienda> elencoAziende;
@Transient
private List<List<ProcedimentoAzienda>> elencoRTIAziendePartecipanti;
@Transient
private ProcedimentoAzienda aziendaAggiudicataria;
@OneToMany(mappedBy="procedimento", fetch = FetchType.LAZY)
private List<ProcedimentoImporti> elencoImporti = new ArrayList<ProcedimentoImporti>();
@Transient
private Double totaleImportoPagato = 0d;
...... getter and setter
}
实体 B
@Entity
@Table(name = "aziende")
public class Azienda {
public final static String SESSO_MASCHIO = "M";
public final static String SESSO_FEMMINA = "F";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "azienda_seq")
@SequenceGenerator(name = "azienda_seq", sequenceName = "azienda_id_seq", allocationSize = 1)
private Integer id;
@Column(name = "ragione_sociale")
private String ragioneSociale;
@Column(name = "codice_fiscale")
private String codiceFiscale;
@Column(name = "identificativo_estero")
private String identificativoEstero;
@Column(name = "partita_iva")
private String partitaIva;
.....getter and setter
}
实体映射连接table
@Entity
@Table(name = "procedimento_azienda")
class ProcedimentoAzienda implements Serializable{
@Id
@ManyToOne
@JoinColumn(name = "procedimento_id")
private Procedimento procedimento;
@Id
@ManyToOne
@JoinColumn(name = "azienda_id")
private Azienda azienda;
@Column(name = "cig")
private String cig;
@Column(name = "n_ragg")
private Integer nRagg;
@Column(name = "ruolo_ragg")
private String ruoloRagg;
@Column(name = "aggiudicatario")
private boolean aggiudicatario;
.....getter and setter
}
在我的 jsp 我有
.......
<td>
<c:if test="${null != item.aziendaAggiudicataria}" >
${item.aziendaAggiudicataria.azienda.ragioneSociale}
</c:if>
<c:if test="${null != item.elencoRTIAziendeAggiudicatarie}">
<c:forEach items="${item.elencoRTIAziendeAggiudicatarie}" var="item2" >
– ${item2.azienda.ragioneSociale}
</c:forEach>
</c:if>
</td>
.......
执行时出现错误
09:10:05,404 ERROR [http-nio-8080-exec-9][PortletRequestDispatcherImpl:261] javax.servlet.ServletException: javax.el.PropertyNotFoundException: The class 'it.realt.trasparenza.services.procedimenti.ProcedimentoAzienda' does not have a readable property 'azienda'.
javax.servlet.ServletException: javax.el.PropertyNotFoundException: The class 'it.realt.trasparenza.services.procedimenti.ProcedimentoAzienda' does not have a readable property 'azienda'.
我在尝试访问 jointable 实体中的每个 属性 时遇到错误。
我的实现有什么问题?
提前致谢
已解决....我没看到我忘记了 ProcedimentoAzienda class
中的 "public"
我在持久层使用 spring mvc 和 spring data jpa 开发 liferay 7 portlet。 数据保存在专用数据库中。
我的pom
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.realt</groupId>
<artifactId>trasparenza</artifactId>
<packaging>war</packaging>
<name>trasparenza Portlet</name>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<liferay.impl.version>2.3.0</liferay.impl.version> <!-- liferay kernel & implementation are different than liferay version starting from liferay 7 -->
<spring.version>4.3.6.RELEASE</spring.version>
<hibernate-validator-version>5.3.0.Final</hibernate-validator-version>
<servlet.version>3.1.0</servlet.version>
<portlet.version>2.0</portlet.version>
</properties>
<profiles>
<profile>
<id>internal-profile</id>
<properties>
<liferay.version>7.0-ga3</liferay.version>
<liferay.maven.plugin.version>7.0-ga3</liferay.maven.plugin.version>
<liferay.auto.deploy.dir>c:/liferay-ce-portal-7.0-ga3/deploy</liferay.auto.deploy.dir>
<liferay.app.server.deploy.dir>c:/liferay-ce-portal-7.0-ga3/tomcat-8.0.32/webapps</liferay.app.server.deploy.dir>
<liferay.app.server.lib.global.dir>c:/liferay-ce-portal-7.0-ga3/tomcat-8.0.32/lib/ext</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>c:/liferay-ce-portal-7.0-ga3/tomcat-8.0.32/webapps/ROOT</liferay.app.server.portal.dir>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Ingalls-RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- liferay 7 -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.impl</artifactId>
<version>${liferay.impl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>${liferay.impl.version}</version>
<scope>provided</scope>
</dependency>
<!-- Servlet and JSR -->
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>${portlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>-->
<!-- spring data jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.RELEASE</version>
</dependency>
<!-- JPA Provider (Hibernate) -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.6.Final</version>
</dependency>
<!-- DataSource (HikariCP) -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- end spring data jpa -->
<!-- thymeleaf and dialects -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212.jre7</version>
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava-collections -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-collections</artifactId>
<version>r03</version>
</dependency>
</dependencies>
<build>
<finalName>trasparenza</finalName>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>7.0.0-m2</version>
<!--
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>build-css</goal>
</goals>
</execution>
</executions>
-->
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginType>portlet</pluginType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.6</version>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
我与连接中的额外列存在多对多关系 table。
实体 A
@Entity
@Table(name = "procedimento")
public class Procedimento {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "procedimento_seq")
@SequenceGenerator(name = "procedimento_seq", sequenceName = "procedimento_id_seq", allocationSize = 1)
private Integer id;
@OneToMany(mappedBy = "procedimento", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ProcedimentoAzienda> aziendeProcedimento;
@Transient
private List<ProcedimentoAzienda> elencoRTIAziendeAggiudicatarie;
@Transient
private List<ProcedimentoAzienda> elencoAziende;
@Transient
private List<List<ProcedimentoAzienda>> elencoRTIAziendePartecipanti;
@Transient
private ProcedimentoAzienda aziendaAggiudicataria;
@OneToMany(mappedBy="procedimento", fetch = FetchType.LAZY)
private List<ProcedimentoImporti> elencoImporti = new ArrayList<ProcedimentoImporti>();
@Transient
private Double totaleImportoPagato = 0d;
...... getter and setter
}
实体 B
@Entity
@Table(name = "aziende")
public class Azienda {
public final static String SESSO_MASCHIO = "M";
public final static String SESSO_FEMMINA = "F";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "azienda_seq")
@SequenceGenerator(name = "azienda_seq", sequenceName = "azienda_id_seq", allocationSize = 1)
private Integer id;
@Column(name = "ragione_sociale")
private String ragioneSociale;
@Column(name = "codice_fiscale")
private String codiceFiscale;
@Column(name = "identificativo_estero")
private String identificativoEstero;
@Column(name = "partita_iva")
private String partitaIva;
.....getter and setter
}
实体映射连接table
@Entity
@Table(name = "procedimento_azienda")
class ProcedimentoAzienda implements Serializable{
@Id
@ManyToOne
@JoinColumn(name = "procedimento_id")
private Procedimento procedimento;
@Id
@ManyToOne
@JoinColumn(name = "azienda_id")
private Azienda azienda;
@Column(name = "cig")
private String cig;
@Column(name = "n_ragg")
private Integer nRagg;
@Column(name = "ruolo_ragg")
private String ruoloRagg;
@Column(name = "aggiudicatario")
private boolean aggiudicatario;
.....getter and setter
}
在我的 jsp 我有
.......
<td>
<c:if test="${null != item.aziendaAggiudicataria}" >
${item.aziendaAggiudicataria.azienda.ragioneSociale}
</c:if>
<c:if test="${null != item.elencoRTIAziendeAggiudicatarie}">
<c:forEach items="${item.elencoRTIAziendeAggiudicatarie}" var="item2" >
– ${item2.azienda.ragioneSociale}
</c:forEach>
</c:if>
</td>
.......
执行时出现错误
09:10:05,404 ERROR [http-nio-8080-exec-9][PortletRequestDispatcherImpl:261] javax.servlet.ServletException: javax.el.PropertyNotFoundException: The class 'it.realt.trasparenza.services.procedimenti.ProcedimentoAzienda' does not have a readable property 'azienda'.
javax.servlet.ServletException: javax.el.PropertyNotFoundException: The class 'it.realt.trasparenza.services.procedimenti.ProcedimentoAzienda' does not have a readable property 'azienda'.
我在尝试访问 jointable 实体中的每个 属性 时遇到错误。
我的实现有什么问题?
提前致谢
已解决....我没看到我忘记了 ProcedimentoAzienda class
中的 "public"