EL表单式判断是否为null或者list为empty

http://newnull.com/jdbctemplate%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84orm/

 

@RequestMapping("/login")
	// 请求url地址映射,类似Struts的action-mapping
	public ModelAndView Login(
			@RequestParam(value = "userEmail", required = false) String userEmail,
			@RequestParam(value = "userNick", required = false) String userNick) {
		// @RequestParam是指请求url地址映射中必须含有的参数(除非属性required=false)
		// @RequestParam可简写为:@RequestParam("username")
		//
		// if (!"admin".equals(username) || !"admin".equals(password)) {
		// return "loginError"; //
		// 跳转页面路径(默认为转发),该路径不需要包含spring-servlet配置文件中配置的前缀和后缀
		// }
		// return "loginSuccess";
		String sql = "select * from user_info where user_email=? and password=?";
		UserInfo user = jdbcTemplate.queryForObject(sql,new Object[]{userEmail,userNick},new BeanPropertyRowMapper<UserInfo>(UserInfo.class));
				
		Map<String, UserInfo> model = new HashMap<String, UserInfo>();
		model.put("userlist", user);
		return new ModelAndView("index", model);
	}

 

判断是否为空

 

 

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>           

<c:if test="${userInfo != null}">
						<tr>
							<td>
								<h2>${userInfo.id}</h2>
							</td>
							<td>
								<h2>${userInfo.userNick}</h2>
							</td>
							<td>
								<h2>${userInfo.userEmail}</h2>
							</td>
						</tr>
					</c:if>
 

 

或者使用如下

 

<c:if test="${!empty userInfo}">
				<table>
					<tr align="center"
						<c:if test="${i.index % 2 == 0}"> class="foreach_tr1" </c:if>
						<c:if test="${i.index % 2 == 1}"> class="foreach_tr2" </c:if>>
						<td>
							<h2>${userInfo.id}</h2>
						</td>
						<td>
							<h2>${userInfo.userNick}</h2>
						</td>
						<td>
							<h2>${userInfo.userEmail}</h2>
						</td>
					</tr>
				</table>
			</c:if>
 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值