首先在jsp頁(yè)面中添加文本框(text/textarea)返顺、id()。
首次關(guān)注信息:
<div>
<textarea id="txaDgdFirstInfo" class="form-control" style="height: 100px;"></textarea>
</div>
添加數(shù)據(jù)庫(kù)新增字段(first_info)
利用hibernate框架映射
打開database explorer
add jars 添加mysql connect jar包
然后finish
![%]57S@Y6DN@FIR9VO`_GZXB.png](http://upload-images.jianshu.io/upload_images/3404498-c7870c407aebd283.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
打開對(duì)應(yīng)的數(shù)據(jù)庫(kù)表,
右鍵進(jìn)行映射
![
![
在公共類(CommonVo和TSpAccount)中檢查是否生成firstInfo,并且設(shè)置get/set
找到Account類肋杖,修改
// Property accessors
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
回到j(luò)sp頁(yè)面在頁(yè)面中尋找提交方法趴腋。并且把數(shù)據(jù)獲取提交
,"cvoParameter.firstInfo": $("#txaDgdFirstInfo").val()
funCallback = funCallback || function(){};
var sText = "是否確定保存授權(quán)設(shè)置?";
var sUrl = "spAction_saveDoctorGrantSetting";
var objParams = {
"cvoParameter.jsonData": doctorSetting.getGrantData()
,"cvoParameter.firstInfo": $("#txaDgdFirstInfo").val()
};
commonJs.confirmSubmit(sText, sUrl, objParams, funCallback);
};
根據(jù)Url = "spAction_saveDoctorGrantSetting"找到相應(yīng)的action及方法
/**
* 保存私人醫(yī)生授權(quán)設(shè)置
*/
@IAccess(competenceNumber = { GlobalCache.UserRole.SPD }, returnFormat = GlobalCache.JSON)
public void saveDoctorGrantSetting() {
CommonVo cvoParams = getCvoParameter();
MessageVo mvoResult = new MessageVo();
if (StringUtils.isEmpty(cvoParams.getJsonData())) {
mvoResult.setSuccess(false);
mvoResult.setMessage("缺少參數(shù)吧兔!");
} else {
cvoParams.setId(getLoginInfos().getId());
mvoResult = funSp.saveDoctorGrantSetting(cvoParams);
}
outJson(mvoResult);
}
打開saveDoctorGrantSetting方法更新文本框內(nèi)容磷仰。
cvoUpdate.setFirstInfo(cvoParams.getFirstInfo());
/**
* 保存私人醫(yī)生授權(quán)設(shè)置
* @param cvoParams
* @return
*/
public MessageVo saveDoctorGrantSetting(CommonVo cvoParams) {
Set<Long> setIds = new HashSet<Long>();
Long lDoctor = null;
if (!StringUtils.isEmpty(cvoParams.getJsonData())) {
JSONArray jsonArray = JSONArray.fromObject(cvoParams.getJsonData());
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
CommonVo cvoDetail = (CommonVo) JSONObject.toBean(jsonObject, CommonVo.class);
setIds.add(cvoDetail.getId());
if ("1".equals(cvoDetail.getIsBinding())) {
lDoctor = cvoDetail.getId();
}
}
}
StringBuilder sbBuffer = new StringBuilder();
for (Long lId : setIds) {
sbBuffer.append(lId).append(",");
}
if (sbBuffer.length() > 0) {
sbBuffer.deleteCharAt(sbBuffer.length() - 1);
}
CommonVo cvoUpdate = new CommonVo();
cvoUpdate.setId(cvoParams.getId());
cvoUpdate.setFirstInfo(cvoParams.getFirstInfo());
cvoUpdate.setDoctorIdList(CommonBean.canNullValue(sbBuffer.toString()));
cvoUpdate.setDoctorId(CommonBean.canNullValueLong(lDoctor));
MessageVo mvoResult = tdoSpAccount.update(cvoUpdate);
mvoResult.setMessage(mvoResult.isSuccess() ? "授權(quán)設(shè)置保存成功!" : "授權(quán)設(shè)置保存失斁嘲灶平!");
return mvoResult;
}
找到對(duì)應(yīng)名稱的TableDao類
寫入update語句
public MessageVo update(CommonVo cvoUpdate) {
MessageVo mvoResult = new MessageVo();
String sHql = "update " + TABLE_NAME + " set ";// 更新語句
try {
Object[] objParameter = null;// 當(dāng)為條件時(shí)第3個(gè)參數(shù)為是否必要,當(dāng)為參數(shù)時(shí)第3個(gè)參數(shù)為默認(rèn)值
ArrayList<Object[]> arrCondition = new ArrayList<Object[]>();// 條件列表
ArrayList<Object[]> arrParameter = new ArrayList<Object[]>();// 參數(shù)列表
// 設(shè)置更新條件
objParameter = new Object[] { " first_info = ? ", cvoUpdate.getFirstInfo() };
arrParameter.add(objParameter);//
// 執(zhí)行更新語句
update(sHql, arrCondition, arrParameter);
mvoResult.setSuccess(true);
mvoResult.setMessage("更新數(shù)據(jù)成功箍土!");
} catch (Exception e) {
CommonBean.handleException(e, mvoResult);
mvoResult.setSuccess(false);
mvoResult.setMessage("更新數(shù)據(jù)失敺晗怼!");
e.printStackTrace();
}
return mvoResult;
}
存儲(chǔ)至數(shù)據(jù)庫(kù)以完成
取出數(shù)據(jù)
在jsp頁(yè)面找加載的方法吴藻,并根據(jù)id利用jquery給id賦值 $("#txaDgdFirstInfo").val(data.cvoResult.firstInfo);
doctorSetting.loadSetting = function(){
var sUrl = "spAction_loadDoctorGrantSetting";
commonJs.openAjax(sUrl, { hasLoading:false }, function(data){
if(!data.success){
commonJs.openDialog("error", data.message);
return;
}
var $doctorList = $("#divDgdTemplate select").append($('<option value="">--請(qǐng)選擇--</option>'));
var arrDoctor = data.lstResult2 || [];
$.each(arrDoctor, function(i, item){
var $option = $("<option></option>").text(item.name).attr("value", item.id);
$doctorList.append($option);
});
var arrGrant = data.lstResult || [];
$.each(arrGrant, function(i, item){
var $tr = doctorSetting.addDoctor();
$tr.find("select option[value='" + item.id + "']").prop("selected", true);
if(item.isBinding == "1"){
$tr.find("input[name='rad_canReply']").iCheck("check");
}
});
if(arrGrant.length == 0){
doctorSetting.addDoctor();
}
$("#txaDgdFirstInfo").val(data.cvoResult.firstInfo);
}, commonJs.funError);
};
根據(jù)action找到方法瞒爬,
/**
* 獲取私人醫(yī)生授權(quán)設(shè)置
* @return
*/
@IAccess(competenceNumber = { GlobalCache.UserRole.SPD }, returnFormat = GlobalCache.JSON)
public void loadDoctorGrantSetting() {
CommonVo cvoParams = getCvoParameter();
cvoParams.setId(getLoginInfos().getId());
cvoParams.setSpId(getSpId());
MessageVo mvoResult = funSp.loadDoctorGrantSetting(cvoParams);
mvoResult.setLstResult2(funClinic.listStaffInSp(cvoParams.getSpId(), null));
outJson(mvoResult);
}
查找loadDoctorGrantSetting方法
數(shù)據(jù)獲取 mvoResult.setCvoResult(cvoAccount);
/**
* 獲取私人醫(yī)生授權(quán)設(shè)置
* @param cvoParams
* @return
*/
@SuppressWarnings("unchecked")
public MessageVo loadDoctorGrantSetting(CommonVo cvoParams) {
MessageVo mvoResult = new MessageVo();
CommonVo cvoAccount = tdoSpAccount.getOne(cvoParams);
if (cvoAccount == null) {
mvoResult.setSuccess(false);
mvoResult.setMessage("請(qǐng)重新登陸系統(tǒng)!");
return mvoResult;
}
if (!StringUtils.isEmpty(cvoAccount.getDoctorIdList())) {
CommonVo cvoSelect = new CommonVo();
cvoSelect.setPageNum(1);
cvoSelect.setLimitNum(Integer.MAX_VALUE);
cvoSelect.setSpId(cvoParams.getSpId());
cvoSelect.setSql(" and id in (" + cvoAccount.getDoctorIdList() + ") ");
List<CommonVo> lstDoctor = (List<CommonVo>) tdoSpAccount.getList(cvoSelect).getLstResult();
lstDoctor = (lstDoctor != null) ? lstDoctor : new ArrayList<CommonVo>();
if (cvoAccount.getDoctorId() != null && cvoAccount.getDoctorId() != 0) {
for (CommonVo cvoDoctor : lstDoctor) {
if (cvoAccount.getDoctorId().equals(cvoDoctor.getId())) {
cvoDoctor.setIsBinding("1");
} else {
cvoDoctor.setIsBinding("0");
}
}
}
mvoResult.setLstResult(lstDoctor);
}
mvoResult.setCvoResult(cvoAccount);
mvoResult.setSuccess(true);
return mvoResult;
現(xiàn)在基本已完成