目录
1.登录界面实现
2.用户管理实现
3.删除用户实现
4.更新用户实现
5.新增用户实现
正文
1.登录界面实现
控制层login.do
@RequestMapping("login.do")
public ModelAndView login(User user){
boolean flag =userService.login(user.getUsername(),user.getPassword());
ModelAndView modelAndView=new ModelAndView();
if(flag)
{
modelAndView.setViewName("main");
}else
{
modelAndView.setViewName("../failer");
}
return modelAndView;
}
login.jsp中添加动作
`<form method="post" action="/user/login.do">
<div class="form-group has-feedback">
<input type="text" class="form-control"
placeholder="用户名" name="username"> <span
class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control"
placeholder="密码" name="password"> <span
class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label><input type="checkbox"> 记住 下次自动登录</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
</div>
<!-- /.col -->
</div>
</form>`
2.用户管理实现
aside.jsp中添加动作
<ul class="treeview-menu">
<li id="system-setting">
<a
href="/user/findAll.do"> <i
class="fa fa-circle-o"></i> 用户管理
</a>
</li>
<li id="system-setting1"><a
href="#"> <i
class="fa fa-circle-o"></i> 角色管理
</a></li>
</ul>
控制层findAll.do
@RequestMapping("findAll.do")
public ModelAndView findAll(){
List<User> users=userService.findAll();
ModelAndView mv=new ModelAndView();
mv.setViewName("user-list");
mv.addObject("users",users);
return mv;
}
3.删除用户实现
list-user.jsp中添加动作
<c:forEach items="${users}" var="user">
<tr>
<td><input id="ids" name="ids" type="checkbox" value="${user.id}"></td>
<td>${user.id}</td>
<td>${user.username}</td>
<td>${user.password}</td>
<td class="text-center">
<a href="/user/toUpdate.do?id=${user.id}" class="btn bg-olive btn-xs">更新</a>
<a href="/user/deleteById.do?id=${user.id}" class="btn bg-olive btn-xs">删除</a>
<a href="" class="btn bg-olive btn-xs">添加角色</a>
</td>
</tr>
</c:forEach>
控制层删除用户
@RequestMapping("deleteById.do")
public String delete(int id){
userService.deleteById(id);
return "redirect:findAll.do";
}
点击删除则删除该用户信息
4.更新用户实现
在list-user.jsp的更新按钮添加动作
<a href="/user/toUpdate.do?id=${user.id}" class="btn bg-olive btn-xs">更新</a>
在控制层跳转到user-update.jsp页面
@RequestMapping("toUpdate.do")
public ModelAndView toUpdate(int id) {
User user=userService.selectUserById(id);
ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject("user",user);
modelAndView.setViewName("user-update");
return modelAndView;
}
更新页面
5.新增用户实现
在list-user.jsp的新建按钮添加动作
<button type="button" class="btn btn-default" title="新建"
onclick="location.href='${pageContext.request.contextPath}/pages/user-add.jsp'" >
<i class="fa fa-file-o"></i> 新建
</button>
在控制层动作响应
@RequestMapping("add.do")
public String add(User user){
userService.add(user);
return "redirect:findAll.do";
}
新建用户界面
今天学习了ssm框架的增删改查操作。