Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解决;“计算SpringEL表达式的异常”;春天的靴子?_Java_Spring_Thymeleaf - Fatal编程技术网

Java 如何解决;“计算SpringEL表达式的异常”;春天的靴子?

Java 如何解决;“计算SpringEL表达式的异常”;春天的靴子?,java,spring,thymeleaf,Java,Spring,Thymeleaf,我在Spring boot应用程序中使用Microsoft SQL。我已经解决了所有问题,现在我正在尝试将数据从SQL数据库传递到前端。但是,当我通过thymeleaf传递信息时,它不起作用。我有一个应用程序存储库和一个DTO类,它们实际传递数据。尽管我一直在犯同样的错误。很抱歉用这么多代码轰炸每个人,但我一直在试图找到一个解决方案,但仍然想不出解决方法。我相信这与TestApp类有关,但不确定在哪里 错误: org.springframework.expression.spel.Sp

我在Spring boot应用程序中使用Microsoft SQL。我已经解决了所有问题,现在我正在尝试将数据从SQL数据库传递到前端。但是,当我通过
thymeleaf
传递信息时,它不起作用。我有一个应用程序存储库和一个DTO类,它们实际传递数据。尽管我一直在犯同样的错误。很抱歉用这么多代码轰炸每个人,但我一直在试图找到一个解决方案,但仍然想不出解决方法。我相信这与TestApp类有关,但不确定在哪里

错误:


    org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'dtoTiername' cannot be found on object of type 'com.John.model.TestApp' - maybe not public or not valid?

        @Query("SELECT new com.John.model.TestApp(t.tiername, t.system) FROM AppSelectorTier t")
        List<TestApp>getServerInfo();



    public List<TestApp> getServerInfo() {
                List<TestApp> myList = appRepository.getServerInfo();
                System.out.println(myList.size());
                return myList;
            }

        @RequestMapping("/edit")
        public ModelAndView editTab(Model model) {

            ModelAndView modelAndView = new ModelAndView();
            List<TestApp>ary4 = new ArrayList<TestApp>();
            try {
                System.out.println("Hello Code");
                ary4 = joinQueryService.getServerInfo();
                modelAndView.setViewName("create");             

            } catch (Exception e) {
                e.printStackTrace();
                modelAndView.setViewName("test");           
            }
            modelAndView.addObject("ary4",ary4);
            return modelAndView;                                
        }


    <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                      <th>Tiername</th>
                      <th>System</th>
                    </tr>
                </thead>

                 <tbody>
                    <tr th:each="ary4 : ${ary4}">
                        <td th:text="${ary4.dtoTiername}"></td>
                        <td th:text="${ary4.dtoSystem}"></td>
                    </tr>
                </tbody>

               </table>

package com.John.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

public class TestApp implements java.io.Serializable  {

    private String dtoTiername;
    private String dtoSystem;

    private static final long serialVersionUID = 1L;


    //Constructor
    public TestApp(String dtoTiername, String dtoSystem) {
        super();
        this.dtoTiername = dtoTiername;
        this.dtoSystem = dtoSystem;
    }

    //Default Constructor
    public TestApp() {

    }



    //Getter
    public String getName() {
        return dtoTiername;
    }

    public String getSystem() {
        return dtoSystem;
    }


    //Setter
    public void setName(String dtoTiername) {
        this.dtoTiername = dtoTiername;
    }


    public void setSystem(String dtoSystem) {
        this.dtoSystem = dtoSystem;
    }

}

package com.John.model;

import java.util.*;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tier")
public class AppSelectorTier implements java.io.Serializable {

    @Id
    @Column(name = "tiername")
    private String tiername;

    @Column(name = "system")
    private String system;

    private static final long serialVersionUID = 1L;


    //Constructor
    public AppSelectorTier(String tiername, String system) {
        super();
        this.tiername = tiername;
        this.system = system;
    }

    //Default Constructor
    public AppSelectorTier() {

    }



    //Getter
    public String getName() {
        return tiername;
    }

    public String getSystem() {
        return system;
    }


    //Setter
    public void setName(String tiername) {
        this.tiername = tiername;
    }


    public void setSystem(String system) {
        this.system = system;
    }

}

应用程序存储库:


    org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'dtoTiername' cannot be found on object of type 'com.John.model.TestApp' - maybe not public or not valid?

        @Query("SELECT new com.John.model.TestApp(t.tiername, t.system) FROM AppSelectorTier t")
        List<TestApp>getServerInfo();



    public List<TestApp> getServerInfo() {
                List<TestApp> myList = appRepository.getServerInfo();
                System.out.println(myList.size());
                return myList;
            }

        @RequestMapping("/edit")
        public ModelAndView editTab(Model model) {

            ModelAndView modelAndView = new ModelAndView();
            List<TestApp>ary4 = new ArrayList<TestApp>();
            try {
                System.out.println("Hello Code");
                ary4 = joinQueryService.getServerInfo();
                modelAndView.setViewName("create");             

            } catch (Exception e) {
                e.printStackTrace();
                modelAndView.setViewName("test");           
            }
            modelAndView.addObject("ary4",ary4);
            return modelAndView;                                
        }


    <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                      <th>Tiername</th>
                      <th>System</th>
                    </tr>
                </thead>

                 <tbody>
                    <tr th:each="ary4 : ${ary4}">
                        <td th:text="${ary4.dtoTiername}"></td>
                        <td th:text="${ary4.dtoSystem}"></td>
                    </tr>
                </tbody>

               </table>

package com.John.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

public class TestApp implements java.io.Serializable  {

    private String dtoTiername;
    private String dtoSystem;

    private static final long serialVersionUID = 1L;


    //Constructor
    public TestApp(String dtoTiername, String dtoSystem) {
        super();
        this.dtoTiername = dtoTiername;
        this.dtoSystem = dtoSystem;
    }

    //Default Constructor
    public TestApp() {

    }



    //Getter
    public String getName() {
        return dtoTiername;
    }

    public String getSystem() {
        return dtoSystem;
    }


    //Setter
    public void setName(String dtoTiername) {
        this.dtoTiername = dtoTiername;
    }


    public void setSystem(String dtoSystem) {
        this.dtoSystem = dtoSystem;
    }

}

package com.John.model;

import java.util.*;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tier")
public class AppSelectorTier implements java.io.Serializable {

    @Id
    @Column(name = "tiername")
    private String tiername;

    @Column(name = "system")
    private String system;

    private static final long serialVersionUID = 1L;


    //Constructor
    public AppSelectorTier(String tiername, String system) {
        super();
        this.tiername = tiername;
        this.system = system;
    }

    //Default Constructor
    public AppSelectorTier() {

    }



    //Getter
    public String getName() {
        return tiername;
    }

    public String getSystem() {
        return system;
    }


    //Setter
    public void setName(String tiername) {
        this.tiername = tiername;
    }


    public void setSystem(String system) {
        this.system = system;
    }

}

实体:


    org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'dtoTiername' cannot be found on object of type 'com.John.model.TestApp' - maybe not public or not valid?

        @Query("SELECT new com.John.model.TestApp(t.tiername, t.system) FROM AppSelectorTier t")
        List<TestApp>getServerInfo();



    public List<TestApp> getServerInfo() {
                List<TestApp> myList = appRepository.getServerInfo();
                System.out.println(myList.size());
                return myList;
            }

        @RequestMapping("/edit")
        public ModelAndView editTab(Model model) {

            ModelAndView modelAndView = new ModelAndView();
            List<TestApp>ary4 = new ArrayList<TestApp>();
            try {
                System.out.println("Hello Code");
                ary4 = joinQueryService.getServerInfo();
                modelAndView.setViewName("create");             

            } catch (Exception e) {
                e.printStackTrace();
                modelAndView.setViewName("test");           
            }
            modelAndView.addObject("ary4",ary4);
            return modelAndView;                                
        }


    <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                      <th>Tiername</th>
                      <th>System</th>
                    </tr>
                </thead>

                 <tbody>
                    <tr th:each="ary4 : ${ary4}">
                        <td th:text="${ary4.dtoTiername}"></td>
                        <td th:text="${ary4.dtoSystem}"></td>
                    </tr>
                </tbody>

               </table>

package com.John.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

public class TestApp implements java.io.Serializable  {

    private String dtoTiername;
    private String dtoSystem;

    private static final long serialVersionUID = 1L;


    //Constructor
    public TestApp(String dtoTiername, String dtoSystem) {
        super();
        this.dtoTiername = dtoTiername;
        this.dtoSystem = dtoSystem;
    }

    //Default Constructor
    public TestApp() {

    }



    //Getter
    public String getName() {
        return dtoTiername;
    }

    public String getSystem() {
        return dtoSystem;
    }


    //Setter
    public void setName(String dtoTiername) {
        this.dtoTiername = dtoTiername;
    }


    public void setSystem(String dtoSystem) {
        this.dtoSystem = dtoSystem;
    }

}

package com.John.model;

import java.util.*;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tier")
public class AppSelectorTier implements java.io.Serializable {

    @Id
    @Column(name = "tiername")
    private String tiername;

    @Column(name = "system")
    private String system;

    private static final long serialVersionUID = 1L;


    //Constructor
    public AppSelectorTier(String tiername, String system) {
        super();
        this.tiername = tiername;
        this.system = system;
    }

    //Default Constructor
    public AppSelectorTier() {

    }



    //Getter
    public String getName() {
        return tiername;
    }

    public String getSystem() {
        return system;
    }


    //Setter
    public void setName(String tiername) {
        this.tiername = tiername;
    }


    public void setSystem(String system) {
        this.system = system;
    }

}


属性由getter和setter映射,因此您可以执行以下任一操作

第一名:


    org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'dtoTiername' cannot be found on object of type 'com.John.model.TestApp' - maybe not public or not valid?

        @Query("SELECT new com.John.model.TestApp(t.tiername, t.system) FROM AppSelectorTier t")
        List<TestApp>getServerInfo();



    public List<TestApp> getServerInfo() {
                List<TestApp> myList = appRepository.getServerInfo();
                System.out.println(myList.size());
                return myList;
            }

        @RequestMapping("/edit")
        public ModelAndView editTab(Model model) {

            ModelAndView modelAndView = new ModelAndView();
            List<TestApp>ary4 = new ArrayList<TestApp>();
            try {
                System.out.println("Hello Code");
                ary4 = joinQueryService.getServerInfo();
                modelAndView.setViewName("create");             

            } catch (Exception e) {
                e.printStackTrace();
                modelAndView.setViewName("test");           
            }
            modelAndView.addObject("ary4",ary4);
            return modelAndView;                                
        }


    <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                      <th>Tiername</th>
                      <th>System</th>
                    </tr>
                </thead>

                 <tbody>
                    <tr th:each="ary4 : ${ary4}">
                        <td th:text="${ary4.dtoTiername}"></td>
                        <td th:text="${ary4.dtoSystem}"></td>
                    </tr>
                </tbody>

               </table>

package com.John.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

public class TestApp implements java.io.Serializable  {

    private String dtoTiername;
    private String dtoSystem;

    private static final long serialVersionUID = 1L;


    //Constructor
    public TestApp(String dtoTiername, String dtoSystem) {
        super();
        this.dtoTiername = dtoTiername;
        this.dtoSystem = dtoSystem;
    }

    //Default Constructor
    public TestApp() {

    }



    //Getter
    public String getName() {
        return dtoTiername;
    }

    public String getSystem() {
        return dtoSystem;
    }


    //Setter
    public void setName(String dtoTiername) {
        this.dtoTiername = dtoTiername;
    }


    public void setSystem(String dtoSystem) {
        this.dtoSystem = dtoSystem;
    }

}

package com.John.model;

import java.util.*;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tier")
public class AppSelectorTier implements java.io.Serializable {

    @Id
    @Column(name = "tiername")
    private String tiername;

    @Column(name = "system")
    private String system;

    private static final long serialVersionUID = 1L;


    //Constructor
    public AppSelectorTier(String tiername, String system) {
        super();
        this.tiername = tiername;
        this.system = system;
    }

    //Default Constructor
    public AppSelectorTier() {

    }



    //Getter
    public String getName() {
        return tiername;
    }

    public String getSystem() {
        return system;
    }


    //Setter
    public void setName(String tiername) {
        this.tiername = tiername;
    }


    public void setSystem(String system) {
        this.system = system;
    }

}

保持getter setter与变量名对齐

public class TestApp implements java.io.Serializable  {

    private String dtoTiername;
    private String dtoSystem;

    public String getDtoTiername() {
        return dtoTiername;
    }
    public void setDtoTiername(String dtoTiername) {
        this.dtoTiername = dtoTiername;
    }
    public String getDtoSystem() {
        return dtoSystem;
    }
    public void setDtoSystem(String dtoSystem) {
        this.dtoSystem = dtoSystem;
    }

}
秒:


    org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'dtoTiername' cannot be found on object of type 'com.John.model.TestApp' - maybe not public or not valid?

        @Query("SELECT new com.John.model.TestApp(t.tiername, t.system) FROM AppSelectorTier t")
        List<TestApp>getServerInfo();



    public List<TestApp> getServerInfo() {
                List<TestApp> myList = appRepository.getServerInfo();
                System.out.println(myList.size());
                return myList;
            }

        @RequestMapping("/edit")
        public ModelAndView editTab(Model model) {

            ModelAndView modelAndView = new ModelAndView();
            List<TestApp>ary4 = new ArrayList<TestApp>();
            try {
                System.out.println("Hello Code");
                ary4 = joinQueryService.getServerInfo();
                modelAndView.setViewName("create");             

            } catch (Exception e) {
                e.printStackTrace();
                modelAndView.setViewName("test");           
            }
            modelAndView.addObject("ary4",ary4);
            return modelAndView;                                
        }


    <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                      <th>Tiername</th>
                      <th>System</th>
                    </tr>
                </thead>

                 <tbody>
                    <tr th:each="ary4 : ${ary4}">
                        <td th:text="${ary4.dtoTiername}"></td>
                        <td th:text="${ary4.dtoSystem}"></td>
                    </tr>
                </tbody>

               </table>

package com.John.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

public class TestApp implements java.io.Serializable  {

    private String dtoTiername;
    private String dtoSystem;

    private static final long serialVersionUID = 1L;


    //Constructor
    public TestApp(String dtoTiername, String dtoSystem) {
        super();
        this.dtoTiername = dtoTiername;
        this.dtoSystem = dtoSystem;
    }

    //Default Constructor
    public TestApp() {

    }



    //Getter
    public String getName() {
        return dtoTiername;
    }

    public String getSystem() {
        return dtoSystem;
    }


    //Setter
    public void setName(String dtoTiername) {
        this.dtoTiername = dtoTiername;
    }


    public void setSystem(String dtoSystem) {
        this.dtoSystem = dtoSystem;
    }

}

package com.John.model;

import java.util.*;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tier")
public class AppSelectorTier implements java.io.Serializable {

    @Id
    @Column(name = "tiername")
    private String tiername;

    @Column(name = "system")
    private String system;

    private static final long serialVersionUID = 1L;


    //Constructor
    public AppSelectorTier(String tiername, String system) {
        super();
        this.tiername = tiername;
        this.system = system;
    }

    //Default Constructor
    public AppSelectorTier() {

    }



    //Getter
    public String getName() {
        return tiername;
    }

    public String getSystem() {
        return system;
    }


    //Setter
    public void setName(String tiername) {
        this.tiername = tiername;
    }


    public void setSystem(String system) {
        this.system = system;
    }

}

将JSP变量更改为

<tr th:each="ary4 : ${ary4}">
    <td th:text="${ary4.name}"></td>
    <td th:text="${ary4.system}"></td>
</tr>

您的属性名称是
name
,而不是
dtoTiername
。属性由getter和setter定义,而不是由backing字段定义。