如何在jsp頁(yè)面中添加文框存儲(chǔ)和獲取

首先在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框架映射
打開(kāi)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)

打開(kāi)對(duì)應(yīng)的數(shù)據(jù)庫(kù)表,


9P{78}KG18O~$K`LGG(@XD7.png

右鍵進(jìn)行映射

![
![


[ZA0J[DYKB4YG{EIEXN%IJ8.png](http://upload-images.jianshu.io/upload_images/3404498-93d5dc4df2f6fd9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ](http://upload-images.jianshu.io/upload_images/3404498-f23a8da292e0657c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

在公共類(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);
    }

打開(kāi)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類
寫(xiě)入update語(yǔ)句

public MessageVo update(CommonVo cvoUpdate) {
        MessageVo mvoResult = new MessageVo();
        String sHql = "update " + TABLE_NAME + " set ";// 更新語(yǔ)句
        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í)行更新語(yǔ)句
            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)在基本已完成

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語(yǔ)法,類相關(guān)的語(yǔ)法,內(nèi)部類的語(yǔ)法,繼承相關(guān)的語(yǔ)法,異常的語(yǔ)法,線程的語(yǔ)...
    子非魚(yú)_t_閱讀 34,652評(píng)論 18 399
  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,545評(píng)論 19 139
  • (一)Struts、Spring、Hibernate、Mybatis框技術(shù) 1.Struts2.0有幾種標(biāo)簽庫(kù) 【...
    獨(dú)云閱讀 3,374評(píng)論 0 62
  • 一. Java基礎(chǔ)部分.................................................
    wy_sure閱讀 4,011評(píng)論 0 11
  • 婚姻對(duì)于每個(gè)人來(lái)說(shuō)都是人生大事,對(duì)于婚姻伴侶的選擇決定了你人生下半場(chǎng)的幸福程度?!肮缮瘛卑头铺卦f(shuō)過(guò):其實(shí)你人生中...
    CBE教育聯(lián)盟閱讀 355評(píng)論 0 0

友情鏈接更多精彩內(nèi)容