gpt4 book ai didi

java - if-else 语句无法正常工作

转载 作者:行者123 更新时间:2023-11-30 02:53:04 37 4
gpt4 key购买 nike

我的网站就像这样。在此页面中,我尝试在两个单独的表中检索已回答和未回答的问题。但在输出中,我在“已回答的问题”表中显示已回答和未回答的问题。这里出了什么问题?我感谢所有的帮助和努力。这是我的代码:-

<%@page import="model.QuestionBean"%>
<%@page import="java.util.List"%>
<%@page import="model.QuestionDAO"%>
<%@page import="model.QuestionDAOFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Questions</title>
</head>
<body>
<div>



<%
QuestionDAOFactory qdf=new QuestionDAOFactory();
QuestionDAO qd=qdf.createQuestionDAO();
List<QuestionBean> list=qd.getQuestions();
for (QuestionBean qb : list) {
%>

<%
if(qb.getIsAnswered().equalsIgnoreCase("Y"))
%>
<table style="width: 50%;height: 100%;border: 1px solid black;" align="">
<thead>
<tr>
<th>Answered Questions</th>
</tr>
</thead>
<tbody>
<%
{
%>
<tr><td><a href="viewQuestion.jsp?id=<%=qb.getQuestionId() %>"><%=qb.getQuestionText() %></a></td></tr>
<%
}
%>
</tbody>
</table>
<%
else
%>
<table style="width: 50%;height: 100%;border: 1px solid black;" align="">
<thead>
<tr>
<th>Unanswered Questions</th>
</tr>
</thead>
<tbody>
<%
{
%>
<tr><td><a href="viewQuestion.jsp?id=<%=qb.getQuestionId() %>"><%=qb.getQuestionText() %></a></td></tr>
<%
}
%>
</tbody>
</table>


<%
}
%>

</table>
</div>
</body>
</html>

最佳答案

我认为问题出在你的 if-else 语句中。你的 getter 告诉我返回值是一个 boolean 值,但你进行了一个字符串比较:

qb.getIsAnswered().equalsIgnoreCase("Y")

更改您的数据模型或调试此行的返回值。

请发布您的模型类。

关于java - if-else 语句无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38053423/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com