首页 > 代码库 > 前台交互,根据id、关键字查询、插入新数据到数据库
前台交互,根据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); } }
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); } });
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); } });
传代数值的,先传id(id:id)
前台交互,根据id、关键字查询、插入新数据到数据库
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。