public boolean update(final Article article) { Timestamp time = new Timestamp(System.currentTimeMillis()); StringBuilder sf = new StringBuilder("update "); sf.append(tableName).append(" set "); if (notEmpty(article.getTitle())) { sf.append(" title=").append(article.getTitle()).append(","); } if (notEmpty(article.getContent())) { sf.append(" content=").append(article.getContent()).append(","); } if (notEmpty(article.getCategory())) { sf.append(" category=").append(article.getCategory()).append(","); } if (notEmpty(article.getAuthorId())) { sf.append(" authorId=").append(article.getAuthorId()).append(","); } if (notEmpty(article.getEditorId())) { sf.append(" editorId=").append(article.getEditorId()).append(","); } if (notEmpty(article.getMediaId())) { sf.append(" mediaId=").append(article.getMediaId()).append(","); } sf.append(" uptime=").append(time.toString()).append(" where id=").append(article.getId()); logger.info(sf.toString()); int ret = jdbcTemplateWrite.update(sf.toString()); return ret > 0; }
public boolean insert(Article article) { Timestamp time = new Timestamp(System.currentTimeMillis()); StringBuilder sf = new StringBuilder("insert into "); sf.append(tableName) .append(" (title, content, ctime, uptime, category, authorId, editorId, mediaId) values (") .append(article.getTitle()) .append(article.getContent()) .append(time) .append(time) .append(article.getCategory()) .append(article.getAuthorId()) .append(article.getEditorId()) .append(article.getMediaId()); logger.info(sf.toString()); int ret = jdbcTemplateWrite.update(sf.toString()); return ret > 0; }