首页 > 其他 > 详细

08 SSM整合案例(企业权限管理系统):09.用户操作

时间:2019-09-24 10:31:34      阅读:246      评论:0      收藏:0      [点我收藏+]

04.AdminLTE的基本介绍

05.SSM整合案例的基本介绍

06.产品操作

07.订单操作

08.权限控制

09.用户操作

10.权限关联与控制

11.AOP日志

09.用户操作 

 


 

 1. 用户操作-查询所有用户

 技术分享图片

 3.3.1.用户查询页面 user-list.jsp
 请在资料中查看具体代码

                            <!--数据列表-->
                            <table id="dataList"
                                class="table table-bordered table-striped table-hover dataTable">
                                <thead>
                                    <tr>
                                        <th class="" style="padding-right: 0px"><input
                                            id="selall" type="checkbox" class="icheckbox_square-blue">
                                        </th>
                                        <th class="sorting_asc">ID</th>
                                        <th class="sorting_desc">用户名</th>
                                        <th class="sorting_asc sorting_asc_disabled">邮箱</th>
                                        <th class="sorting_desc sorting_desc_disabled">联系电话</th>
                                        <th class="sorting">状态</th>
                                        <th class="text-center">操作</th>
                                    </tr>
                                </thead>
                                <tbody>

                                    <c:forEach items="${userList}" var="user" varStatus="s">
                                        <tr>
                                            <td><input name="ids" type="checkbox" id="${s.index}" value="${user.id}"></td>
                                            <td>${user.id }</td>
                                            <td>${user.username }</td>
                                            <td>${user.email }</td>
                                            <td>${user.phoneNum }</td>
                                            <td>${user.statusStr }</td>                                            
                                            <td class="text-center">
                                                <a href="${pageContext.request.contextPath}/user/findById.do?id=${user.id}" class="btn bg-olive btn-xs">详情</a>
                                                <a href="${pageContext.request.contextPath}/user/findUserByIdAndAllRole.do?id=${user.id}" class="btn bg-olive btn-xs">添加角色</a>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </tbody>

视图层  UserController  

 

@Controller
@RequestMapping(value = "/user")
public class UsersController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception{

        ModelAndView mv = new ModelAndView("user-list2");
        //获取一个添加对象
        List<UserInfo> userList = userService.findAll();
        //attributeName取决于jsp页面上的EL表达式{}里面的字符串
        mv.addObject("userList",userList);
        return mv;
    }

}

 

 UserServiceImpl

 新添加的部分代码:

 

    // 查询所有用户
    @Override
    public List<UserInfo> findAll() throws Exception {
        return userDao.findAll();
    }

 持久层 IUserDao

 新添加的部分代码:

    /**
     * 查询所有用户
     * @return
     * @throws Exception
     */
    @Select("select * from USERS")
    public List<UserInfo> findAll() throws Exception;

 

 user-list.jsp里面的一个按钮控件通过onclick 实现跳转请求  

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <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>
                                        
                                        <button type="button" class="btn btn-default" title="刷新">
                                            <i class="fa fa-refresh"></i> 刷新
                                        </button>
                                    </div>
                                </div>
                            </div>

 

  user-add.jsp里面关键信息如下:

  form表单的action属性

            <!-- 内容头部 /-->

            <form action="${pageContext.request.contextPath}/user/save.do"
                method="post">
                <!-- 正文区域 -->

 

  3.4 用户添加  

技术分享图片

 DAO层

 

    /**
     *  添加一个新用户
     * @param userInfo
     */
    @Insert({"insert into USERS(username,email,password,phoneNum,status)",
            "values(#{username},#{email},#{password},#{phoneNum},#{status})"})
    public void save(UserInfo userInfo) throws Exception;

 

Utils工具类

 

package cn.bjut.ssm.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class BCryptPasswordEncoderUtils {

    private static BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    //工具类的方法最好用static关键字修饰
    //明文转换成密文工具类
    public static String encodePassword(String password){

        return bCryptPasswordEncoder.encode(password);
    }
}

 

Service层

    //添加一个新用户
    @Override
    public void save(UserInfo userInfo) throws Exception {
        //对密码进行加密处理
        userInfo.setPassword(bCryptPasswordEncoder.encode(userInfo.getPassword()));
        userDao.save(userInfo);
        //返回void
        return ;
    }

 

 Controller层

 

    //添加用户(后自动请求查询所有用户)
    @RequestMapping("/save.do")
    public String save(UserInfo userInfo)throws Exception{
        userService.save(userInfo);
        //返回字符串为当前控制类的注解@RequestMapping后面小括号里的内容
        return "redirect:findAll.do";
    }

 

 技术分享图片

 

 修改oracle数据库中表的varchar2字段类型长度 

 技术分享图片

 

 

 

 

 

====================

end

08 SSM整合案例(企业权限管理系统):09.用户操作

原文:https://www.cnblogs.com/MarlonKang/p/11576163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!