javax.el.PropertyNotFoundException: 在类型[com.project70.Flight]上未找到属性[FlightNo]。

huangapple go评论111阅读模式
英文:

javax.el.PropertyNotFoundException: Property [FlightNo] not found on type [com.project70.Flight]

问题

这是控制器类中的方法,接受模型对象列表:

@RequestMapping("cancel")
public String listTicket(Model m) {
    System.out.println("Inside listTicket method");
    List<Flight> list = fs.listAll();
    m.addAttribute("list", list);
    return "cancelTicket";
}

服务类方法:

public List<Flight> listAll(){
    return repo.findAll();
}

模型类,包含各字段的 getter 和 setter 方法。我已经使用了所有必需的注解,但这里省略了注解 @Entity@Table

public class Flight {
    
    private int id;
    private String FlightNo;
    private String FlightName;
    private String FlightFrom;
    private String FlightTo;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFlightNo() {
        return FlightNo;
    }

    public void setFlightNo(String flightNo) {
        FlightNo = flightNo;
    }

    public String getFlightName() {
        return FlightName;
    }

    public void setFlightName(String flightName) {
        FlightName = flightName;
    }

    public String getFlightFrom() {
        return FlightFrom;
    }

    public void setFlightFrom(String flightFrom) {
        FlightFrom = flightFrom;
    }

    public String getFlightTo() {
        return FlightTo;
    }

    public void setFlightTo(String flightTo) {
        FlightTo = flightTo;
    }
}

JSP 页面脚本:

<c:forEach var="li" items="${list}">
    <tr>
        <td>${li.id}</td>
        <td>${li.FlightNo}</td>
        <td>${li.FlightName}</td>
        <td>${li.FlightFrom}</td>
        <td>${li.FlightTo}</td>
        <td><a href="">Cancel Ticket</a></td>
    </tr>
</c:forEach>

这是错误信息:

javax.el.PropertyNotFoundException: 在类型 [com.cognizant.project70.Flight] 上找不到属性 [FlightNo]
    // ... (以下省略)
英文:

Here is the method inside controller class taking the model object list

@RequestMapping(&quot;cancel&quot;)
public String listTicket(Model m) {
	System.out.println(&quot;Inside listTicket method&quot;);
	List&lt;Flight&gt; list=fs.listAll();
	m.addAttribute(&quot;list&quot;,list);
	return &quot;cancelTicket&quot;;
}

Service class method

public List&lt;Flight&gt; listAll(){
	return repo.findAll();
}

Model class with getters and setters of respective fields.
I have used all the required annoations but haven't posted here, so ignore that
(Annotations omitted: @Entity & @Table)

public class Flight {
	
	private int id;
	private String FlightNo;
	private String FlightName;
	private String FlightFrom;
	private String FlightTo;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFlightNo() {
		return FlightNo;
	}

	public void setFlightNo(String flightNo) {
		FlightNo = flightNo;
	}

	public String getFlightName() {
		return FlightName;
	}

	public void setFlightName(String flightName) {
		FlightName = flightName;
	}

	public String getFlightFrom() {
		return FlightFrom;
	}

	public void setFlightFrom(String flightFrom) {
		FlightFrom = flightFrom;
	}

	public String getFlightTo() {
		return FlightTo;
	}

	public void setFlightTo(String flightTo) {
		FlightTo = flightTo;
	}

}

JSP page scriptlet

	&lt;c:forEach var=&quot;li&quot; items=&quot;${list}&quot;&gt;
		&lt;tr&gt;
			&lt;td&gt;${li.id}&lt;/td&gt;
			&lt;td&gt;${li.FlightNo}&lt;/td&gt;
			&lt;td&gt;${li.FlightName}&lt;/td&gt;
			&lt;td&gt;${li.FlightFrom}&lt;/td&gt;
			&lt;td&gt;${li.FlightTo}&lt;/td&gt;
			&lt;td&gt;&lt;a href=&quot;&quot;&gt;Cancel Ticket&lt;/a&gt;&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/c:forEach&gt;

Here is the error

javax.el.PropertyNotFoundException: Property [FlightNo] not found on type [com.cognizant.project70.Flight]
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:260) ~[tomcat-el-api-9.0.37.jar:3.0.FR]
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:212) ~[tomcat-el-api-9.0.37.jar:3.0.FR]
at javax.el.BeanELResolver.property(BeanELResolver.java:333) ~[tomcat-el-api-9.0.37.jar:3.0.FR]
at javax.el.BeanELResolver.getValue(BeanELResolver.java:92) ~[tomcat-el-api-9.0.37.jar:3.0.FR]
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:125) ~[tomcat-jasper-9.0.37.jar:9.0.37]
at org.apache.el.parser.AstValue.getValue(AstValue.java:169) ~[tomcat-jasper-el-9.0.37.jar:9.0.37]
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190) ~[tomcat-jasper-el-9.0.37.jar:9.0.37]
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:701) ~[tomcat-jasper-9.0.37.jar:9.0.37]
at org.apache.jsp.pages.cancelTicket_jsp._jspx_meth_c_005fforEach_005f0(cancelTicket_jsp.java:202) ~[na:na]
at org.apache.jsp.pages.cancelTicket_jsp._jspService(cancelTicket_jsp.java:150) ~[na:na]
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71) ~[tomcat-jasper-9.0.37.jar:9.0.37]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-servlet-api-9.0.37.jar:4.0.FR]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) ~[tomcat-jasper-9.0.37.jar:9.0.37]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) ~[tomcat-jasper-9.0.37.jar:9.0.37]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) ~[tomcat-jasper-9.0.37.jar:9.0.37]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-servlet-api-9.0.37.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:113) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:113) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:113) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-servlet-api-9.0.37.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-servlet-api-9.0.37.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-util-9.0.37.jar:9.0.37]
at java.base/java.lang.Thread.run(Thread.java:835) ~[na:na]

答案1

得分: -1

我相信 FlightNo 和其他字段访问器不符合 JavaBean 命名约定,这就是为什么会抛出异常的原因。它们应该如下所示:

对于所有变量,请使用驼峰命名模式,如下所示。

在模型类和视图页面中将字段更改为 flightNo、flightName 等,将第一个字母改为小写。

然后生成公共的 getters 和 setters。

英文:

I believe the FlightNo and other field accessors don't match the bean naming conventions and that's why the exception is thrown. They should be as follows:

Use camel case pattern for all the variables like below.

Change fields to flightNo,flightName etc in model class and view page. By making first letter lowercase.

And then generate public getters and setters.

huangapple
  • 本文由 发表于 2020年8月23日 02:12:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63539549.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定