陈旧的开发模式

美工(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前后端分离的更多相关文章

  1. 【开源】分享一个前后端分离方案-前端angularjs+requirejs+dhtmlx 后端asp.net webapi

    一.前言 半年前左右折腾了一个前后端分离的架子,这几天才想起来翻出来分享给大家.关于前后端分离这个话题大家也谈了很久了,希望我这个实践能对大家有点点帮助,演示和源码都贴在后面. 二.技术架构 这两年a ...

  2. 【开源.NET】 分享一个前后端分离的轻量级内容管理框架

    开发框架要考虑的面太多了:安全.稳定.性能.效率.扩展.整洁,还要经得起实践的考验,从零开发一个可用的框架,是很耗时费神的工作.网上很多开源的框架,为何还要自己开发?我是基于以下两点: 没找到合适的: ...

  3. java前后端分离是否会成为趋势

    现在项目当中使用的是springboot+springcloud,这套框架也用了半年了,springboot是spring4.0的升级版,简化了springmvc的xml配置,是spring家族中目前 ...

  4. [开源] angularjs + Asp.net 前后端分离解决方案

    本文版权归 博客园 萧秦 所有,此处为技术收藏,如有再转,请于篇头明显位置标明原创作者及出处,以示尊重! 作者:萧秦 原文:http://www.cnblogs.com/xqin/p/4862849. ...

  5. .NET Core前后端分离快速开发框架(Core.3.0+AntdVue)

    .NET Core前后端分离快速开发框架(Core.3.0+AntdVue) 目录 引言 简介 环境搭建 开发环境要求 基础数据库构建 数据库设计规范 运行 使用教程 全局配置 快速开发 管理员登录 ...

  6. [转].NET Core前后端分离快速开发框架(Core.3.0+AntdVue)

    [转].NET Core前后端分离快速开发框架(Core.3.0+AntdVue) 目录 引言 简介 环境搭建 开发环境要求 基础数据库构建 数据库设计规范 运行 使用教程 全局配置 快速开发 管理员 ...

  7. NET Core3前后端分离开发框架

    NET Core前后端分离快速开发框架 https://www.cnblogs.com/coldairarrow/p/11870993.html 引言 时间真快,转眼今年又要过去了.回想今年,依次开源 ...

  8. 前后端分离Java后端主流开发环境框架20200622

    开发环境: IDE:IntelliJ IDEA 2017+ DB: mysql5.7.4.PostgreSQL.mongoDB.redis JDK:JDK1.8+ Maven:Maven 3.2.3+ ...

  9. 前后端分离中,Gulp实现头尾等公共页面的复用

    前言 通常我们所做的一些页面,我们可以从设计图里面看出有一些地方是相同的.例如:头部,底部,侧边栏等等.如果前后端分离时,制作静态页面的同学,对于这些重复的部分只能够通过复制粘贴到新的页面来,如果页面 ...

随机推荐

  1. CentOS7 SUDO 笔记--没配置sudoer,为什么有的账号能用sudo命令,有的不能用

    原来: 一.安装linux 创建的用户(管理员打钩)默认在 wheel组里. 1. 使用 cat /etc/passwd 查看用户所在组.中间那个数字是 groupid 不太好看 2.使用 cat / ...

  2. git账户配置

    一.生成github的ssh key ssh-keygen ssh-keygen -t rsa -f ~/.ssh/zzf073_rsa -C zzf073@163.com 二.配置账户公钥 1.查看 ...

  3. 剑指offer 栈的压入和弹出

    题目描述输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈 ...

  4. Regex 常见语法

    常用元字符 . 匹配除换行符以外的任意字符. \w 匹配字母或数字或下划线或汉字.\W 匹配任意不是字母,数字,下划线,汉字的字符. \s 匹配任意的空白符.\S 匹配任意不是空白符的字符.等价于 [ ...

  5. el-upload进度条无效,on-progress无效问题解决方案

    事先声明,本人系.net后端老菜鸟,vue接触没有多长时间,如果存在技术分享错误,切莫见怪,第一次写博,还请大佬们多多担待,转载请注明出处谢谢! 最近项目用到饿了么上传,于是参照官网接入el-uplo ...

  6. Mysql外键约束之CASCADE、SET NULL、RESTRICT、NO ACTION

    Mysql中有目前只有InnoDB引擎支持外键约束,InnoDB中外键约束定义的语法如下: ALTER TABLE tbl_name ADD [CONSTRAINT [symbol]] FOREIGN ...

  7. Django2.0版本以上与pymsql 不匹配问题以及解决方法

    Django2.0版本以上与pymsql 不匹配问题以及解决方法 Django 2.0 以上 如果使用pymysql0.93,需要一下两步操作: # 1 第一次报错信息: File "D:\ ...

  8. js中面向对象(创建对象的几种方式)

    1.面向对象编程(OOP)的特点: 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有的对象下继承出新的对象 多态:多对象的不同形态 注:本文引用于 http://www.cnblogs. ...

  9. ES6 变量与解构(二)

    一.变量的声明与使用 [测试示例需要在node环境中测试,浏览器环境下并不完全兼容ES6代码]ES6中可以使用 {} 来包含任意一段代码,被 {} 包裹的内容称为一个代码块(局部作用域) let关键字 ...

  10. 小程序动态设置style,使用内部数据