java技术框架springMVC
1.前台jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<table class="easyui-datagrid" id="roleList" title="岗位列表"
data-options="singleSelect:false,collapsible:true,pagination:true,url:'/role/list',method:'get',pageSize:30,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'ck',checkbox:true"></th>
<!-- <th data-options="field:'id',width:200">ID</th> -->
<th data-options="field:'name',width:200">岗位名称</th>
<th data-options="field:'description',width:200">岗位描述</th>
<th data-options="field:'createTime',width:200,align:'center',formatter:TT.formatDateTime">创建日期</th>
<th data-options="field:'updateTime',width:200,align:'center',formatter:TT.formatDateTime">更新日期</th>
<th data-options="field:'id',width:100,align:'center',formatter:TT.formatUrlRole">操作</th>
</tr>
</thead>
</table>
<script type="text/javascript" src="js/role/role-list.js"></script>
2.前台js
/**
* 选择岗位id
*
* @returns {Array}
*/
function getSelectionsIds_role() {
var roleid_str = $("#roleList");
var sels = roleid_str.datagrid("getSelections");
var ids = [];
var names_br = [];
var id_array=[];
for ( var i in sels) {
ids.push(sels[i].id);
names_br.push("<Br>"+sels[i].name);
}
ids = ids.join(",");
names_br = names_br.join(",");
id_array.push(ids,names_br);
return id_array;
}
var toolbar = [
{
text : '新增',
iconCls : 'icon-add',
handler : function() {
$(".tree-title:contains('新增岗位')").parent().click();
}
},
/* {
text : '查看',
iconCls : 'icon-tip',
handler : function() {
var id_array = getSelectionsIds_circle();
var ids=id_array[0];
//console.log(ids.length);
if (ids.length == 0) {
$.messager.alert('提示', '未选中圈子!');
return;
}else if(ids.length >=20){//-------19位----------
$.messager.alert('提示', '只能查看一个圈子!');
return;
}
//--------给隐藏input赋值-----
$("#circle_circleId").attr("value",ids);
$('#tabs').tabs('close', "圈子用户列表");//先关闭"圈子用户列表"tab,然后再打开
//var pp = $('#tabs').tabs('getSelected');
//console.log(pp);
//var tab1 = pp.panel('options').tab; // the corresponding tab object
//console.log(tab1);
$('#tabs').tabs('add',{
title:'圈子用户列表',
content:'圈子用户列表',
href: 'circle-users-list',
closable:true
});
}
},*/
{
text : '删除',
iconCls : 'icon-cancel',
handler : function() {
var id_array = getSelectionsIds_role();
var ids=id_array[0];
var names_br=id_array[1];
if (ids.length == 0) {
$.messager.alert('提示', '未选中岗位!');
return;
}
$.messager.confirm('确认', '确定删除: ' + names_br + ' 的岗位吗?', function(
r) {
if (r) {
var params = {
"ids" : ids,
"deleteflag" : '0'
};
$.post("/role/delete", params, function(data) {
if (data.status == 200) {
$.messager.alert('提示', '删除岗位成功!', undefined,
function() {
$("#roleList").datagrid("reload");
});
}
});
}
});
}
},
'-', ];
/**
* 修改岗位
* @param id
* @param name
*/
function modifyRole(id,name,des){
$("#role_roleId_modify").attr("value",id);
$("#role_name_modify").attr("value",name);
$("#role_des_modify").attr("value",des);
$('#tabs').tabs('close', "修改岗位");//先关闭"修改岗位"tab,然后再打开
$('#tabs').tabs('add',{
title:'修改岗位',
content:'修改岗位',
href: 'role-modify',
closable:true
});
}
3.后台controller
package org.bigdatacn.sfgk.jdpt.controller;
import java.util.Date;
import org.bigdatacn.sfgk.jdpt.common.pojo.DatagridResult;
import org.bigdatacn.sfgk.jdpt.common.pojo.JdResult;
import org.bigdatacn.sfgk.jdpt.common.utils.ExceptionUtil;
import org.bigdatacn.sfgk.jdpt.common.utils.IDUtils;
import org.bigdatacn.sfgk.jdpt.pojo.JdptRole;
import org.bigdatacn.sfgk.jdpt.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/role")
public class RoleController {
@Autowired
RoleService roleService;
/**
*
* @description 查询所有岗位
* @author
* @creatime 2016年6月18日下午4:20:26
* @user renzong
* @update
* @updatetime 2016年6月18日下午4:20:26
* @param page
* @param rows
* @param id
* @return
*/
@RequestMapping("/list")
@ResponseBody
DatagridResult getRoleList(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "30") Integer rows, Long id) {
try {
return roleService.getRoleList(page, rows);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
*
* @description 删除一个或多个岗位
* @author
* @creatime 2016年6月18日下午4:20:45
* @user renzong
* @update
* @updatetime 2016年6月18日下午4:20:45
* @param ids
* @return
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public JdResult delete(String[] ids) {
try {
return roleService.delete(ids);
} catch (Exception e) {
e.printStackTrace();
return JdResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* @description 新增岗位
* @author renzong
* @creatime 2016年6月20日上午10:43:23
* @user renzong
* @update
* @updatetime 2016年6月20日上午10:43:23
* @param role
* @return
*/
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ResponseBody
public JdResult save(JdptRole role) {
try {
Date time = new Date();
role.setId(IDUtils.get19NumID());
role.setCreateUserId("11111");
role.setCreateTime(time);
role.setUpdateUserId("11111");
role.setUpdateTime(time);
return roleService.create(role);
} catch (Exception e) {
e.printStackTrace();
return JdResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* @description 修改岗位
* @author renzong
* @creatime 2016年6月20日上午10:43:39
* @user renzong
* @update
* @updatetime 2016年6月20日上午10:43:39
* @param role
* @return
*/
@RequestMapping(value = "/modify", method = RequestMethod.POST)
@ResponseBody
public JdResult modify(JdptRole role) {
try {
Date time = new Date();
role.setUpdateUserId("11111");//-------?
role.setUpdateTime(time);
return roleService.update(role);
} catch (Exception e) {
e.printStackTrace();
return JdResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
}
4.后台service
package org.bigdatacn.sfgk.jdpt.service;
import org.bigdatacn.sfgk.jdpt.common.pojo.DatagridResult;
import org.bigdatacn.sfgk.jdpt.common.pojo.JdResult;
import org.bigdatacn.sfgk.jdpt.pojo.JdptRole;
import org.bigdatacn.sfgk.jdpt.pojo.JdptUser;
public interface RoleService {
/**
*
* @description 分页获取岗位列表
* @author renzong
* @creatime 2016年6月18日上午10:33:45
* @user renzong
* @update
* @updatetime 2016年6月18日上午10:33:45
* @param page
* @param rows
* @return
*/
DatagridResult getRoleList(Integer page, Integer rows) throws Exception;
/**
*
* @description 删除一个或多个岗位
* @author renzong
* @creatime 2016年6月18日下午3:46:11
* @user renzong
* @update
* @updatetime 2016年6月18日下午3:46:11
* @param ids
* @return
*/
JdResult delete(String[] ids) throws Exception;
/**
*
* @description 新增岗位
* @author renzong
* @creatime 2016年6月18日下午5:10:23
* @user renzong
* @update
* @updatetime 2016年6月18日下午5:10:23
* @param role
* @return
*/
JdResult create(JdptRole role) throws Exception;
/**
*
* @description 修改岗位
* @author renzong
* @creatime 2016年6月20日上午10:45:07
* @user renzong
* @update
* @updatetime 2016年6月20日上午10:45:07
* @param role
* @return
*/
JdResult update(JdptRole role);
}
5.后台serviceimpl
package org.bigdatacn.sfgk.jdpt.service.impl;
import java.util.Date;
import java.util.List;
import org.bigdatacn.sfgk.jdpt.common.pojo.DatagridResult;
import org.bigdatacn.sfgk.jdpt.common.pojo.JdResult;
import org.bigdatacn.sfgk.jdpt.common.utils.IDUtils;
import org.bigdatacn.sfgk.jdpt.mapper.JdptRoleMapper;
import org.bigdatacn.sfgk.jdpt.pojo.JdptRole;
import org.bigdatacn.sfgk.jdpt.pojo.JdptRoleExample;
import org.bigdatacn.sfgk.jdpt.pojo.JdptRoleExample.Criteria;
import org.bigdatacn.sfgk.jdpt.pojo.JdptUser;
import org.bigdatacn.sfgk.jdpt.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
JdptRoleMapper roleMapper;
/**
*
* @description 分页获取岗位列表
* @author renzong
* @creatime 2016年6月18日上午10:33:45
* @user renzong
* @update
* @updatetime 2016年6月18日上午10:33:45
* @param page
* @param rows
* @return
*/
@Override
public DatagridResult getRoleList(Integer page, Integer rows) throws Exception {
JdptRoleExample example = new JdptRoleExample();
example.setOrderByClause("update_time desc");//排序
Criteria criteria = example.createCriteria();
// 设置分页插件
PageHelper.startPage(page, rows);
List<JdptRole> list = roleMapper.selectByExample(example);
DatagridResult datagrid = new DatagridResult();
datagrid.setRows(list);
// 获取总记录数
PageInfo<JdptRole> pageInfo = new PageInfo<>(list);
datagrid.setTotal(pageInfo.getTotal());
return datagrid;
}
/**
*
* @description 删除一个或多个岗位
* @author renzong
* @creatime 2016年6月18日下午4:11:14
* @user renzong
* @update
* @updatetime 2016年6月18日下午4:11:14
* @param ids
* @return
*/
@Override
public JdResult delete(String[] ids) throws Exception {
JdptRoleExample example = null;
for (String value : ids) {
example = new JdptRoleExample();
Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(value);
roleMapper.deleteByExample(example);
}
return JdResult.ok();
}
/**
*
* @description 新增岗位
* @author renzong
* @creatime 2016年6月18日下午5:11:08
* @user renzong
* @update
* @updatetime 2016年6月18日下午5:11:08
* @param role
* @return
*/
@Override
public JdResult create(JdptRole role) throws Exception {
int n = roleMapper.insert(role);
if (n > 0) {
return JdResult.ok();
} else {
return JdResult.build(404, "保存失败");
}
}
/**
*
* @description 修改岗位
* @author renzong
* @creatime 2016年6月20日上午10:48:59
* @user renzong
* @update
* @updatetime 2016年6月20日上午10:48:59
* @param role
* @return
*/
@Override
public JdResult update(JdptRole role) {
JdptRoleExample example = new JdptRoleExample();
Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(role.getId());
int n = roleMapper.updateByExample(role, example);
if (n > 0) {
return JdResult.ok();
} else {
return JdResult.build(404, "修改失败");
}
}
}
6.中间用到的实体类
package org.bigdatacn.sfgk.jdpt.common.pojo;
/**
*
*
* 类名称:Datagrid
* 类描述:
* 创建人:
* 创建时间:2016年6月21日 上午11:10:31
* 修改人:
* 修改时间:2016年6月21日 上午11:10:31
* 修改备注:
* @version
*
*/
public class DatagridResult {
private Long total;// 总数
// 响应中的数据
private Object rows;
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public Object getRows() {
return rows;
}
public void setRows(Object rows) {
this.rows = rows;
}
}
package org.bigdatacn.sfgk.jdpt.pojo;
import java.util.Date;
public class JdptRole {
private String id;
private String name;
private String description;
private Date createTime;
private String createUserId;
private Date updateTime;
private String updateUserId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getCreateUserId() {
return createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId == null ? null : createUserId.trim();
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getUpdateUserId() {
return updateUserId;
}
public void setUpdateUserId(String updateUserId) {
this.updateUserId = updateUserId == null ? null : updateUserId.trim();
}
}