• 前台交互,根据id、关键字查询、插入新数据到数据库


        public void update() {
    
            Patent patent = patentservice.get(id);
            name=Iso2Utf.encode(name);
            author=Iso2Utf.encode(author);
            attachmentName=Iso2Utf.encode(attachmentName);
            company=Iso2Utf.encode(company);
            place=Iso2Utf.encode(place);
            remark=Iso2Utf.encode(remark);
            if (patent != null) {
                patent.setAuthor(author);
                patent.setAttachmentName(attachmentName);
                patent.setCompany(company);
                patent.setName(name);
                patent.setPlace(place);
                patent.setRemark(remark);
    
                patentservice.update(patent);
            }
        }
    update

    name=Iso2Utf.encode(name);

    需要做转换,乱码

    /**
         * 根据id获取专利详细信息
         */
        public String loadDataByid() {
            Patent patent = patentservice.get(id);
    
            Date date_date = patent.getDate();
            Date date_issueDate = patent.getIssueDate();
            String str_date_date = sd.format(date_date);
            String str_date_issueDate = sd1.format(date_issueDate);
    
            PatentVo pVo = new PatentVo();
            try {
                BeanUtils.copyProperties(pVo, patent);
            } catch (IllegalAccessException | InvocationTargetException e1) {
                e1.printStackTrace();
            }
            pVo.setDate(str_date_date);
            pVo.setIssueDate(str_date_issueDate);
            pVo.setDoctypeId(patent.getDoctype().getId());
            pVo.setDoctypeName(patent.getDoctype().getName());
            pVo.setUserId(patent.getUser().getId());
            pVo.setUserName(patent.getUser().getName());
    
            String jsonResult = JSONObject.fromObject(pVo).toString();
            try {
                response.getWriter().write(jsonResult);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    关键字查询

    }
    pVo.setDate(str_date_date);
    pVo.setIssueDate(str_date_issueDate);
    pVo.setDoctypeId(patent.getDoctype().getId());
    pVo.setDoctypeName(patent.getDoctype().getName());
    pVo.setUserId(patent.getUser().getId());
    pVo.setUserName(patent.getUser().getName());

    包含实体类的,放在Vo里

    /**
         * 根据关键字获取专利详细信息
         */
        public String loadDataByKeyWord() {
            key = Iso2Utf.encode(key);
            List<Patent> patents = patentservice.getListByKeyWord(key);
            List<PatentVo> patentVos = new ArrayList<PatentVo>();
            for (Patent patent : patents) {
                PatentVo patentVo = new PatentVo();
                try {
                    BeanUtils.copyProperties(patentVo, patent);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                patentVo.setDoctypeId(patent.getDoctype().getId());
                patentVo.setDoctypeName(patent.getDoctype().getName());
                patentVo.setDate(sd.format(patent.getDate()));
                patentVo.setIssueDate(sd1.format(patent.getIssueDate()));
                patentVos.add(patentVo);
            }
            String jsonResult = JSONArray.fromObject(patentVos).toString();
            try {
                response.getWriter().write(jsonResult);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

    后台java代码,不允许setId

    前台

    ajax({
                        url : "appcanAjax/appPatent_loadDataByKeyWord?key=" + key,
                        data : {
                            pageNo : pageNo,
                            pageSize : pageSize
                        },
                        type : "get",
                        dataType : "json",
                        successx : function(data) {
                            if (data.length > 0) {
                                //遍历数据
                                for (var i = 0; i < data.length; i++) {
                                    var list = {
                                        id : data[i].id,
                                        title : data[i].name,
                                        note : "发明人:" + data[i].author,
                                        describe : "授权号:" + data[i].number,
                                        icon : iconpath
                                    }
                                    listData.push(list);
                                }
                            } else {
                                $toast('暂无数据!', 2500);
                            }
                            if (pageNo > 1) {
                                lv.add(listData, 1)
                                if (listData.length == 0) {
                                    $toast('没有更多记录了...', 2000);
                                }
                            } else {
                                lv.set(listData);
                            }
                        },
                        error : function(xhr, type) {
                            $toast("网络连接超时", 3500);
                        }
                    });
    Appcan
    ajax({
                        url : "appcanAjax/appPatent_update",
                        data : {
                            id : id,
                            name : name,
                            author : author,
                            company : company,
                            place : place,
                            attachmentName : attachmentName,
                            remark : remark
                        },
                        dataType : "json",
                        successx : function(data) {
                            $toast("保存成功", 1000);
                            setTimeout(function() {
                                location.reload()
                            }, '1000')
                        },
                        error : function(xhr, type) {
                            $toast("网络连接超时", 2000);
                        }
                    });
    View Code

    传代数值的,先传id(id:id)

  • 相关阅读:
    C#和sqlserver中生成新的32位GUID
    IIS7下swfupload上传大文件出现404错误
    jQuery 判断是否为数字的方法 及 转换数字函数
    js数组与字符串的相互转换方法
    jquery 中如何将数组转化为json字符串,然后再转化回来?
    Firemonkey Android 虚拟机
    Eclipse apk 签名
    win10 修改hosts
    eclipse 预览Android界面报错
    夜神模拟器
  • 原文地址:https://www.cnblogs.com/1ming/p/5830669.html
Copyright © 2020-2023  润新知