代码如下:
<%String seatgrade= " ";
while(rs.next()){
seatgrade=rs.getString( "seatgrade ");
if(seatgrade.equals( "top "))
seatgrade= "头等舱 ";
else if(seatgrade.equals( "mid "))
seatgrade= "经济舱 ";
else if(seatgrade.equals( "bg1 "))
seatgrade= "折扣舱 ";
else
seatgrade= "最低价 ";
%>
<td align= "center " class= "style16 "> <%=seatgrade%> </td> <%}%>
从数据库读出来明明的是 "top "(如果不用if else语句直接显示seatgrade的话),但是加上if else 做判断,seatgrade显示出来就是最低价.肯定是if else 的语句哪里写错了,请各位指点一下~谢谢了~
------解决方案--------------------
seatgrade=rs.getString( "seatgrade ");
->
seatgrade=rs.getString( "seatgrade ").trim()
在字符串末尾的空格等字符你是看不到的
------解决方案--------------------
应该是seatgrade字段中后面有空格,你的字段应该不是varchar的,if else 本身没有问题