spring boot jsp c:set无法与无类型原始值一起使用

时间:2018-10-24 07:45:31

标签: jsp spring-boot jstl

我正在尝试使我的Web应用程序正常工作。但是我的jsp中的对象修复存在问题。这是对象:

@Entity
public class Reparation implements Serializable {

   @EmbeddedId  
   private ReparationMId idRM;
   private int idClient;
   private String nomc;
   private String prenomc;
   private String probleme;
   private Timestamp dateDepot;
   private float prixPrevu;
   private int idEtat;
   private String etat;
   private float prixFinal;
   private Timestamp datePrevu;
   private Timestamp dateLivraison;
   private int idPersonnel;
   private String nomp;
   private String prenomp;
   private String magasin;
   private int produitClient;

   @OneToOne
   @JoinColumn(name = "idMagasin", insertable=false, updatable=false)
    Magasin magasinPoint;

   public ReparationMId getId(){
       return this.idRM;
   }

这是ReparationMId我的jsp问题:

@Embeddable
public class ReparationMId implements Serializable{
     @Column(name="id")
   Integer idReparation;
  @Column(name="idMagasin")
   Integer idMagasin;

   //implements equals and hashCode
   public Integer getIdReparation(){
       return this.idReparation;
   }

   public Integer getIdMagasin(){
       return this.idMagasin;
   }...

在我的jsp中,我无法访问idRM来获取idReparation:

<table align="center" ="3">
        <tr><th>Client</th><th>Probleme</th><th>Date dépôt</th><th>Prix prévu</th><th>etat</th><th>Pieces utilisés</th></tr>
        <c:forEach items="${reparations}" var="reparation">
        <tr>

            <td><c:out value="${reparation.nomc}"/>
            <c:out value="${reparation.prenomc}"/></td>
            <td><c:out value="${reparation.probleme}"/></td>
            <td><c:out value="${reparation.prixPrevu}"/></td>
            <td><c:out value="${reparation.etat}"/><td>
            <c:set var="rmID" scope="page" value="${reparation.idRM}"/>
            <td></td>

        </tr>
        </c:forEach>
        </table>

您会看到c:set无法使用idClient这样的基本类型,但不能使用ReparationMId类型的idRM。如何实现呢?

错误:

  

发生意外错误(类型=内部服务器错误,   状态= 500)。处理JSP页面时发生异常   [/WEB-INF/view/reparation.jsp]在第[83]行80:81:82:83:84:85:86:    堆栈跟踪:

谢谢。

编辑:页面JSP的顶部

<!doctype html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Lato|Playfair+Display|Catamaran" rel="stylesheet"> 
    <title>Commandes station phone 
    </title>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
</head>
<body>

    <header>            
                    <!-- Masquée sur smartphones, taille 2 sur tablettes et plus -->

                    <nav class="navbar navbar-expand-lg navbar-light bg-light barimg">
                        <div class="container-fluid">
                        <div class="navbar-header">

                        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                         <span class="navbar-toggler-icon"></span>
                        </button>
                        <a class="navbar-brand" href="index.html"><img src="../images/logo.png" alt="" class="logo"></a>

编辑2:POM.XML

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.stationphone</groupId>
    <artifactId>db</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>WebServiceStationPhone</name>
    <description>Demo project for Spring Boot</description>

        <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

        <dependencies>
                <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-data-jpa</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-entitymanager</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-orm</artifactId>
                </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.restdocs</groupId>
            <artifactId>spring-restdocs-mockmvc</artifactId>
            <scope>test</scope>
        </dependency>
                <dependency>
                    <groupId>javax.xml.bind</groupId>
                    <artifactId>jaxb-api</artifactId>
                    <version>2.3.0</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                    <version>2.5</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>jstl</artifactId>
                  <version>1.2</version>
                </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

项目结构:

enter image description here

enter image description here 数据库:

1 个答案:

答案 0 :(得分:0)

那么简单 我的类Reparation的获取者是getId()而不是getIdRM()。 当您不知道有什么问题时,很高兴知道这一点。 感谢Avijit Barua的帮助。