EasyUI实现工地领款单项目
- 环境搭建
引入jar、配置Spring MVC、web.xml、日志等
- 建表
- 自动生成MyBatis相关文件
mybatis-generator-core-1.3.2.jar
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfiguration 3 PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 6 <generatorConfiguration> 7 <context id="testTables" targetRuntime="MyBatis3"> 8 <commentGenerator> 9 <!-- 是否去除自动生成的注释 true:是 : false:否 --> 10 <property name="suppressAllComments" value="true" /> 11 </commentGenerator> 12 <!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> 13 <jdbcConnection driverClass="com.mysql.jdbc.Driver" 14 connectionURL="jdbc:mysql://localhost:3306/consite?useSSL=false" userId="root" 15 password="123456"> 16 </jdbcConnection> 17 <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 18 NUMERIC 类型解析为java.math.BigDecimal --> 19 <javaTypeResolver> 20 <property name="forceBigDecimals" value="false" /> 21 </javaTypeResolver> 22 23 <!-- targetProject:生成PO类的位置 --> 24 <javaModelGenerator targetPackage="org.zln.consite.domain" 25 targetProject="src/main/java"> 26 <!-- enableSubPackages:是否让schema作为包的后缀 --> 27 <property name="enableSubPackages" value="false" /> 28 <!-- 从数据库返回的值被清理前后的空格 --> 29 <property name="trimStrings" value="true" /> 30 </javaModelGenerator> 31 <!-- targetProject:mapper映射文件生成的位置 --> 32 <sqlMapGenerator targetPackage="org.zln.consite.mapper" 33 targetProject="src/main/resources"> 34 <!-- enableSubPackages:是否让schema作为包的后缀 --> 35 <property name="enableSubPackages" value="false" /> 36 </sqlMapGenerator> 37 <!-- targetPackage:mapper接口生成的位置 --> 38 <javaClientGenerator type="XMLMAPPER" 39 targetPackage="org.zln.consite.mapper" 40 targetProject="src/main/java"> 41 <!-- enableSubPackages:是否让schema作为包的后缀 --> 42 <property name="enableSubPackages" value="false" /> 43 </javaClientGenerator> 44 <!-- 指定数据库表 --> 45 <table schema="" tableName="T00_Dict"></table> 46 <table schema="" tableName="T00_User"></table> 47 <table schema="" tableName="T01_LKD"></table> 48 49 </context> 50 </generatorConfiguration>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import java.io.File; 2 import java.util.ArrayList; 3 import java.util.List; 4 5 import org.mybatis.generator.api.MyBatisGenerator; 6 import org.mybatis.generator.config.Configuration; 7 import org.mybatis.generator.config.xml.ConfigurationParser; 8 import org.mybatis.generator.internal.DefaultShellCallback; 9 10 public class GeneratorSqlmap { 11 12 public void generator() throws Exception{ 13 14 List<String> warnings = new ArrayList<>(); 15 boolean overwrite = true; 16 //指定 逆向工程配置文件 17 File configFile = new File("/Users/sherry/WorkPath/Git/lkd/consite/src/main/resources/generatorConfig.xml"); 18 System.out.println(configFile.getAbsolutePath()); 19 ConfigurationParser cp = new ConfigurationParser(warnings); 20 Configuration config = cp.parseConfiguration(configFile); 21 DefaultShellCallback callback = new DefaultShellCallback(overwrite); 22 MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,callback, warnings); 23 myBatisGenerator.generate(null); 24 25 } 26 public static void main(String[] args) throws Exception { 27 try { 28 GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap(); 29 generatorSqlmap.generator(); 30 } catch (Exception e) { 31 e.printStackTrace(); 32 } 33 34 } 35 36 }
- 首页跳转
输入http://ip:port/consite后,默认根据web.xml的配置,去跳转到index.jsp文件的,我这里再做一次跳转
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
String homePage = request.getContextPath();
%>
<script type="text/javascript">
var login = "<%=homePage%>/t00_CommonController/goPage.html?page=login";
console.log("跳转到登录页:"+login);
window.location.href = login;
</script>
相应的控制层代码如下
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package org.zln.consite.controller; 2 3 import org.slf4j.Logger; 4 import org.slf4j.LoggerFactory; 5 import org.springframework.stereotype.Controller; 6 import org.springframework.web.bind.annotation.RequestMapping; 7 import org.springframework.web.bind.annotation.RequestParam; 8 9 10 /** 11 * 通用控制器 12 * Created by sherry on 17/1/4. 13 */ 14 @Controller 15 @RequestMapping("/t00_CommonController") 16 public class T00_CommonController { 17 /** 18 * 日志 19 */ 20 private Logger logger = LoggerFactory.getLogger(T00_CommonController.class); 21 22 @RequestMapping(value = "/goPage.html", params = "page") 23 public String goPage(@RequestParam String page) { 24 logger.debug("跳转到:/WEB-INF/jsp/" + page + ".jsp"); 25 return page; 26 } 27 }
- 登陆界面
经过跳转后,首先进入登陆界面,如下
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %> 4 <% 5 String homePage = request.getContextPath(); 6 %> 7 <!DOCTYPE HTML> 8 <html> 9 <head> 10 <title>登陆</title> 11 <meta charset="UTF-8"/> 12 <link rel="stylesheet" type="text/css" href="<%=homePage%>/jslib/jquery-easyui-1.5/themes/default/easyui.css" 13 charset="utf-8"/> 14 <link rel="stylesheet" type="text/css" href="<%=homePage%>/jslib/jquery-easyui-1.5/themes/icon.css" 15 charset="utf-8"/> 16 <script type="text/javascript" src="<%=homePage%>/jslib/jquery-easyui-1.5/jquery.min.js" charset="utf-8"></script> 17 <script type="text/javascript" src="<%=homePage%>/jslib/jquery-easyui-1.5/jquery.easyui.min.js" 18 charset="utf-8"></script> 19 <script type="text/javascript" src="<%=homePage%>/jslib/jquery-easyui-1.5/locale/easyui-lang-zh_CN.js" 20 charset="utf-8"></script> 21 <style type="text/css"> 22 <%--右对齐--%> 23 td:first-of-type { 24 text-align: right 25 } 26 </style> 27 <script type="text/javascript"> 28 $(function () { 29 $("#dd").dialog({ 30 closable: false, 31 buttons: [ 32 { 33 text: "登陆", 34 handler: function () { 35 console.log("登陆"); 36 } 37 }, { 38 text: "重填", 39 handler: function () { 40 console.log("重填"); 41 } 42 } 43 ] 44 }); 45 }) 46 </script> 47 </head> 48 <body> 49 <%--登陆表单--%> 50 <form id="dd" class="easyui-dialog" title="登陆" style="width:250px;height:150px;" 51 data-options="resizable:true,modal:true" method="post"> 52 <table> 53 <tr> 54 <td>用户名</td> 55 <td> 56 <input type="text" name="username" class="easyui-validatebox" data-options="required:true"/> 57 </td> 58 </tr> 59 <tr> 60 <td>密码</td> 61 <td> 62 <input type="password" name="password" class="easyui-validatebox" data-options="required:true"> 63 </td> 64 </tr> 65 </table> 66 </form> 67 68 </body> 69 </html>
- 实现登陆与后台的交互
EasyUI登陆与表单重填
buttons: [
{
text: "登陆",
handler: function () {
console.log("登陆");
$("#dd").form("submit", {
url: "<%=homePage%>/t00_UserController/login.ajax"
, success: function (data) {
data = JSON.parse(data);
if ("0" == data.st) {
console.log("登陆成功");
$.messager.show({
title: '提示',
msg: '登陆成功',
timeout: 5000,
showType: 'slide'
});
$("#dd").dialog("close");
} else {
console.log("登陆失败");
$.messager.alert('警告', "登陆失败", "warning");
}
}
})
}
}, {
text: "重填",
handler: function () {
console.log("重填");
$("#dd :input")
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
}
}
]
后台代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package org.zln.consite.controller; 2 3 import org.slf4j.Logger; 4 import org.slf4j.LoggerFactory; 5 import org.springframework.stereotype.Controller; 6 import org.springframework.web.bind.annotation.RequestMapping; 7 import org.springframework.web.bind.annotation.RequestParam; 8 import org.springframework.web.bind.annotation.ResponseBody; 9 10 import java.util.HashMap; 11 import java.util.Map; 12 13 /** 14 * Created by sherry on 17/1/4. 15 */ 16 @Controller 17 @RequestMapping("/t00_UserController") 18 public class T00_UserController { 19 20 /** 21 * 日志 22 */ 23 private Logger logger = LoggerFactory.getLogger(T00_UserController.class); 24 25 @RequestMapping("/login.ajax") 26 @ResponseBody 27 public Map<String, String> login(@RequestParam Map<String, String> map) { 28 Map<String, String> map1 = new HashMap<>(); 29 logger.debug("登陆参数:"+map); 30 if ("admin".equalsIgnoreCase(map.get("username"))){ 31 map1.put("st","0"); 32 }else { 33 map1.put("st","-1"); 34 } 35 logger.debug("返回:"+map1); 36 return map1; 37 } 38 }
- 工作界面
接下去的更新,见
https://git.oschina.net/sherryBy/lkd.git