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)