jquery Temp jsonToAction

来源:互联网 发布:全局搜索能力强的算法 编辑:程序博客网 时间:2024/06/06 04:28
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><link href="css/bootstraped.min.css" rel="stylesheet" media="screen"/><script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><script type="text/javascript" src="js/demo_ajax_json.js"></script><script src="js/jquery.tmpl.min.js"></script> </head><body><form action="departmentSelect.action" class="form-search">部门名:<input type="text" name="departmentPVO.deptName" id="departmentQuery" class="input-medium search-query"><button type="button" class="btn" onclick="ajaxQuery()">查询</button></form><input type="button" class="btn" value="新增" onclick="location.href='toAdd.action'"/> <script type="text/zskx-tmpl" id="tmpl"><tr><td>${deptId}</td><td>${createTime}</td><td>${modifyTime}</td><td>${deptName}</td><td><a href="departmentUpdate.action">修改</a>      <a href="departmentDelete.action">删除</a></td></tr></script>  <table  class="table table-hover"><thead><tr>    <th><b>部门ID</b></th><th><b>创建时间</b></th> <th><b>修改时间</b></th> <th><b>部门名称</b></th><th><b>操作</b></th></tr></thead><tbody id='context'></tbody></table>   <script type="text/javascript">    jQuery(document).ready(function($){   $.getJSON("departmentPVOShowJson.action",function(json){   console.log(json); console.log($('#tmpl').tmpl(json).appendTo('#context'));});      console.log("in ready...");});    function ajaxQuery(){    var par = $("#departmentQuery").val();                $.getJSON("departmentSelectJson.action?deptName="+par,function(json){    console.log(json);    $("#context").text("");    console.log($("#tmpl").tmpl(json).appendTo("#context"));    });    }</script></body></html




public void showDeptJson() {logger.info("showDeptJson in...");List<DepartmentPVO> list = departmentPVOService.selectDepartment();JSONArray array = new JSONArray();for (DepartmentPVO d : list) {JSONObject jo = new JSONObject();jo.put("deptId", d.getDeptId());jo.put("createTime", d.getCreateTime().toString());jo.put("modifyTime", d.getModifyTime().toString());jo.put("deptName", d.getDeptName());array.add(jo);}logger.info(array.toString());try {response.setContentType("text/html");response.setCharacterEncoding("UTF-8");response.getWriter().write(array.toString());} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}