中软国际实训日记第三天-7.22

目录

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框架的增删改查操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值