<select id="findUserByNameLike" parameterType="String" resultType="cc.javar.model.User">
select * from user where username LIKE "%"#{username}"%"
</select>
JAVA代码
/**
* 模糊查询名字
* @param request
* @param name
* @param map
* @return
*/
@RequestMapping("/findUserByNameLike")
public String findUserByNameLike(HttpServletRequest request,String username,Map<String,Object> map){
try {
List<User> users=userService.findUserByNameLike(username);
map.put("allUser", users);
return "userListLike";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "userListLike";
}
}
/**
* 先进去查询页面,这里其实可以跟上面写在一起,我们先分开写
* @return
*/
@RequestMapping("/userListLike")
public String userListLike(){
return "userListLike";
}
前台
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix ="c" uri ="http://java.sun.com/jsp/jstl/core"%>
<!doctype html>
<html>
<head>
<title>Javar管理系统后台</title>
</head>
<body >
<form action="findUserByNameLike" method="post">
<input type="text" class="" name="username" placeholder="输入你需要查询得账号信息">
<p><button type="submit" >查询</button></p>
</form>
<table>
<tr>
<td>id</td>
<td>账号</td>
<td>密码</td>
<td>编辑</td>
<td>删除 </td>
</tr>
<c:forEach items="${allUser }" var="User">
<tr>
<td>${User.id}</td>
<td>${User.username}</td>
<td>${User.password}</td>
<td><a href="/ssm/updateUser2?id=${User.id}">编辑</a></td>
<td><a href="/ssm/deleteUser?id=${User.id}">删除</a> </td>
</tr>
</c:forEach>
</table>
</body>
</body>
</html>