1.頁面傳遞來的參數的默認值。返回的參數也是轉化爲json形式javascript
@RequestMapping("/item/cat/list")
@ResponseBody
public List<EasyUITreeNode> list(@RequestParam(value="id", defaultValue = "0") Long parentId) {
List<EasyUITreeNode> itemCatList = itemCatService.getItemCatList(parentId);
return itemCatList;
}css
2.html
@RequestMapping("/{page}")
public String showIndex(@PathVariable String page){
return page;
}java
3.properties文件中定義的常量jquery
@Value("${IMAGE_SERVER_URL}")
private String IMAGE_SERVER_URL;ajax
4.json
//返回一個json,json中有一個error,url;error,message
@RequestMapping(value="/pic/upload",produces=MediaType.TEXT_PLAIN_VALUE+";charset=utf-8")
@ResponseBody
public String picUpLoad(MultipartFile uploadFile){
try {
System.out.println("aaa");
//接收頁面上傳的文件
byte[] content = uploadFile.getBytes();
//去文件的擴展名
String filename = uploadFile.getOriginalFilename();
String ext = filename.substring(filename.lastIndexOf(".")+1);
//把文件內容上傳到圖片服務器
FastDFSClient fastDFSClient = new FastDFSClient("classpath:resource/fast_dfs.conf");
//從配置文件中取圖片服務器的url
String url = fastDFSClient.uploadFile(content, ext);
//設置建立返回結果對象
Map map = new HashMap();
map.put("error", 0);
map.put("url", IMAGE_SERVER_URL+url);
//返回結果
return JsonUtils.objectToJson(map);
} catch (Exception e) {
Map map = new HashMap();
map.put("error", 1);
map.put("message", "圖片上傳失敗");
return JsonUtils.objectToJson(map);
}
}服務器
5.cookie
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加業務受理單</title>
<!-- 導入jquery核心類庫 -->
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 導入easyui類庫 -->
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("body").css({visibility:"visible"});
// 對save按鈕條件 點擊事件
$('#save').click(function(){
// 對form 進行校驗
if($('#noticebillForm').form('validate')){
$('#noticebillForm').submit();
}
});
});
</script>
</head>
<body class="easyui-layout" style="visibility:hidden;">
<div region="north" style="height:31px;overflow:hidden;" split="false"
border="false">
<div class="datagrid-toolbar">
<a id="save" icon="icon-save" href="#" class="easyui-linkbutton"
plain="true">新單</a>
<a id="edit" icon="icon-edit" href="${pageContext.request.contextPath }/page_qupai_noticebill.action" class="easyui-linkbutton"
plain="true">工單操做</a>
</div>
</div>
<div region="center" style="overflow:auto;padding:5px;" border="false">
<form id="noticebillForm" action="${pageContext.request.contextPath }/noticebillAction_save.action" method="post">
<table class="table-edit" width="95%" align="center">
<tr class="title">
<td colspan="4">客戶信息</td>
</tr>
<tr>
<td>來電號碼:</td>
<script>
$(function(){
//爲手機號輸入框綁定離焦事件
$("input[name=telephone]").blur(function(){
//發送ajax請求,訪問Action,在Action中調用crm項目根據手機號查詢客戶信息,在Action中將查詢出的客戶信息
//序列化爲json數據返回頁面
var telephone = this.value;
var url = "${pageContext.request.contextPath}/noticebillAction_findCustomerByPhone.action";
$.post(url,{"phone":telephone},function(data){
if(data != null){
//將客戶的信息顯示到當前頁面上
$("input[name=customerId]").val(data.id);
$("input[name=customerName]").val(data.name);
$("input[name=delegater]").val(data.name);
$("input[name=pickaddress]").val(data.address);
}else{
$("input[name=customerId]").val("");
$("input[name=customerName]").val("");
$("input[name=delegater]").val("");
$("input[name=pickaddress]").val("");
}
});
});
});
</script>
<td><input type="text" class="easyui-validatebox" name="telephone"
required="true" /></td>
<td>客戶編號:</td>
<td><input type="text" class="easyui-validatebox" name="customerId"
required="true" /></td>
</tr>
<tr>
<td>客戶姓名:</td>
<td><input type="text" class="easyui-validatebox" name="customerName"
required="true" /></td>
<td>聯繫人:</td>
<td><input type="text" class="easyui-validatebox" name="delegater"
required="true" /></td>
</tr>
<tr class="title">
<td colspan="4">貨物信息</td>
</tr>
<tr>
<td>品名:</td>
<td><input type="text" class="easyui-validatebox" name="product"
/></td>
<td>件數:</td>
<td><input type="text" class="easyui-numberbox" name="num"
/></td>
</tr>
<tr>
<td>重量:</td>
<td><input type="text" class="easyui-numberbox" name="weight"
/></td>
<td>體積:</td>
<td><input type="text" class="easyui-validatebox" name="volume"
/></td>
</tr>
<tr>
<td>取件地址</td>
<td colspan="3"><input type="text" class="easyui-validatebox" name="pickaddress"
required="true" size="144"/></td>
</tr>
<tr>
<td>到達城市:</td>
<td><input type="text" class="easyui-validatebox" name="arrivecity"
/></td>
<td>預定取件時間:</td>
<td><input type="text" class="easyui-datebox" name="pickdate"
data-options="editable:false" /></td>
</tr>
<tr>
<td>備註:</td>
<td colspan="3"><textarea rows="5" cols="80" type="text" class="easyui-validatebox" name="remark"
></textarea></td>
</tr>
</table>
</form>
</div>
</body>
</html>app