1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>数据</title>
  6. <link rel="stylesheet" href="static/css/style.css" type="text/css">
  7. <!-- jQuery-easyUI start -->
  8. <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
  9. <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
  10. <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/color.css">
  11. <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
  12. <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  13. <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
  14. <!-- jQuery-easyUI end -->
  15. <script type="text/javascript">
  16. document.createElement("section");
  17. document.createElement("article");
  18. document.createElement("footer");
  19. document.createElement("header");
  20. document.createElement("hgroup");
  21. document.createElement("nav");
  22. document.createElement("menu");
  23. </script>
  24. <script type="text/javascript">
  25. function Save() {
  26. document.getElementById("PageOfficeCtrl1").WebSave();
  27. }
  28. </script>
  29. </head>
  30. <body>
  31. <header>
  32. <div class="w12 header">
  33. <a class="db logo fl"><img src="static/images/logo.jpg"
  34. width="327" height="94" alt="" />
  35. </a>
  36. <div class="fr logofr">
  37. <a href="#" class="blk">返回首页</a> |<a href="#" class="blk">客服中心</a><br>
  38. 如注册遇到问题请拨打:<strong style="font-size:14px;">400-000-0000</strong>
  39. </div>
  40. </div>
  41. </header>
  42. <div class="head_border"></div>
  43. <section class="w12 login"> <em class="fr">当前用户:张三 </em> </section>
  44. <section class="main w12">
  45. <div class="title">
  46. <a class="title1 db fl">审核报告</a><a class="title2 db fl">审核合同</a>
  47. </div>
  48. <div class="fr tit2">
  49. <span class="arr"></span>
  50. </div>
  51. </section>
  52. <br /><br />
  53. <div style="text-align:content;margin-left: 300px;">
  54. <table id="dg" title="北京某某科技有限公司" class="easyui-datagrid" style="width:700px;height:250px;,margin: auto;"
  55. url="get_users.php" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true">
  56. <thead>
  57. <tr id="insertSpareEpt">
  58. <th field="firstname" width="50">单位编号</th>
  59. <th field="lastname" width="50">单位名称</th>
  60. <th field="phone" width="50">单位性质</th>
  61. <th field="email" width="50">单位地址</th>
  62. </tr>
  63. </thead>
  64. </table>
  65. </div>
  66. <div id="toolbar">
  67. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">添加</a>
  68. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
  69. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
  70. </div>
  71. <div id="divTab"></div>
  72. <!-- 弹窗 -->
  73. <div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:\'thin\',buttons:\'#dlg-buttons\'">
  74. <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
  75. <h3>单位信息</h3>
  76. <div style="margin-bottom:10px">
  77. <input name="firstname" class="easyui-textbox" required="true" label="单位编号:" style="width:100%">
  78. </div>
  79. <div style="margin-bottom:10px">
  80. <input name="lastname" class="easyui-textbox" required="true" label="单位名称:" style="width:100%">
  81. </div>
  82. <div style="margin-bottom:10px">
  83. <input name="phone" class="easyui-textbox" required="true" label="单位性质:" style="width:100%">
  84. </div>
  85. <div style="margin-bottom:10px">
  86. <input name="email" class="easyui-textbox" required="true" validType="email" label="单位地址:" style="width:100%">
  87. </div>
  88. </form>
  89. </div>
  90. <div id="dlg-buttons">
  91. <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">添加</a>
  92. <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$(\'#dlg\').dialog(\'close\')" style="width:90px">取消</a>
  93. </div>
  94. <script type="text/javascript">
  95. var url;
  96. function newUser(){
  97. $(\'#dlg\').dialog(\'open\').dialog(\'center\').dialog(\'setTitle\',\'New User\');
  98. $(\'#fm\').form(\'clear\');
  99. url = \'save_user.php\';
  100. }
  101. function editUser(){
  102. var row = $(\'#dg\').datagrid(\'getSelected\');
  103. if (row){
  104. $(\'#dlg\').dialog(\'open\').dialog(\'center\').dialog(\'setTitle\',\'Edit User\');
  105. $(\'#fm\').form(\'load\',row);
  106. url = \'update_user.php?id=\'+row.id;
  107. }
  108. }
  109. function saveUser1(){
  110. $(\'#fm\').form(\'submit\',{
  111. url: saveInfo,
  112. onSubmit: function(){
  113. return $(this).form(\'validate\');
  114. },
  115. success: function(result){
  116. var result = eval(\'(\'+result+\')\');
  117. if (result.errorMsg){
  118. $.messager.show({
  119. title: \'Error\',
  120. msg: result.errorMsg
  121. });
  122. } else {
  123. $(\'#dlg\').dialog(\'close\'); // close the dialog
  124. $(\'#dg\').datagrid(\'reload\'); // reload the user data
  125. }
  126. }
  127. });
  128. }
  129. /* 保存 */
  130. function saveUser(){
  131. var info;
  132. var firstname = $("input[name=\'firstname\']").val();
  133. var lastname = $("input[name=\'lastname\']").val();
  134. var phone = $("input[name=\'phone\']").val();
  135. var email = $("input[name=\'email\']").val();
  136. $.ajax({
  137. type : \'get\',
  138. url : \'saveInfo\',
  139. data:{
  140. "firstname":firstname,
  141. "lastname":lastname,
  142. "phone":phone,
  143. "email":email
  144. },
  145. cache : false,
  146. async : false,
  147. dataType : \'json\',
  148. success : function(data){
  149. $("#dg").datagrid("loadData",data);// 数据加载jQuery easyUI表格中
  150. /* var tabStr = "";
  151. $.each(data, function(index,value){
  152. var item = data[index];
  153. var itemFirstname = item.firstname;
  154. var itemLastname = item.lastname;
  155. var itemPhone = item.phone;
  156. var itemEmail = item.email;
  157. var itemStr = "<table border=\'1\' cellpadding=\'0\' cellspacing=\'0\'><tr>"+
  158. "<td name=\'firstname\' width=50>"+itemFirstname+"</td>"+
  159. "<td name=\'lastname\' width=50>"+itemLastname+"</td>"+
  160. "<td name=\'phone\' width=50>"+itemPhone+"</td>"+
  161. "<td name=\'email\' width=50>"+itemEmail+"</td>"+
  162. "</tr></table>";
  163. tabStr += itemStr;
  164. })
  165. document.getElementById("divTab").innerHTML = tabStr; */
  166. } , error:function(data){
  167. alert("加载数据失败!"+data);
  168. }
  169. });
  170. // 关闭添加窗口
  171. $(\'#dlg\').dialog(\'close\');
  172. }
  173. function destroyUser(){
  174. var row = $(\'#dg\').datagrid(\'getSelected\');
  175. if (row){
  176. $.messager.confirm(\'Confirm\',\'Are you sure you want to destroy this user?\',function(r){
  177. if (r){
  178. $.post(\'destroy_user.php\',{id:row.id},function(result){
  179. if (result.success){
  180. $(\'#dg\').datagrid(\'reload\'); // reload the user data
  181. } else {
  182. $.messager.show({ // show error message
  183. title: \'Error\',
  184. msg: result.errorMsg
  185. });
  186. }
  187. },\'json\');
  188. }
  189. });
  190. }
  191. }
  192. </script>
  193. </body>
  194. </html>
  195. package com.wyebd.controller;
  196. import java.sql.Connection;
  197. import java.sql.DriverManager;
  198. import java.sql.PreparedStatement;
  199. import java.sql.ResultSet;
  200. import java.sql.SQLException;
  201. import java.sql.Statement;
  202. import java.util.ArrayList;
  203. import java.util.List;
  204. import java.util.Map;
  205. import javax.servlet.http.HttpServletRequest;
  206. import javax.servlet.http.HttpServletResponse;
  207. import org.apache.log4j.Logger;
  208. import org.springframework.web.bind.annotation.RequestMapping;
  209. import org.springframework.web.bind.annotation.RequestMethod;
  210. import org.springframework.web.bind.annotation.RestController;
  211. import org.springframework.web.servlet.ModelAndView;
  212. import com.alibaba.fastjson.JSON;
  213. import com.wyebd.bean.Contract;
  214. import com.zhuozhengsoft.pageoffice.OpenModeType;
  215. import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
  216. import com.zhuozhengsoft.pageoffice.wordwriter.WordDocument;
  217. @RestController
  218. public class ReadDataController {
  219. private static Logger log = Logger.getLogger(ReadOnlyController.class);
  220. private final String DB_URL = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8";
  221. private static final String USER = "root";
  222. private static final String PASS = "root";
  223. private static Connection con = null;
  224. private static PreparedStatement ps = null;
  225. private static Statement stmt = null;
  226. private static ResultSet rs = null;
  227. /**
  228. * 跳转至查询页面
  229. * @param request
  230. * @param response
  231. * @param map
  232. * @return
  233. */
  234. @RequestMapping(value = "/readData", method = RequestMethod.GET)
  235. public ModelAndView readData() {
  236. ModelAndView mv = new ModelAndView("readData");
  237. return mv;
  238. }
  239. /**
  240. * 保存
  241. * @param request
  242. * @param response
  243. * @param map
  244. * @return
  245. */
  246. @RequestMapping("saveInfo")
  247. public String saveInfo(HttpServletRequest request, HttpServletResponse response, Map<String, Object> map) {
  248. List<Contract> list = new ArrayList<Contract>();
  249. String firstname = request.getParameter("firstname");
  250. String lastname = request.getParameter("lastname");
  251. String phone = request.getParameter("phone");
  252. String email = request.getParameter("email");
  253. String json = null;
  254. int id = 0;
  255. try {
  256. getConnection();
  257. ps = con.prepareStatement("insert into test values (?,?,?,?,?)");
  258. ps.setInt(1, id);
  259. ps.setString(2, firstname);
  260. ps.setString(3, lastname);
  261. ps.setString(4,phone);
  262. ps.setString(5, email);
  263. ps.executeUpdate();
  264. log.info("添加成功");
  265. rs = stmt.executeQuery("select * from test");
  266. while(rs.next()){
  267. Contract con = new Contract();
  268. con.setFirstname(rs.getString("firstname"));
  269. con.setLastname(rs.getString("lastname"));
  270. con.setPhone(rs.getString("phone"));
  271. con.setEmail(rs.getString("email"));
  272. list.add(con);
  273. }
  274. // list转为json传入前端
  275. json = JSON.toJSONString(list);
  276. log.info(json);
  277. // 取得流向JSP传递数据
  278. response.setContentType("text/html;charset=UTF-8");
  279. response.getWriter().println(json);
  280. response.reset();
  281. } catch (Exception e) {
  282. log.info("SQLException: " + e.getMessage());
  283. e.printStackTrace();
  284. } finally {
  285. try {
  286. ps.close();
  287. con.close();
  288. } catch (SQLException e) {
  289. e.printStackTrace();
  290. }
  291. }
  292. return json;
  293. }
  294. /**
  295. * 连接数据库
  296. * @throws ClassNotFoundException
  297. * @throws SQLException
  298. */
  299. public void getConnection() throws ClassNotFoundException, SQLException {
  300. try {
  301. Class.forName("com.mysql.jdbc.Driver");
  302. con = DriverManager.getConnection(DB_URL, USER, PASS);
  303. stmt = con.createStatement();
  304. } catch (Exception e) {
  305. System.out.println("SQLException: " + e.getMessage());
  306. e.printStackTrace();
  307. }
  308. }
  309. }

 

版权声明:本文为hongwei2085原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/hongwei2085/p/9058535.html