公司用了这个叫做jeecg的快速开发框架,我不知道有多少公司在用这个框架,园子里有的可以吱一声。个人觉得这框架唯一优势就是可以让不会ssh的人也能进行开发,只要你会J2SE,有web后台发开经验即可。
框架的优劣这里不做说明,但是官方文档真的写的很粗糙,很多时候需要自己额外添加一些功能的时候会有一点无处下手的感觉。接触了一段时间后,也踩了不少的坑,现在记录一下,以飨读者。
jeecg版本:3.7.1
1.跨域过滤器
public class CorsFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Appkey"); filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { } } <!-- web.xml中配置--> <filter> <filter-name>cors</filter-name> <filter-class>cn.crenative.afloan.core.controller.CorsFilter</filter-class> </filter> <filter-mapping> <filter-name>cors</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>2.文件上传
@RequestMapping(params = "doUpload", method = RequestMethod.POST) @ResponseBody public AjaxJson doUpload(MultipartHttpServletRequest request, String path) { logger.info("后台上传文件"); AjaxJson j = new AjaxJson(); String fileName = null; String ctxPath = request.getSession().getServletContext().getRealPath(path); File file = new File(ctxPath); if (!file.exists()) { file.mkdir();// 创建文件根目录 } Map<String, MultipartFile> fileMap = request.getFileMap(); for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { MultipartFile mf = entity.getValue();// 获取上传文件对象 fileName = mf.getOriginalFilename();// 获取文件名 String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt; String savePath = file.getPath() + "/" + newFileName;// 上传后的文件绝对路径 System.out.println("上传后路径:" + savePath); File savefile = new File(savePath); try { // String imageUrl = "http://" + request.getServerName() + ":" + request.getLocalPort() + request.getContextPath() + path + "/" + newFileName; String imageUrl = request.getContextPath() + path + "/" + newFileName; logger.info("输出路径:" + imageUrl); mf.transferTo(savefile); j.setObj(imageUrl); } catch (IOException e) { e.printStackTrace(); } } j.setMsg("上传成功"); return j; } <t:webUploader url="upload.do?doUpload&path=[相对路径]" name="[数据库字段]" extensions="" auto="true" pathValues="${后端set的attribute名称}"/> <!-- eg:--> <t:webUploader url="upload.do?doUpload&path=/upload/afloan/users/attachment" name="credentialPhoto" extensions="" auto="true" pathValues="${attachmentPage.credentialPhoto}"/>3.dictSelect
<t:dictSelect field="credentialType" type="select" defaultVal="${attachmentPage.credentialType}" typeGroupCode="attachment" hasLabel="false"/>4.全局表单元素的隐藏
$(":input").attr("disabled", "true"); $('select').attr('disabled', true);5.添加一个提示的窗口
layer.open({ title: title, //弹窗title content: content, //弹窗内容 icon: 7, yes: function (index) { //回调函数 }, btn: ['确定', '取消'], btn2: function (index) { layer.close(index); } });6.选择datagrid中选中的行。
var rowsData = $('#' + id).datagrid('getSelections'); //获取具体的字段名,推荐第二种取值形式,如果使用一对多,name字段名可能长这样(user.id),使用第一种方式会报错 console.log(rowData[0].fieldname) console.log(rowData[0]['fieldname')7. 选择datagrid中选中的行
// 在方法中添加index,控件会自动添加选择的行号 <t:dgFunOpt title="删除" funname="deleteOne()" urlclass="ace_button" urlfont="fa-trash-o"/> function deleteOne(index) { console.log(index); var row = $("#usersList").datagrid('getData').rows[index]; }8.添加一个新的标签页
//function addOneTab(subtitle, url, icon),该方法定义在curdtools_zh-cn.js中 function openAuditTab(id, mobile) { addOneTab("用户" + mobile + "的档案", "userInfo?userInfo&mode=claim&userId=" + id); }9.popup,弹框选择相应的记录,并回调到父页面。
//设置表单内容 function setUser(obj, rowTag, selected) { if (selected == '' || selected == null) { alert("请选择"); return false; } else { var str = ""; var name = ""; var idNo = ""; $.each(selected, function (i, n) { str += n.mobile; name += n.realName; idNo += n.idcardNo; }); $("input[id='" + rowTag + ".mobile']").val(str); $("input[id='" + rowTag + ".realName']").val(name); $("input[id='" + rowTag + ".idcardNo']").val(idNo); return true; } } /** * 弹出popup窗口获取 * @param obj * @param rowTag 行标记 * @param code 动态报表配置ID */ function selectUser(obj, rowTag) { if (rowTag == null) { alert("popup参数配置不全"); return; } console.log($('#mobile').val()); var inputClickUrl = basePath + "/users?userSelect"; if (typeof (windowapi) == 'undefined') { //页面弹出popup $.dialog({ content: "url:" + inputClickUrl, zIndex: getzIndex(), lock: true, title: "选择客户", width: 1000, height: 300, cache: false, ok: function () { iframe = this.iframe.contentWindow; var selected = iframe.getSelectRows(); //重要,此处获取行数据 return setUserMobile(obj, rowTag, selected); }, cancelVal: '关闭', cancel: true //为true等价于function(){} }); } else { //popup内弹出popup $.dialog({ content: "url:" + inputClickUrl, zIndex: getzIndex(), lock: true, title: "选择客户", width: 1000, height: 300, parent: windowapi, //设置弹出popup的openner cache: false, ok: function () { iframe = this.iframe.contentWindow; var selected = iframe.getSelectRows(); //重要,此处获取行数据 return setUserMobile(obj, rowTag, selected); }, cancelVal: '关闭', cancel: true //为true等价于function(){} }); } } <!-- 方法绑定 --> <input class="inputxt" onclick="selectUser(this,'user');" placeholder="点击选择客户" id="user.mobile" name="appUser.mobile" value="${borrowInfoPage.appUser.mobile}"/>10.一对多关系的使用
具体例子:借款订单(afl_borrow_info)中存在用户表(afl_user)外键,通过user_id关联。
@Entity @Table(name = "afl_borrow_info", schema = "") @DynamicUpdate(true) @DynamicInsert(true) @SuppressWarnings("serial") public class BorrowInfoEntity implements java.io.Serializable { private UsersEntity appUser; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "user_id") public UsersEntity getAppUser() { return appUser; } public void setAppUser(UsersEntity appUser) { this.appUser = appUser; } }关联之后,所有的查询(service层)和页面渲染(jsp),均不再使用user_id而是使用appUser.id,别的字段同理。
本作品采用 知识共享署名 3.0 中国大陆许可协议进行许可。欢迎转载,演绎或用于商业目的,但是必须保留本文的署名 Fururur(包含链接),如您有任何疑问或者授权方面的协商,请给我留言。转载于:https://www.cnblogs.com/Jeely/p/11310356.html
相关资源:JAVA上百实例源码以及开源项目