private List<WxArticle> getArticle(List<Map<String, Object>> result) { List<WxArticle> list = new ArrayList<WxArticle>(); for (Map<String, Object> map : result) { WxArticle article = new WxArticle(); for (String str : map.keySet()) { Object obj = map.get(str); if ("id".equals(str)) { article.setId((Integer) obj); } else if ("title".equals(str)) { article.setTitle((String) obj); } else if ("summary".equals(str)) { article.setSummary((String) obj); } else if ("type".equals(str)) { article.setType((String) obj); } else if ("content".equals(str)) { article.setContent((String) obj); } else if ("status".equals(str)) { article.setStatus((String) obj); } else if ("price".equals(str)) { article.setPrice((Integer) obj); } else if ("createtime".equals(str)) { article.setCreatetime((Date) obj); } } list.add(article); } return list; }
public void updateArticle(WxArticle wxArticle) { String createtime = DateUtil.dateToString(wxArticle.getCreatetime(), null); String sql = "UPDATE `wxarticle` SET title='TITLE', summary='SUMMARY', type='TYPE', content='CONTENT', price=PRICE, createtime='CREATETIME' " + "where id=ID;"; sql = sql.replace("TITLE", wxArticle.getTitle()) .replace("SUMMARY", wxArticle.getSummary()) .replace("TYPE", wxArticle.getType()) .replace("CONTENT", wxArticle.getContent()) .replace("PRICE", wxArticle.getPrice() + "") .replace("CREATETIME", createtime) .replace("ID", wxArticle.getId() + ""); jdbcTemplate.execute(sql); }
public void saveArticle(WxArticle wxArticle) { String createtime = DateUtil.dateToString(wxArticle.getCreatetime(), null); String sql = "INSERT INTO `wxarticle`(title, summary, type, content, status, price, createtime) " + "VALUES('TITLE','SUMMARY','TYPE','CONTENT','1', PRICE, 'CREATETIME');"; sql = sql.replace("TITLE", wxArticle.getTitle()) .replace("SUMMARY", wxArticle.getSummary()) .replace("TYPE", wxArticle.getType()) .replace("CONTENT", wxArticle.getContent()) .replace("PRICE", wxArticle.getPrice() + "") .replace("CREATETIME", createtime); jdbcTemplate.execute(sql); }