spring 引导显示 jsp 中的数据不工作

spring boot displaying data in jsp not working

我们正在做一个学校作业,我们创建了一个在线汽车商店,我们想显示数据库中的所有汽车,但我们收到以下错误

There was an unexpected error (type=Internal Server Error, status=500).
/views/order.jsp (line: [74], column: [12]) [${orders.package}] contains invalid expression(s): [javax.el.ELException: Failed to parse the expression [${orders.package}]]
org.apache.jasper.JasperException: /views/order.jsp (line: [74], column: [12]) [${orders.package}] contains invalid expression(s): [javax.el.ELException: Failed to parse the expression [${orders.package}]]

显示列表内容的jsp文件

<tabel>
    <tr>
        <th>price</th>
        <th>package</th>
        <th>category</th>
    </tr>
        <c:forEach items="${order}" var="orders">
    <tr>
        <td><c:out value="${orders.price}"/></td>
        <td><c:out value="${orders.package}"/></td>
        <td><c:out value="${orders.category}"/></td>
    </tr>
    </c:forEach>
</table>

从数据库中获取数据并将其提供给模型的控制器

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */

package com.autoszalon.auto.application.controller;

import com.autoszalon.auto.application.domains.User;
import com.autoszalon.auto.application.service.vehicleservice;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;



/**
 *
 * @author Nagy
 */


@Controller
public class vehiclecontroller {
    
    @Autowired
    
    private vehicleservice vehicleservice;
    
   @GetMapping("order")
    
    public String listVehicle(Model jarmumodel){
        
        List<vehiclefinddto> carlist = new ArrayList<>();
        
        vehicleservice.findAllVeichle().forEach(h 
                -> carlist.add(new vehiclefinddto(h.getPrice(), h.getCarpackage(), h.getCategory()))
        );
      jarmumodel.addAttribute("order", carlist);
     
      return "order";
      }
    @PostMapping("orderfilter")
    public String vehichle(vehichledtotemp vehichledto ){
        vehicleservice.transfertovehichlefinddto(vehichledto);
        
    return "order";
    }
    
    }
    

控制器的服务

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.autoszalon.auto.application.service;

import com.autoszalon.auto.application.controller.vehichledtotemp;
import com.autoszalon.auto.application.controller.vehiclefinddto;
import com.autoszalon.auto.application.domains.Carpackage;
import com.autoszalon.auto.application.domains.Veichle;
import com.autoszalon.auto.application.repositorys.Veichlerepository;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Nagy
 */
@Service
public class vehicleservice {
    @Autowired
    public Veichlerepository vehiclerepo;
    
        public Iterable<Veichle> findAllVeichle() {
        return vehiclerepo.findAll();
    }
        public Iterable<Veichle> findAllBycarpackage(Carpackage carpackage){
            return (Iterable<Veichle>) vehiclerepo.findAllBycarpackage(carpackage);
        }
        public vehiclefinddto transfertovehichlefinddto(vehichledtotemp vehdtotemp){
            vehiclefinddto vfinddto = new vehiclefinddto(vehdtotemp.getDoors(),vehdtotemp.getCarpackage(), vehdtotemp.getCategory(), vehdtotemp.getColor(), vehdtotemp.isAllwheels(), (int) vehdtotemp.getPrice());
            return vfinddto;
        }
        public Iterable<Veichle> findAlLbycolor(String color) {
            return vehiclerepo.findcarsbycolor(color);
        }
      
            public Iterable<Veichle> findAlLbyall(boolean Allwheel, float price,int doors, String color) {
        return vehiclerepo.findcarsbyAll(Allwheel, price, doors, color);
    }
            
        }


```
this is the data transfer object 
```

/**
 *
 * @author Nagy
 */
public class vehiclefinddto {
    private final float price;
    private final Carpackage carpackage;
   // private final String color;
  //  private final int doors;
    private final Categoryenum category;
   //private final boolean Allwheels;

    public vehiclefinddto(float price, Carpackage carpackage, Categoryenum category) {
        this.price = price;
        this.carpackage = carpackage;
        this.category = category;
    }

    public vehiclefinddto(int doors, Carpackage carpackage, Categoryenum category, String color, boolean allwheels, int i) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public float getPrice() {
        return price;
    }

    public Carpackage getCarpackage() {
        return carpackage;
    }
/*
    public String getColor() {
        return color;
    }

    public int getDoors() {
        return doors;
    }
*/
    public Categoryenum getCategory() {
        return category;
    }
/*
    public boolean isAllwheels() {
        return Allwheels;
    }
    */
    
    
    
}


```

您试图在 JSP 中引用错误的变量。

是拼车不是包裹。所以尝试使用这个变量。

value="${orders.carpackage}"

以上内容将解决您的问题,但除此之外,我会要求您遵循正确的命名约定。 Class 名称应为驼峰式,foreach 项目应为复数,每个项目应为单数等