0.本例子是基于jQuery的
1.引入jct包
<!-- 引入jct包 -->
<script type="text/javascript" src="${ctx }/js/jct.js"></script>
<script type="text/javascript" src="${ctx }/js/dateutils.js"></script>
2.通过ajax 传递参数给java
var assessEntity = null;
$(document).ready(function() {
var seeAssessDetail = function(id){
$("#assessDetail").click();
var url = "${ctx }/classes/assess/assess!getOneAssess.action";
var params = {selectId:id};
$.ajax({url:url,dataType:"json",data:params,error:ajaxSendError,success:ajaxSendSuccess});
};
var ajaxSendSuccess = function(xhr, textStatus, errorThrows){
assessEntity = xhr;
var templete=$("#assessTemplete").val();
try{
var jct = new jCT(templete);
jct.Build();
var htmlSrc = jct.GetView();
}catch(e){alert(e);}
$("#assessTempleteCont").html(htmlSrc);
};
var ajaxSendError = function(xhr, textStatus, errorThrown){
alert("无法发送请求,可能是网络出现了故障。status:" +textStatus+" detail:"+errorThrown);
};
window.seeAssessDetail = seeAssessDetail;
});
3.写模板
<textarea id="assessTemplete" style="display:none">
<table cellpadding="5" cellspacing="0" border="0" width="585px" class="particular">
<tr>
<td width="80px" class="tb_row1">评价课程:</td>
<td class="tb_row2">+-assessEntity.subject.name-+</td>
</tr>
<tr>
<td class="tb_row1">评价老师:</td>
<td class="tb_row2">+-assessEntity.teacher.name-+</td>
</tr>
<tr>
<td class="tb_row1">评价时间:</td>
<td class="tb_row2">+-assessEntity.assessTime-+</td>
</tr>
<tr class="gutBkColor">
<td colspan="2">
<div class="gut" style="height:300px;overflow-y:auto;font-size:12px;">
+-assessEntity.content-+
</div>
</td>
</tr>
</table>
</textarea>
4.定义,要放模板的位置,就是添加完数据后,要把模板放入何处
<div id="assessTempleteCont">
</div>
5.定义java生成json类的方法
public String getOneAssess() throws Exception {
AssessStudent as = assessManager.get(selectId);
try{
super.writeJson(as,new String[]{"hibernateLazyInitializer", "handler"}, super.getDatePattern());//自定义该方法,封装spring生成json类的方法
}catch(Exception e){
logger.warn("AssessStudent无法转换成json", e);
}
return null;
}