档案管理系统总结

                    档案管理总结逻辑代码

1.角色管理
当前系统主要分为几种角色:员工、档案管理员、系统管理员、数据维护员,
并提供给管理员任意添加和删除角色的功能,除了“系统管理员”的权限外,
其他角色权限都可以任意进行修改,而功能权限就是后台的管理菜单,如某些角色具备哪个权限,
那么进入后台管理后只能看到相应的功能菜单。

使用角色 : 系统管理员
BaseMapper

 public interface BaseMapper<T> {
    //删除
    int deleteByPrimaryKey(Long id);
    //添加
    int insert(T record);

    T selectByPrimaryKey(Long id);

    List<T> queryPage(BaseQueryObject bo);
    //修改
    int updateByPrimaryKey(T record);

}

关键字查询 RoleQuery

 public class RoleQuery extends BaseQueryObject{
    //关键字查询
    private String keyword;

    public String getKeyword() {
        if (StringUtils.hasLength(keyword)){
            return keyword.trim();
        }
        return null;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

RoleMapper

public interface RoleMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Role record);

    Role selectByPrimaryKey(Long id);

    int updateByPrimaryKey(Role record);

    List queryPage(BaseQueryObject bo);
}

sql增删查改
cn.itsource.mapper
 RoleMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.itsource.mapper.RoleMapper" >
  <resultMap id="BaseResultMap" type="cn.itsource.domain.Role" >
    <id column="id" property="id"  />
    <result column="user_name" property="username"  />
    <result column="sn" property="sn"  />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from t_role
    where id = #{id,}
  </delete>
  <insert id="insert" parameterType="cn.itsource.domain.Role" useGeneratedKeys="true" keyProperty="id" >
    insert into t_role (user_name, sn)values (#{username}, #{sn})
  </insert>
  <update id="updateByPrimaryKey" parameterType="cn.itsource.domain.Role" >
    update t_role  set user_name = #{username}, sn = #{sn}
    where id = #{id,}
  </update>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, user_name, sn from t_role
    where id = #{id}
  </select>
  <select id="queryPage" resultMap="BaseResultMap" >
    select id, user_name, sn
    from t_role
    <include refid="whereId"></include>
  </select>
  <sql id="whereId" >
    <where>
      <if test="keyword != null">
        and user_name like concat("%",#{keyword},"%")
      </if>
    </where>
  </sql>
</mapper>

        service

public interface IRoleService extends IBaseService<Role> {
    PageResult<Role> queryPage(RoleQuery bo);

    int insert(Role role);
    //删除employee和role的中间表
    void deleteEmployeeIDAndRoleId(Long id1);
    //删除role和Permisson的中间表
    void deleteRoleIDAndPermissonId(Long id);
}


    serviceImpl
@Service
@Transactional
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService{
    @Autowired
    private RoleMapper roleMapper ;

    @Override
    public PageResult queryPage(RoleQuery bo) {
        Page<Object> page = PageHelper.startPage(bo.getPage(), bo.getRows());
        Page ts = (Page) roleMapper.queryPage(bo);
        return new PageResult(ts.getTotal(),ts.getResult());
    }

    @Override
    public void deleteEmployeeIDAndRoleId(Long id1) {

    }

    @Override
    public void deleteRoleIDAndPermissonId(Long id) {

    }


web RoleController 跳转页

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    //跳转到列表界面
    @RequestMapping("/index")
    public String indxe(Model model){
        return "role";
    }

    //员工显示列表信息
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(RoleQuery rq){
        return roleService.queryPage(rq);
    }

    /**
     * 员工添加/修改
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Role role){
        try {
            if(role.getId() == null){
                roleService.insert(role);
            }else{
                roleService.updateByPrimaryKey(role);
            }
            return AjaxResult.success();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("啊,系统异常啦,我们正在殴打程序员O(∩_∩)O~");
        }
    }

    /**
     * 员工删除
     */
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id){
        try {
            roleService.deleteByPrimaryKey(id);
            return AjaxResult.success();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("啊,系统异常啦,我们正在殴打程序员O(∩_∩)O~");
        }
    }
}



js页面 Role.js




$(function () {
    //变量的抽取:
    var roleDatagrid=$('#departmentDatagrid');  //employeeDataGrid
    var roleDlg=$('#roleDlg');
    var  roleForm=$('#roleForm');


    //datagrid
    roleDatagrid.datagrid({
        url: 'role/list',
        fit:true,
        title:'角色管理',
        rownumbers:true,
        pagination:true,
        singleSelect:true,
        toolbar:"#toolbar",
        columns: [[
            /*使用遍历:遍历的是Velocity中上下文的对象:
            * fieldList
            *                  {field: 'id', title: 'id', width: '10%',align:  'center'},
            * */
            {field: 'username', title: '权限管理员', width: '50%',align:  'center'},
            {field: 'sn', title: '编号', width: '50%',align:  'center'},
            /*{field: 'Permission', title: '权限', width: '30%',align:  'center'}*/
        ]]
    });

 
    //按钮的事件
    var methodObj={
        'search':function () {
            var keyword = $("#keyword").val();
            roleDatagrid.datagrid("load",{"keyword":keyword})
        },
        'add':function () {
            //弹出一个dialog,里面装form表单  departmentDlg
          roleDlg.dialog('open').dialog('center').dialog('setTitle','角色添加').dialog("resize",{
              width:850,
              height:510
          }).dialog("center");

            //清空表单
            roleForm.form('clear');

           //想办法发一个请求 menu/findMenuByLoginUser 获取数据 在弹窗里面填充

        },
        'edit':function () {
            //先获取编辑的数据
            var row = roleDatagrid.datagrid('getSelected');
            //做一个判断:是否选中
            if (row){
                //弹出dialog,进行数据的回显
                //弹出一个dialog,里面装form表单  departmentDlg
                roleDlg.dialog('open').dialog('center').dialog('setTitle','角色修改');
                //清空表单
                roleForm.form('clear');
                //表单数据的回显:
                roleForm.form('load',row);
            }else{
                $.messager.alert('温馨提示','请选中需要编辑的行!!','warning');
            }
        },
        'delete':function () {
            //先获取删除的数据
            var row = roleDatagrid.datagrid('getSelected');
            //做一个判断:是否选中
            if (row){
                $.messager.confirm('温馨提示','你确定删除:[<font color="pink">'+row.name+"</font>]吗?",function(r){
                    // 选中:确认的操作:调用后台的删除方法:发送ajax调用
                    if (r){
                        // 发送ajax调用 $.get(url,params,function(d){},type)
                        $.get('department/delete?id='+row.id,function (d) {
                            //d的处理
                            if(d.success){
                                //true:成功
                                $.messager.alert('操作提示',d.msg,'info');
                                //页面刷新
                                cmdObj.refresh();
                            }else{
                                //false:失败:提示
                                $.messager.alert('错误提示',d.msg,'error');
                            }

                        },'json')
                    }
                });
            }else{
                $.messager.alert('温馨提示','请选中需要删除的行!!','warning');
            }
        },
        'refresh':function () {
            //datagrid的重新加载: $("selector").datagrid('funName');
            roleDatagrid.datagrid('reload');
        },
        'submit':function(){
            //提交:表单的提交:
            roleForm.form('submit', {
                url:'role/saveOrUpdate',
                onSubmit: function(){
                },
                success:function(data){
                    // {"success":true,"msg":"操作成功"}==>json字符串
                    var $data = $.parseJSON(data);
                    //弹框提示和刷新
                    if($data.success){
                        $.messager.alert('操作提示',$data.msg,'info');
                    }else{
                        $.messager.alert('错误提示',$data.msg,'error');

                    }

                    roleDlg.dialog('close');
                    //页面刷新
                    methodObj.refresh();
                }
            });
        },
        'cancel':function(){
            //关闭dialog,不清空form,在打开dialog的时候清空
            roleDlg.dialog('close');
        }

    };

    //toolbar绑定事件:如果按钮禁用了怎么办?下午具体实现
    $("a[data-method]").on('click',function () {
        //data-cmd="add"
        var method=$(this).data('method');
        methodObj[method]();
    });
});



Role.jsp 前台展示页面


<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>

    <title>角色管理员</title>
    <%--引入公共依赖--%>
    <%@include file="/static/common/common_header.jsp"%>
    <script src="/static/js/model/role.js"></script>

</head>
<body>
<%--部门表格展示--%>
<table id="departmentDatagrid"></table>
<%--操作部门CRUD的按钮--%>
<div id="toolbar">
    <a data-method="add" href="javascript:void(0)" class="easyui-linkbutton c1" iconCls="icon-add" plain="true">添加</a>
    <a data-method="edit" href="javascript:void(0)" class="easyui-linkbutton c2" iconCls="icon-edit" plain="true" >编辑</a>
    <a data-method="delete" href="javascript:void(0)" class="easyui-linkbutton c3" iconCls="icon-remove" plain="true" >删除</a>
    <a data-method="refresh" href="javascript:void(0)" class="easyui-linkbutton c4" iconCls="icon-reload" plain="true" >刷新</a>
    &emsp;
    角色:<input type="text" id="keyword">
    <a data-method="search" href="javascript:void(0)" class="easyui-linkbutton c4" iconCls="icon-search" plain="true" >查询</a>
</div>
<%--角色CRUD弹窗--%>
<div id="roleDlg" class="easyui-dialog" style="width: 400px"
     closed="true" buttons="#dlg-buttons">
    <form id="roleForm" method="post" novalidate style="margin:0;padding:20px 50px">
        <%--编辑隐藏域的处理--%>
        <input type="hidden" name="id" >
        <table>
            <tr>
                <td style="text-align: right">角色管理员:</td>
                <td><input class="easyui-textbox" type="text" name="name"></input></td>
                <td style="text-align: right">角色编号:</td>
                <td><input class="easyui-textbox" type="text" name="sn"></input></td>
            </tr>
            <table id="dg" class="easyui-datagrid" title="所有权限"
                   data-options="
           fit:true,
           striped:true,
           rownumbers:true,
           fitColumns:true,
           pagination:true,
           toolbar:'#tb',
           url:'permission/list'">
                <thead>
                <tr>
                    <th data-options="field:'id',checkbox:true,width:'1%'">ID</th>
                    <th data-options="field:'name',width:100">权限名</th>
                    <th data-options="field:'url',width:100">url路径</th>
                    <th data-options="field:'sn',width:100">编号</th>
                </tr>
                </thead>
            </table>
        </table>
    </form>
</div>
<%--弹窗的按钮--%>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" data-cmd="submit" style="width:90px">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton c8" iconCls="icon-cancel" data-cmd="cancel" style="width:90px">取消</a>
</div>
</body>
</html>


多模块开发的布局格式以及配置文件公共代码详情;

    basic-core
    mapper
BaseMapper
package cn.itsource.mapper;

import cn.itsource.query.BaseQueryObject;

import java.util.List;

public interface BaseMapper<T> {
    //删除
    int deleteByPrimaryKey(Long id);
    //添加
    int insert(T record);

    T selectByPrimaryKey(Long id);

    List<T> queryPage(BaseQueryObject bo);
    //修改
    int updateByPrimaryKey(T record);

}
    quer
BaseQueryObject
package cn.itsource.query;


//每个查询都有的公共属性
public class BaseQueryObject {
    //当前页
    private Integer page = 1;
    //当前页的总条数
    private Integer rows = 10;

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getRows() {
        return rows;
    }

    public void setRows(Integer rows) {
        this.rows = rows;
    }
}


    service层
        BaseServiceImpl
package cn.itsource.service.impl;

import cn.itsource.mapper.BaseMapper;
import cn.itsource.query.BaseQueryObject;
import cn.itsource.service.IBaseService;
import cn.itsource.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper ;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return baseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(T record) {
        return baseMapper.insert(record);
    }

    @Override
    @Transactional(readOnly = true)
    public T selectByPrimaryKey(Long id) {
        return baseMapper.selectByPrimaryKey(id);
    }


    @Override
    public int updateByPrimaryKey(T record) {
        return baseMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult selectForList(BaseQueryObject qo) {
        return null;
    }

    @Override
    public Page<T> findPageByQuery(BaseQueryObject baseQueryObject) {
        return null;
    }


}

    IBaseService
package cn.itsource.service;

import cn.itsource.query.BaseQueryObject;
import cn.itsource.util.PageResult;
import com.github.pagehelper.Page;

public interface IBaseService<T> {
    int deleteByPrimaryKey(Long id);

    int insert(T record);

    T selectByPrimaryKey(Long id);

    int updateByPrimaryKey(T record);

    PageResult selectForList(BaseQueryObject qo);

    //查询分页,根据查询条件
    Page<T> findPageByQuery(BaseQueryObject baseQueryObject);


}    

       basic-util
    
    util    
AjaxResult

package cn.itsource.util;

public class AjaxResult {
    private boolean success = true;
    private String msg;

    //返回成功的AjaxResult
    public static AjaxResult success(){
        return new AjaxResult();
    }
    //返回有异常的AjaxResult
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = success();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public boolean isSuccess() {
        return success;
    }

    private void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }
}



EasyuiColumn

package cn.itsource.util;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EasyuiColumn {
    public String title();
}


FieldVo

package cn.itsource.util;

public class FieldVo {

    //domain的field
    private String title;

    //domain的title:标签上的值
    private String field;

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

PageResult

package cn.itsource.util;

import java.util.ArrayList;
import java.util.List;

public class PageResult<T> {

    private long total = 0;

    private List rows = new ArrayList();

    public PageResult() {
    }

    public PageResult(long total, List rows) {
        this.total = total;
        this.rows = rows;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List getRows() {
        return rows;
    }

    public void setRows(List rows) {
        this.rows = rows;
    }
}

    mg-service

applicationContext.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/task
     http://www.springframework.org/schema/task/spring-task-4.0.xsd
">
    <!--引入jdbc.properties-->
    <context:property-placeholder location="classpath:jdbc.properties" />

    <!--扫描Service层-->
    <context:component-scan base-package="cn.itsource.service" />
    <!-- 1.开启注解AOP -->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
    <!-- 配置自动代理功能 -->
    <aop:config proxy-target-class="true"></aop:config>
    <!--开启定时任务注解-->
    <task:annotation-driven />

    <!--创建数据源(dataSource)-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    <!--
        咱们以前学过JPA,JPA的话需要配置EntityManagerFactory(需要读取配置,做很多事情都能配置)
            咱们使用了一个FactoryBean完成 -> EntityManagerFactoryBean
        配置SqlSessionFactory需要读取配置,做很多事情都能配置),它有一个叫做SqlSessionFactoryBean
     -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!--XML的映射-->
       <property name="mapperLocations" value="classpath:cn/itsource/mapper/*Mapper.xml"/>
       <!-- &lt;!&ndash;为所有相应的包中的类取别名&ndash;&gt;
        <property name="typeAliasesPackage" value="cn.itsource.ssme.domain" />-->

        <!--配置一个拦截器(分页插件):注意一下版本问题-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>helperDialect=mysql</value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>

    <!--一劳永逸的方案:直接创建所有的映射器mapper-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.itsource.mapper" />
    </bean>

    <!--我们需要配置一个事务管理器
        以前学习JPA ,是有一个类JpaTransactionManager的事务对象
        mybatis用的是:DataSourceTransactionManager
    -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!--配置标签支持事务-->
    <tx:annotation-driven transaction-manager="transactionManager" />
    <!--引入shiro的配置文件-->
    <import resource="classpath:applicationContext-shiro.xml"/>

</beans>


    jdbc.properties链接数据库
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///dn  dn表示的是数据库里面链接的数据库名字
jdbc.username=root
jdbc.password=123456


    mg-web
common
    common_header.jsp  获取上下文路径

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--
  request.getScheme() -> http
  request.getServerName() -> 服务名 : localhost
  request.getServerPort() -> 端口
  request.getContextPath() -> 获取上下路径
--%>
<%
    //http://localhost:80/crm/
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>" >

<link rel="stylesheet" type="text/css" href="static/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="static/js/easyui/themes/icon.css">
<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/js/easyui/jquery.easyui.min.js"></script>





















































                    档案管理总结逻辑代码

1.角色管理
当前系统主要分为几种角色:员工、档案管理员、系统管理员、数据维护员,
并提供给管理员任意添加和删除角色的功能,除了“系统管理员”的权限外,
其他角色权限都可以任意进行修改,而功能权限就是后台的管理菜单,如某些角色具备哪个权限,
那么进入后台管理后只能看到相应的功能菜单。

使用角色 : 系统管理员
BaseMapper

 public interface BaseMapper<T> {
    //删除
    int deleteByPrimaryKey(Long id);
    //添加
    int insert(T record);

    T selectByPrimaryKey(Long id);

    List<T> queryPage(BaseQueryObject bo);
    //修改
    int updateByPrimaryKey(T record);

}

关键字查询 RoleQuery

 public class RoleQuery extends BaseQueryObject{
    //关键字查询
    private String keyword;

    public String getKeyword() {
        if (StringUtils.hasLength(keyword)){
            return keyword.trim();
        }
        return null;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

RoleMapper

public interface RoleMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Role record);

    Role selectByPrimaryKey(Long id);

    int updateByPrimaryKey(Role record);

    List queryPage(BaseQueryObject bo);
}

sql增删查改
cn.itsource.mapper
 RoleMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.itsource.mapper.RoleMapper" >
  <resultMap id="BaseResultMap" type="cn.itsource.domain.Role" >
    <id column="id" property="id"  />
    <result column="user_name" property="username"  />
    <result column="sn" property="sn"  />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from t_role
    where id = #{id,}
  </delete>
  <insert id="insert" parameterType="cn.itsource.domain.Role" useGeneratedKeys="true" keyProperty="id" >
    insert into t_role (user_name, sn)values (#{username}, #{sn})
  </insert>
  <update id="updateByPrimaryKey" parameterType="cn.itsource.domain.Role" >
    update t_role  set user_name = #{username}, sn = #{sn}
    where id = #{id,}
  </update>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, user_name, sn from t_role
    where id = #{id}
  </select>
  <select id="queryPage" resultMap="BaseResultMap" >
    select id, user_name, sn
    from t_role
    <include refid="whereId"></include>
  </select>
  <sql id="whereId" >
    <where>
      <if test="keyword != null">
        and user_name like concat("%",#{keyword},"%")
      </if>
    </where>
  </sql>
</mapper>

        service

public interface IRoleService extends IBaseService<Role> {
    PageResult<Role> queryPage(RoleQuery bo);

    int insert(Role role);
    //删除employee和role的中间表
    void deleteEmployeeIDAndRoleId(Long id1);
    //删除role和Permisson的中间表
    void deleteRoleIDAndPermissonId(Long id);
}


    serviceImpl
@Service
@Transactional
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService{
    @Autowired
    private RoleMapper roleMapper ;

    @Override
    public PageResult queryPage(RoleQuery bo) {
        Page<Object> page = PageHelper.startPage(bo.getPage(), bo.getRows());
        Page ts = (Page) roleMapper.queryPage(bo);
        return new PageResult(ts.getTotal(),ts.getResult());
    }

    @Override
    public void deleteEmployeeIDAndRoleId(Long id1) {

    }

    @Override
    public void deleteRoleIDAndPermissonId(Long id) {

    }


web RoleController 跳转页

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    //跳转到列表界面
    @RequestMapping("/index")
    public String indxe(Model model){
        return "role";
    }

    //员工显示列表信息
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(RoleQuery rq){
        return roleService.queryPage(rq);
    }

    /**
     * 员工添加/修改
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Role role){
        try {
            if(role.getId() == null){
                roleService.insert(role);
            }else{
                roleService.updateByPrimaryKey(role);
            }
            return AjaxResult.success();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("啊,系统异常啦,我们正在殴打程序员O(∩_∩)O~");
        }
    }

    /**
     * 员工删除
     */
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id){
        try {
            roleService.deleteByPrimaryKey(id);
            return AjaxResult.success();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("啊,系统异常啦,我们正在殴打程序员O(∩_∩)O~");
        }
    }
}



js页面 Role.js




$(function () {
    //变量的抽取:
    var roleDatagrid=$('#departmentDatagrid');  //employeeDataGrid
    var roleDlg=$('#roleDlg');
    var  roleForm=$('#roleForm');


    //datagrid
    roleDatagrid.datagrid({
        url: 'role/list',
        fit:true,
        title:'角色管理',
        rownumbers:true,
        pagination:true,
        singleSelect:true,
        toolbar:"#toolbar",
        columns: [[
            /*使用遍历:遍历的是Velocity中上下文的对象:
            * fieldList
            *                  {field: 'id', title: 'id', width: '10%',align:  'center'},
            * */
            {field: 'username', title: '权限管理员', width: '50%',align:  'center'},
            {field: 'sn', title: '编号', width: '50%',align:  'center'},
            /*{field: 'Permission', title: '权限', width: '30%',align:  'center'}*/
        ]]
    });

 
    //按钮的事件
    var methodObj={
        'search':function () {
            var keyword = $("#keyword").val();
            roleDatagrid.datagrid("load",{"keyword":keyword})
        },
        'add':function () {
            //弹出一个dialog,里面装form表单  departmentDlg
          roleDlg.dialog('open').dialog('center').dialog('setTitle','角色添加').dialog("resize",{
              width:850,
              height:510
          }).dialog("center");

            //清空表单
            roleForm.form('clear');

           //想办法发一个请求 menu/findMenuByLoginUser 获取数据 在弹窗里面填充

        },
        'edit':function () {
            //先获取编辑的数据
            var row = roleDatagrid.datagrid('getSelected');
            //做一个判断:是否选中
            if (row){
                //弹出dialog,进行数据的回显
                //弹出一个dialog,里面装form表单  departmentDlg
                roleDlg.dialog('open').dialog('center').dialog('setTitle','角色修改');
                //清空表单
                roleForm.form('clear');
                //表单数据的回显:
                roleForm.form('load',row);
            }else{
                $.messager.alert('温馨提示','请选中需要编辑的行!!','warning');
            }
        },
        'delete':function () {
            //先获取删除的数据
            var row = roleDatagrid.datagrid('getSelected');
            //做一个判断:是否选中
            if (row){
                $.messager.confirm('温馨提示','你确定删除:[<font color="pink">'+row.name+"</font>]吗?",function(r){
                    // 选中:确认的操作:调用后台的删除方法:发送ajax调用
                    if (r){
                        // 发送ajax调用 $.get(url,params,function(d){},type)
                        $.get('department/delete?id='+row.id,function (d) {
                            //d的处理
                            if(d.success){
                                //true:成功
                                $.messager.alert('操作提示',d.msg,'info');
                                //页面刷新
                                cmdObj.refresh();
                            }else{
                                //false:失败:提示
                                $.messager.alert('错误提示',d.msg,'error');
                            }

                        },'json')
                    }
                });
            }else{
                $.messager.alert('温馨提示','请选中需要删除的行!!','warning');
            }
        },
        'refresh':function () {
            //datagrid的重新加载: $("selector").datagrid('funName');
            roleDatagrid.datagrid('reload');
        },
        'submit':function(){
            //提交:表单的提交:
            roleForm.form('submit', {
                url:'role/saveOrUpdate',
                onSubmit: function(){
                },
                success:function(data){
                    // {"success":true,"msg":"操作成功"}==>json字符串
                    var $data = $.parseJSON(data);
                    //弹框提示和刷新
                    if($data.success){
                        $.messager.alert('操作提示',$data.msg,'info');
                    }else{
                        $.messager.alert('错误提示',$data.msg,'error');

                    }

                    roleDlg.dialog('close');
                    //页面刷新
                    methodObj.refresh();
                }
            });
        },
        'cancel':function(){
            //关闭dialog,不清空form,在打开dialog的时候清空
            roleDlg.dialog('close');
        }

    };

    //toolbar绑定事件:如果按钮禁用了怎么办?下午具体实现
    $("a[data-method]").on('click',function () {
        //data-cmd="add"
        var method=$(this).data('method');
        methodObj[method]();
    });
});



Role.jsp 前台展示页面


<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>

    <title>角色管理员</title>
    <%--引入公共依赖--%>
    <%@include file="/static/common/common_header.jsp"%>
    <script src="/static/js/model/role.js"></script>

</head>
<body>
<%--部门表格展示--%>
<table id="departmentDatagrid"></table>
<%--操作部门CRUD的按钮--%>
<div id="toolbar">
    <a data-method="add" href="javascript:void(0)" class="easyui-linkbutton c1" iconCls="icon-add" plain="true">添加</a>
    <a data-method="edit" href="javascript:void(0)" class="easyui-linkbutton c2" iconCls="icon-edit" plain="true" >编辑</a>
    <a data-method="delete" href="javascript:void(0)" class="easyui-linkbutton c3" iconCls="icon-remove" plain="true" >删除</a>
    <a data-method="refresh" href="javascript:void(0)" class="easyui-linkbutton c4" iconCls="icon-reload" plain="true" >刷新</a>
    &emsp;
    角色:<input type="text" id="keyword">
    <a data-method="search" href="javascript:void(0)" class="easyui-linkbutton c4" iconCls="icon-search" plain="true" >查询</a>
</div>
<%--角色CRUD弹窗--%>
<div id="roleDlg" class="easyui-dialog" style="width: 400px"
     closed="true" buttons="#dlg-buttons">
    <form id="roleForm" method="post" novalidate style="margin:0;padding:20px 50px">
        <%--编辑隐藏域的处理--%>
        <input type="hidden" name="id" >
        <table>
            <tr>
                <td style="text-align: right">角色管理员:</td>
                <td><input class="easyui-textbox" type="text" name="name"></input></td>
                <td style="text-align: right">角色编号:</td>
                <td><input class="easyui-textbox" type="text" name="sn"></input></td>
            </tr>
            <table id="dg" class="easyui-datagrid" title="所有权限"
                   data-options="
           fit:true,
           striped:true,
           rownumbers:true,
           fitColumns:true,
           pagination:true,
           toolbar:'#tb',
           url:'permission/list'">
                <thead>
                <tr>
                    <th data-options="field:'id',checkbox:true,width:'1%'">ID</th>
                    <th data-options="field:'name',width:100">权限名</th>
                    <th data-options="field:'url',width:100">url路径</th>
                    <th data-options="field:'sn',width:100">编号</th>
                </tr>
                </thead>
            </table>
        </table>
    </form>
</div>
<%--弹窗的按钮--%>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" data-cmd="submit" style="width:90px">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton c8" iconCls="icon-cancel" data-cmd="cancel" style="width:90px">取消</a>
</div>
</body>
</html>


多模块开发的布局格式以及配置文件公共代码详情;

    basic-core
    mapper
BaseMapper
package cn.itsource.mapper;

import cn.itsource.query.BaseQueryObject;

import java.util.List;

public interface BaseMapper<T> {
    //删除
    int deleteByPrimaryKey(Long id);
    //添加
    int insert(T record);

    T selectByPrimaryKey(Long id);

    List<T> queryPage(BaseQueryObject bo);
    //修改
    int updateByPrimaryKey(T record);

}
    quer
BaseQueryObject
package cn.itsource.query;


//每个查询都有的公共属性
public class BaseQueryObject {
    //当前页
    private Integer page = 1;
    //当前页的总条数
    private Integer rows = 10;

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getRows() {
        return rows;
    }

    public void setRows(Integer rows) {
        this.rows = rows;
    }
}


    service层
        BaseServiceImpl
package cn.itsource.service.impl;

import cn.itsource.mapper.BaseMapper;
import cn.itsource.query.BaseQueryObject;
import cn.itsource.service.IBaseService;
import cn.itsource.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper ;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return baseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(T record) {
        return baseMapper.insert(record);
    }

    @Override
    @Transactional(readOnly = true)
    public T selectByPrimaryKey(Long id) {
        return baseMapper.selectByPrimaryKey(id);
    }


    @Override
    public int updateByPrimaryKey(T record) {
        return baseMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult selectForList(BaseQueryObject qo) {
        return null;
    }

    @Override
    public Page<T> findPageByQuery(BaseQueryObject baseQueryObject) {
        return null;
    }


}

    IBaseService
package cn.itsource.service;

import cn.itsource.query.BaseQueryObject;
import cn.itsource.util.PageResult;
import com.github.pagehelper.Page;

public interface IBaseService<T> {
    int deleteByPrimaryKey(Long id);

    int insert(T record);

    T selectByPrimaryKey(Long id);

    int updateByPrimaryKey(T record);

    PageResult selectForList(BaseQueryObject qo);

    //查询分页,根据查询条件
    Page<T> findPageByQuery(BaseQueryObject baseQueryObject);


}    

       basic-util
    
    util    
AjaxResult

package cn.itsource.util;

public class AjaxResult {
    private boolean success = true;
    private String msg;

    //返回成功的AjaxResult
    public static AjaxResult success(){
        return new AjaxResult();
    }
    //返回有异常的AjaxResult
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = success();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public boolean isSuccess() {
        return success;
    }

    private void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }
}



EasyuiColumn

package cn.itsource.util;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EasyuiColumn {
    public String title();
}


FieldVo

package cn.itsource.util;

public class FieldVo {

    //domain的field
    private String title;

    //domain的title:标签上的值
    private String field;

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

PageResult

package cn.itsource.util;

import java.util.ArrayList;
import java.util.List;

public class PageResult<T> {

    private long total = 0;

    private List rows = new ArrayList();

    public PageResult() {
    }

    public PageResult(long total, List rows) {
        this.total = total;
        this.rows = rows;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List getRows() {
        return rows;
    }

    public void setRows(List rows) {
        this.rows = rows;
    }
}

    mg-service

applicationContext.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/task
     http://www.springframework.org/schema/task/spring-task-4.0.xsd
">
    <!--引入jdbc.properties-->
    <context:property-placeholder location="classpath:jdbc.properties" />

    <!--扫描Service层-->
    <context:component-scan base-package="cn.itsource.service" />
    <!-- 1.开启注解AOP -->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
    <!-- 配置自动代理功能 -->
    <aop:config proxy-target-class="true"></aop:config>
    <!--开启定时任务注解-->
    <task:annotation-driven />

    <!--创建数据源(dataSource)-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    <!--
        咱们以前学过JPA,JPA的话需要配置EntityManagerFactory(需要读取配置,做很多事情都能配置)
            咱们使用了一个FactoryBean完成 -> EntityManagerFactoryBean
        配置SqlSessionFactory需要读取配置,做很多事情都能配置),它有一个叫做SqlSessionFactoryBean
     -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!--XML的映射-->
       <property name="mapperLocations" value="classpath:cn/itsource/mapper/*Mapper.xml"/>
       <!-- &lt;!&ndash;为所有相应的包中的类取别名&ndash;&gt;
        <property name="typeAliasesPackage" value="cn.itsource.ssme.domain" />-->

        <!--配置一个拦截器(分页插件):注意一下版本问题-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>helperDialect=mysql</value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>

    <!--一劳永逸的方案:直接创建所有的映射器mapper-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.itsource.mapper" />
    </bean>

    <!--我们需要配置一个事务管理器
        以前学习JPA ,是有一个类JpaTransactionManager的事务对象
        mybatis用的是:DataSourceTransactionManager
    -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!--配置标签支持事务-->
    <tx:annotation-driven transaction-manager="transactionManager" />
    <!--引入shiro的配置文件-->
    <import resource="classpath:applicationContext-shiro.xml"/>

</beans>


    jdbc.properties链接数据库
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///dn  dn表示的是数据库里面链接的数据库名字
jdbc.username=root
jdbc.password=123456


    mg-web
common
    common_header.jsp  获取上下文路径

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--
  request.getScheme() -> http
  request.getServerName() -> 服务名 : localhost
  request.getServerPort() -> 端口
  request.getContextPath() -> 获取上下路径
--%>
<%
    //http://localhost:80/crm/
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>" >

<link rel="stylesheet" type="text/css" href="static/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="static/js/easyui/themes/icon.css">
<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/js/easyui/jquery.easyui.min.js"></script>

























































































posted @ 2019-07-16 10:17  啦啦啦达玛西亚  阅读(306)  评论(0编辑  收藏  举报