EasyUI前后端分离
陈旧的开发模式
美工(ui工程师:出一个项目模型)
java工程师:将原有的html转成jsp,动态展示数据
缺点:
客户需要调节前端的展示效果
解决:由美工去重新排版,重新选色。
Vs
前后端分离
美工、java工程师都是独立工作的,彼此之间在开发过程中是没有任何交际。
在开发前约定数据交互的格式。
java工程师的工作:写方法返回数据如tree_data1.json
美工:只管展示tree_data1.json
1、datagrid布局
2、dialog布局
3、form布局
4、通用的JsonBaseDao增删改方法
5、dao层
6、web层
7、功能完善
前端
userManage.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人员信息维护界面</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/static/js/public/easyui5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/static/js/public/easyui5/themes/icon.css">
<script type="text/javascript"
src="${pageContext.request.contextPath }/static/js/public/easyui5/jquery.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/static/js/public/easyui5/jquery.easyui.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/static/js/userManage.js"></script>
</head>
<body>
<!--展示数据 -->
<table id="dg"></table>
<!--弹窗 -->
<div id="dd" class="easyui-dialog" title="编辑窗体"
style="width: 400px; height: 200px;"
data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:'#bb'">
<!-- 提交的from表单 -->
<form id="ff" method="post">
<input type="hidden" name="SerialNo">
<!--
easyui自带正则 :但是你想要正则规划在easyUI中不存在,easyUI中只是定义了一些常见的正则
可以在easyUI中自定义validType:'正则'
$.4xtends({validType:xxx })
-->
<div>
<label for="uid">uid:</label> <input class="easyui-validatebox"
type="text" name="uid" data-options="required:true" />
</div>
<div>
<label for="uname">uname:</label> <input class="easyui-validatebox"
type="text" name="uname" data-options="required:true" />
</div>
<div>
<label for="upwd">upwd:</label> <input class="easyui-validatebox"
type="text" name="upwd" data-options="required:true" />
</div>
</form>
</div>
<!-- <div id="tb">-->
<!-- <a href="#" class="easyui-linkbutton"-->
<!-- data-options="iconCls:'icon-edit',plain:true" /a> <a href="#"-->
<!-- class="easyui-linkbutton"-->
<!-- data-options="iconCls:'icon-help',plain:true" /a>-->
<!-- </div>>-->
</div>
<div id="bb">
<a href="#" class="easyui-linkbutton" onclick="ok()">保存</a> <a href="#"
class="easyui-linkbutton">关闭</a>
</div> </div> </body>
</html>
userManage.js
$(function(){
var xfq = $("#xfq").val();
$('#dg').datagrid({
url:ctx+'/userAction.action?methodName=list',
// 行填充
fit:true,
// 列填充
fitColumns:true,
pagination:true,
singleSelect:true,
columns:[[
{field:'uid',title:'ID',width:100},
{field:'uname',title:'用户名',width:100},
{field:'upwd',title:'密码',width:100,align:'right'}
]],
toolbar: [{
iconCls: 'icon-add',
handler: function(){
$('#ff').form('clear');//清空文本框的值
$('#dd').dialog('open');//打开表格
$("#dd").attr("title","增加用户");//增加信息
$("#method").val("add"); //通过隐藏ID来设置增加方法
}
},'-',{
iconCls: 'icon-edit',
handler: function(){
$('#dd').dialog('open');
// 到datagrid控件中找需要回填的数据(区别于原来从后台查询)
var row = $('#dg').datagrid('getSelected');
if(row){
// get_data.php指的是回填的数据
$('#ff').form('load',row);
$('#method').val('edit');
}else{
alert("请选择你要修改的行");
}
}
},'-',{
iconCls: 'icon-remove',
handler: function(){
var row =$('#dg').datagrid('getSelected');
if(row){
$.ajax({
url:$("#ctx").val()+'/userAction.action?methodName=remove&&SerialNo='+row.SerialNo,
});
$('#dg').datagrid('reload');//刷新方法
alert('删除成功');
}
else{
alert('删除失败');
}
}
},'-',{
iconCls: 'icon-reload',
handler: function(){alert('刷新按钮')}
}]
});
})
function ok() {
alert('ok');
$('#ff').form('submit', {
// url:ctx+'/userAction.action?methodName=edit',
url:ctx+'/userAction.action?methodName='+$("#method").val(),
success:function(data){
// 针对于后端返回的结果进行处理
$('#ff').form('clear');
$('#dd').dialog('close');
$('#dg').datagrid('reload');
}
});
}
datagrid_data1.json
{"total":28,"rows":[
{"uid":"FI-SW-01","uname":"Koi","upwd":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
{"uid":"K9-DL-01","uname":"Dalmation","upwd":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
{"uid":"RP-SN-01","uname":"Rattlesnake","upwd":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
{"uid":"RP-SN-01","uname":"Rattlesnake","upwd":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
{"uid":"RP-LI-02","uname":"Iguana","upwd":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
{"uid":"FL-DSH-01","uname":"Manx","upwd":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
{"uid":"FL-DSH-01","uname":"Manx","upwd":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
{"uid":"FL-DLH-02","uname":"Persian","upwd":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
{"uid":"FL-DLH-02","uname":"Persian","upwd":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
{"uid":"AV-CB-01","uname":"Amazon Parrot","upwd":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}
]}
UserDao 1 package com.easyui.dao; 2 3 import java.sql.SQLException;
import java.util.List;
import java.util.Map; import com.easyui.util.JsonBaseDao;
import com.easyui.util.JsonUtils;
import com.easyui.util.PageBean;
import com.easyui.util.StringUtils; public class UserDao extends JsonBaseDao{
/**
* 用户登录或者查询用户分页的公共方法
* @param paMap
* @param pageBean
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
public List<Map<String, Object>> list(Map<String, String[]> paMap,PageBean pageBean ) throws InstantiationException, IllegalAccessException, SQLException{
String sql="select * from t_easyui_user_version2 where true";
String uid=JsonUtils.getParamVal(paMap, "uid");
String upwd=JsonUtils.getParamVal(paMap, "upwd");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid="+uid;
}
if(StringUtils.isNotBlank(upwd)) {
sql+=" and upwd="+upwd;
}
return super.executeQuery(sql, pageBean);
}
/**
* 修改
* @param paMap
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws SQLException
*/
public int edit(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
String sql = "update t_easyui_user_version2 set uid=?,uname=?,upwd=? where serialno=?";
return super.executeUpdate(sql, new String[] {"uid","uname","upwd","SerialNo"}, paMap); }
public int add(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
String sql = "insert into t_easyui_user_version2 values(?,?,?)";
return super.executeUpdate(sql, new String[] {"uid","uname","upwd"}, paMap);
}
public int remove(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
String sql = "delete from t_easyui_user_version2 where serialno=?";
return super.executeUpdate(sql, new String[] {"SerialNo"}, paMap);
}
/**
*新增
* @param paMap
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws SQLException
*/
public int add(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
String sql="insert into t_easyui_user_version2 values(?,?,?)";
return super.executeUpdate(sql, new String[] {"uid","uname","upwd"} , paMap);
}
/**
* 删除
* @param paMap
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws SQLException
*/
public int del(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
String sql="delete from t_easyui_user_version2 where SerialNo=?";
return super.executeUpdate(sql, new String[] {"SerialNo"} , paMap);
} /**
* 根据当前用户登录的id去查对应的菜单
* @param paMap
* @param pageBean
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
public List<Map<String, Object>> getMenuByUid(Map<String, String[]> paMap,PageBean pageBean ) throws InstantiationException, IllegalAccessException, SQLException{
String sql="select * from t_easyui_usermenu where true";
String uid=JsonUtils.getParamVal(paMap, "uid");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid="+uid;
} return super.executeQuery(sql, pageBean);
} }
UserAction
package com.easyui.web; import java.util.HashMap;
import java.util.List;
import java.util.Map; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.fasterxml.jackson.databind.ObjectMapper;
import com.easyui.dao.UserDao;
import com.easyui.entity.TreeNode;
import com.easyui.util.PageBean;
import com.easyui.util.ResponseUtil;
import com.zking.framework.ActionSupport; public class UserAction extends ActionSupport{ private UserDao userDao=new UserDao();
/**
* 登录成功后跳转index.jsp
* @param request
* @param response
* @return
* @throws Exception
*/
public String login(HttpServletRequest request,HttpServletResponse response) throws Exception {
//系统中是否有当前登录用户
Map<String, Object> map=null;
try {
map= this.userDao.list(request.getParameterMap(), null).get(0); } catch (Exception e) {
request.setAttribute("msg", "用户不存在");
return "login";
} // 有
//查询用户菜单中间表,获取对应menuid的集合
if(map!=null && map.size()>0) {
//[{Menuid:002,map...},{Menuid:003..}]
//[002,003]
StringBuilder sb=new StringBuilder();
List<Map<String, Object>> menuIdArr = this.userDao.getMenuByUid(request.getParameterMap(), null);
System.out.println(menuIdArr);
for (Map<String, Object> m : menuIdArr) {
sb.append(","+m.get("menuId"));
//,002,003
}
request.setAttribute("menuIds", sb.substring(1)); return "index";
}else {
System.out.println("进来了");
//没有
request.setAttribute("msg", "用户不存在");
// 返回登录界面
return "login";
} } /**
* 数据表格datagrid加载
* @param req
* @param resp
* @return
* @throws Exception
*/
public String list(HttpServletRequest req,HttpServletResponse resp) throws Exception {
ObjectMapper om = new ObjectMapper();
PageBean pageBean = new PageBean();
pageBean.setRequest(req);
List<Map<String, Object>> list = this.userDao.list(req.getParameterMap(), pageBean);
Map<String, Object> map = new HashMap<String,Object>();
map.put("total", pageBean.getTotal());
map.put("rows", list); ResponseUtil.write(resp,om.writeValueAsString(map));
return null; } /**
* form组件提交方法
* @param req
* @param resp
* @return
* @throws Exception
*/
public String edit(HttpServletRequest req,HttpServletResponse resp) throws Exception {
int code = this.userDao.edit(req.getParameterMap());
ObjectMapper om = new ObjectMapper();
Map<String, Object> map = new HashMap<String,Object>();
map.put("code", code);
ResponseUtil.write(resp,om.writeValueAsString(map));
return null; } /**
* 增加
* @param req
* @param resp
* @return
* @throws Exception
*/
public int add(HttpServletRequest req,HttpServletResponse resp) throws Exception {
int add = this.userDao.add(req.getParameterMap());
ObjectMapper om=new ObjectMapper();
ResponseUtil.write(resp, om.writeValueAsString(add));
return add;
} /**
* 删除
* @param req
* @param resp
* @return
* @throws Exception
*/
public int del(HttpServletRequest req,HttpServletResponse resp) throws Exception {
int del = this.userDao.del(req.getParameterMap());
ObjectMapper om=new ObjectMapper();
ResponseUtil.write(resp, om.writeValueAsString(del));
return del;
} }


EasyUI前后端分离的更多相关文章
- 【开源】分享一个前后端分离方案-前端angularjs+requirejs+dhtmlx 后端asp.net webapi
一.前言 半年前左右折腾了一个前后端分离的架子,这几天才想起来翻出来分享给大家.关于前后端分离这个话题大家也谈了很久了,希望我这个实践能对大家有点点帮助,演示和源码都贴在后面. 二.技术架构 这两年a ...
- 【开源.NET】 分享一个前后端分离的轻量级内容管理框架
开发框架要考虑的面太多了:安全.稳定.性能.效率.扩展.整洁,还要经得起实践的考验,从零开发一个可用的框架,是很耗时费神的工作.网上很多开源的框架,为何还要自己开发?我是基于以下两点: 没找到合适的: ...
- java前后端分离是否会成为趋势
现在项目当中使用的是springboot+springcloud,这套框架也用了半年了,springboot是spring4.0的升级版,简化了springmvc的xml配置,是spring家族中目前 ...
- [开源] angularjs + Asp.net 前后端分离解决方案
本文版权归 博客园 萧秦 所有,此处为技术收藏,如有再转,请于篇头明显位置标明原创作者及出处,以示尊重! 作者:萧秦 原文:http://www.cnblogs.com/xqin/p/4862849. ...
- .NET Core前后端分离快速开发框架(Core.3.0+AntdVue)
.NET Core前后端分离快速开发框架(Core.3.0+AntdVue) 目录 引言 简介 环境搭建 开发环境要求 基础数据库构建 数据库设计规范 运行 使用教程 全局配置 快速开发 管理员登录 ...
- [转].NET Core前后端分离快速开发框架(Core.3.0+AntdVue)
[转].NET Core前后端分离快速开发框架(Core.3.0+AntdVue) 目录 引言 简介 环境搭建 开发环境要求 基础数据库构建 数据库设计规范 运行 使用教程 全局配置 快速开发 管理员 ...
- NET Core3前后端分离开发框架
NET Core前后端分离快速开发框架 https://www.cnblogs.com/coldairarrow/p/11870993.html 引言 时间真快,转眼今年又要过去了.回想今年,依次开源 ...
- 前后端分离Java后端主流开发环境框架20200622
开发环境: IDE:IntelliJ IDEA 2017+ DB: mysql5.7.4.PostgreSQL.mongoDB.redis JDK:JDK1.8+ Maven:Maven 3.2.3+ ...
- 前后端分离中,Gulp实现头尾等公共页面的复用
前言 通常我们所做的一些页面,我们可以从设计图里面看出有一些地方是相同的.例如:头部,底部,侧边栏等等.如果前后端分离时,制作静态页面的同学,对于这些重复的部分只能够通过复制粘贴到新的页面来,如果页面 ...
随机推荐
- Flink及Storm、Spark主流流框架比较
转自:http://www.sohu.com/a/142553677_804130 引言 随着大数据时代的来临,大数据产品层出不穷.我们最近也对一款业内非常火的大数据产品 - Apache Flink ...
- IntelliJ IDEA 超实用使用技巧分享
https://blog.csdn.net/weixin_38405253/article/details/102583954 知识点概览: 高效率配置 日常使用 必备快捷键(★★) 查找 跳转切换 ...
- IDEA 2019注册码(2020年4月过期)
IDEA 2019注册码(2020年4月过期) 812LFWMRSH-eyJsaWNlbnNlSWQiOiI4MTJMRldNUlNIIiwibGljZW5zZWVOYW1lIjoi5q2j54mII ...
- jetbrain 公司2019年全套产品的破解方案
百度网盘下载地址是:链接:https://pan.baidu.com/s/1E4E76Oglfexed0iHNiXjEQ 密码:pehx ======================== ...
- 使用redis作为调度中心的celery时启动多个queue,报错Probably the key ('_kombu.binding.reply.celery.pidbox') has been removed from the Redis database
我今天在使用celery启动多个queue时遇到一个问题,当启动第二个queue是,第一个启动的queue日志报了下面一段错误 [2019-12-16 14:40:25,736: ERROR/Main ...
- Unity3d—GUI能量条
1.打开Unity编辑器. 2.在脚本文件夹中添加C#脚本,我的是添加了skill_01这个脚本.(要自己设置文件夹,方便管理,不然文件添乱不方便管理) 3.注意,脚本的名字一旦确定就不要去改动,因为 ...
- [跨域问题]ssm+vue前后台分离跨域问题解决方法
跨域未解决时: Access to XMLHttpRequest at 'http://localhost:8080/vue/findall from origin 'http://localhost ...
- 用JavaScript带你体验V8引擎解析标识符
上一篇讲了字符串的解析过程,这一篇来讲讲标识符(IDENTIFIER)的解析. 先上知识点,标识符的扫描分为快解析和慢解析,一旦出现Ascii编码大于127的字符或者转义字符,会进入慢解析,略微影响性 ...
- 2019-11-29-WPF-绑定命令在-MVVM-的-CanExecute-和-Execute-在按钮点击都没触发可能的原因...
原文:2019-11-29-WPF-绑定命令在-MVVM-的-CanExecute-和-Execute-在按钮点击都没触发可能的原因... title author date CreateTime c ...
- Blend 设置一个圆形的按钮
原文:Blend 设置一个圆形的按钮 1)画一个圆形 右击构成控件 3)选择button 当然如果想做成别的控件 都可以 4)我们有了一个button 5)做动画 6)定义触发器 7)定义事件 效果