<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据</title>
<link rel="stylesheet" href="static/css/style.css" type="text/css">
<!-- jQuery-easyUI start -->
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/color.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<!-- jQuery-easyUI end -->
<script type="text/javascript">
document.createElement("section");
document.createElement("article");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("nav");
document.createElement("menu");
</script>
<script type="text/javascript">
function Save() {
document.getElementById("PageOfficeCtrl1").WebSave();
}
</script>
</head>
<body>
<header>
<div class="w12 header">
<a class="db logo fl"><img src="static/images/logo.jpg"
width="" height="" alt="" />
</a>
<div class="fr logofr">
<a href="#" class="blk">返回首页</a> |<a href="#" class="blk">客服中心</a><br>
如注册遇到问题请拨打:<strong style="font-size:14px;">--</strong>
</div>
</div>
</header>
<div class="head_border"></div>
<section class="w12 login"> <em class="fr">当前用户:张三 </em> </section>
<section class="main w12">
<div class="title">
<a class="title1 db fl">审核报告</a><a class="title2 db fl">审核合同</a>
</div>
<div class="fr tit2">
<span class="arr"></span>
</div>
</section>
<br /><br /> <div style="text-align:content;margin-left: 300px;">
<table id="dg" title="北京某某科技有限公司" class="easyui-datagrid" style="width:700px;height:250px;,margin: auto;"
url="get_users.php" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr id="insertSpareEpt">
<th field="firstname" width="">单位编号</th>
<th field="lastname" width="">单位名称</th>
<th field="phone" width="">单位性质</th>
<th field="email" width="">单位地址</th>
</tr>
</thead>
</table>
</div> <div id="toolbar">
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">添加</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
</div>
<div id="divTab"></div>
<!-- 弹窗 -->
<div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
<form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
<h3>单位信息</h3>
<div style="margin-bottom:10px">
<input name="firstname" class="easyui-textbox" required="true" label="单位编号:" style="width:100%">
</div>
<div style="margin-bottom:10px">
<input name="lastname" class="easyui-textbox" required="true" label="单位名称:" style="width:100%">
</div>
<div style="margin-bottom:10px">
<input name="phone" class="easyui-textbox" required="true" label="单位性质:" style="width:100%">
</div>
<div style="margin-bottom:10px">
<input name="email" class="easyui-textbox" required="true" validType="email" label="单位地址:" style="width:100%">
</div>
</form>
</div>
<div id="dlg-buttons">
<a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">添加</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div> <script type="text/javascript">
var url;
function newUser(){
$('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
$('#fm').form('clear');
url = 'save_user.php';
}
function editUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
$('#fm').form('load',row);
url = 'update_user.php?id='+row.id;
}
}
function saveUser1(){
$('#fm').form('submit',{
url: saveInfo,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.errorMsg){
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
} /* 保存 */
function saveUser(){
var info;
var firstname = $("input[name='firstname']").val();
var lastname = $("input[name='lastname']").val();
var phone = $("input[name='phone']").val();
var email = $("input[name='email']").val();
$.ajax({
type : 'get',
url : 'saveInfo',
data:{
"firstname":firstname,
"lastname":lastname,
"phone":phone,
"email":email
},
cache : false,
async : false,
dataType : 'json',
success : function(data){
$("#dg").datagrid("loadData",data);// 数据加载jQuery easyUI表格中 /* var tabStr = "";
$.each(data, function(index,value){
var item = data[index];
var itemFirstname = item.firstname;
var itemLastname = item.lastname;
var itemPhone = item.phone;
var itemEmail = item.email;
var itemStr = "<table border='1' cellpadding='0' cellspacing='0'><tr>"+
"<td name='firstname' width=50>"+itemFirstname+"</td>"+
"<td name='lastname' width=50>"+itemLastname+"</td>"+
"<td name='phone' width=50>"+itemPhone+"</td>"+
"<td name='email' width=50>"+itemEmail+"</td>"+
"</tr></table>";
tabStr += itemStr;
})
document.getElementById("divTab").innerHTML = tabStr; */ } , error:function(data){
alert("加载数据失败!"+data);
}
});
// 关闭添加窗口
$('#dlg').dialog('close');
} function destroyUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
if (r){
$.post('destroy_user.php',{id:row.id},function(result){
if (result.success){
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.errorMsg
});
}
},'json');
}
});
}
}
</script>
</body>
</html> package com.wyebd.controller; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.wyebd.bean.Contract;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.zhuozhengsoft.pageoffice.wordwriter.WordDocument; @RestController
public class ReadDataController { private static Logger log = Logger.getLogger(ReadOnlyController.class);
private final String DB_URL = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8";
private static final String USER = "root";
private static final String PASS = "root";
private static Connection con = null;
private static PreparedStatement ps = null;
private static Statement stmt = null;
private static ResultSet rs = null; /**
* 跳转至查询页面
* @param request
* @param response
* @param map
* @return
*/
@RequestMapping(value = "/readData", method = RequestMethod.GET)
public ModelAndView readData() {
ModelAndView mv = new ModelAndView("readData");
return mv;
} /**
* 保存
* @param request
* @param response
* @param map
* @return
*/
@RequestMapping("saveInfo")
public String saveInfo(HttpServletRequest request, HttpServletResponse response, Map<String, Object> map) {
List<Contract> list = new ArrayList<Contract>();
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String phone = request.getParameter("phone");
String email = request.getParameter("email");
String json = null;
int id = ;
try {
getConnection();
ps = con.prepareStatement("insert into test values (?,?,?,?,?)");
ps.setInt(, id);
ps.setString(, firstname);
ps.setString(, lastname);
ps.setString(,phone);
ps.setString(, email);
ps.executeUpdate();
log.info("添加成功");
rs = stmt.executeQuery("select * from test");
while(rs.next()){
Contract con = new Contract();
con.setFirstname(rs.getString("firstname"));
con.setLastname(rs.getString("lastname"));
con.setPhone(rs.getString("phone"));
con.setEmail(rs.getString("email"));
list.add(con);
}
// list转为json传入前端
json = JSON.toJSONString(list);
log.info(json);
// 取得流向JSP传递数据
response.setContentType("text/html;charset=UTF-8");
response.getWriter().println(json);
response.reset();
} catch (Exception e) {
log.info("SQLException: " + e.getMessage());
e.printStackTrace();
} finally {
try {
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return json;
} /**
* 连接数据库
* @throws ClassNotFoundException
* @throws SQLException
*/
public void getConnection() throws ClassNotFoundException, SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = con.createStatement();
} catch (Exception e) {
System.out.println("SQLException: " + e.getMessage());
e.printStackTrace();
}
} }

ajax异步加载查询数据库的更多相关文章

  1. 淘宝购物车页面 智能搜索框Ajax异步加载数据

    如果有朋友对本篇文章的一些知识点不了解的话,可以先阅读此篇文章.在这篇文章中,我大概介绍了一下构建淘宝购物车页面需要的基础知识. 这篇文章主要探讨的是智能搜索框Ajax异步加载数据.jQuery的社区 ...

  2. Scrapy爬虫框架教程(四)-- 抓取AJAX异步加载网页

    欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章 sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction ...

  3. jQuery的AJax异步加载

    主要用到load()方法以及getScript()方法,具体以一个例子说明: 在现有html文件中加载一个拟好的片段,以及在片段加载完成之前阻止用户进一步操作的弹出框. 首先是现有html代码,无任何 ...

  4. ajax异步加载问题

    使用ajax异步加载数据,在之后需要用到这个数据时,应该将之后的js一并写入ajax函数中,否则后面的js不能找到动态拼接的dom节点. 或者将其封装成方法,在ajax动态加载数据的最后调用该方法.

  5. Ajax 异步加载

    AJAX (Asynchronous JavaScript and XML,异步的 JavaScript 和 XML).它不是新的编程语言,而是一种使用现有标准的新方法,是在不重新加载整个页面的情况下 ...

  6. 使用Ajax异步加载页面时,怎样调试该页面的Js

    前言-本人不是干前端的,所以有的名词不专业 在前端中,有时候会遇到这样的框架,http://172.17.11.151:8060/frontend/backend.html#1.html (通过解析U ...

  7. ajax异步加载回跳定位

    1)首先,问题是这样的:page1在一个滚动到页面底部加载更新的函数(功能),当页面滚动了第二页(或更多页)时,点击链接跳转到了其他页面(page2),在page2有返回按钮,当从page2返回pag ...

  8. AJAX异步加载

    AJAX含义: 即"Asynchronous Javascript And XML"(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX可以跨 ...

  9. ajax 异步加载显示等待效果

    css: #loading { width:170px; height:25px; border:3px solid #C3DAF9; position:absolute; top:300px; le ...

随机推荐

  1. Jquery 控制table中的checkbox 相关选中事件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Mysql学习(二)之通过homebrew安装mysql后,为什么在系统偏好设置里没有mysql

    原因 用brew install packagename是用来安装命令行工具的,一般不可能影响到图形界面. mysql官方文档是通过dmg文件安装的: The MySQL Installation P ...

  3. 禁止缩放meta标签

    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale= ...

  4. iOS去掉字符串中的HTML标签的方法

    方法一.NSScanner去除标签 - (NSString *)removeTheHtmlFromString:(NSString *)htmlString { NSScanner * scanner ...

  5. Delphi Edit组件

  6. 安全专家发现GE Multilin SR的一个关键漏洞对全球电网构成严重威胁。

    A team of researchers from New York University has found a serious vulnerability in some of GE Multi ...

  7. Python enumerate 使用技巧

    enumerate() 是Python内建的函数,能让打印的结果更清晰,不管是列表,元组,字典,enumerate()都可以帮你完成,在某些需求下还是非常好用的. >>> a = [ ...

  8. fastai 核心部件

    1.ImageDataBunch 对数据封装的很好,包括预处理都在这里面完成了 2.models 现有模型及权重 2-1  create_body 可以用来获取现有模型的主体结构 2-2 create ...

  9. [易学易懂系列|rustlang语言|零基础|快速入门|(14)|Impls & Traits实现与特征]

    [易学易懂系列|rustlang语言|零基础|快速入门|(14)] 有意思的基础知识 Impls & Traits实现与特征 我之前说到的struct结构体,其实就类似于面向对象语言中的类cl ...

  10. Python CGI编程Ⅳ

    使用POST方法传递数据 使用POST方法向服务器传递数据是更安全可靠的,像一些敏感信息如用户密码等需要使用POST传输数据. 以下同样是hello_get.py ,它也可以处理浏览器提交的POST表 ...