首先在jsp页面中添加文本框(text/textarea)、id()。
首次关注信息:
添加数据库新增字段(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)
打开对应的数据库表,
右键进行映射
![
![
在公共类(CommonVo和TSpAccount)中检查是否生成firstInfo,并且设置get/set
找到Account类,修改
// Property accessors
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
回到jsp页面在页面中寻找提交方法。并且把数据获取提交
,"cvoParameter.firstInfo": $("#txaDgdFirstInfo").val()
funCallback = funCallback || function(){};
var sText = "是否确定保存授权设置?";
var sUrl = "spAction_saveDoctorGrantSetting";
var objParams = {
"cvoParameter.jsonData": doctorSetting.getGrantData()
,"cvoParameter.firstInfo": $("#txaDgdFirstInfo").val()
};
commonJs.confirmSubmit(sText, sUrl, objParams, funCallback);
};
根据Url = "spAction_saveDoctorGrantSetting"找到相应的action及方法
/**
* 保存私人医生授权设置
*/
@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("缺少参数!");
} else {
cvoParams.setId(getLoginInfos().getId());
mvoResult = funSp.saveDoctorGrantSetting(cvoParams);
}
outJson(mvoResult);
}
打开saveDoctorGrantSetting方法更新文本框内容。
cvoUpdate.setFirstInfo(cvoParams.getFirstInfo());
/**
* 保存私人医生授权设置
* @param cvoParams
* @return
*/
public MessageVo saveDoctorGrantSetting(CommonVo cvoParams) {
Set setIds = new HashSet();
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() ? "授权设置保存成功!" : "授权设置保存失败!");
return mvoResult;
}
找到对应名称的TableDao类
写入update语句
public MessageVo update(CommonVo cvoUpdate) {
MessageVo mvoResult = new MessageVo();
String sHql = "update " + TABLE_NAME + " set ";// 更新语句
try {
Object[] objParameter = null;// 当为条件时第3个参数为是否必要,当为参数时第3个参数为默认值
ArrayList
存储至数据库以完成
取出数据
在jsp页面找加载的方法,并根据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($(''));
var arrDoctor = data.lstResult2 || [];
$.each(arrDoctor, function(i, item){
var $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);
};
根据action找到方法,
/**
* 获取私人医生授权设置
* @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方法
数据获取 mvoResult.setCvoResult(cvoAccount);
/**
* 获取私人医生授权设置
* @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("请重新登陆系统!");
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 lstDoctor = (List) tdoSpAccount.getList(cvoSelect).getLstResult();
lstDoctor = (lstDoctor != null) ? lstDoctor : new ArrayList();
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;
现在基本已完成