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>