Demo entry 6645387

批量增加用户关注话题

   

Submitted by swd on Oct 10, 2017 at 09:06
Language: Java. Code size: 993 Bytes.

	@Transactional
	public int[] batchSaveTopics(String acct_id, List<String> topicIds) {
		rw.writeLock().lock();
		List<Object[]> listTopic = new ArrayList<Object[]>();
		List<Object[]> listTopicIds = new ArrayList<Object[]>();
		int [] nnum = {};
		for (String topicId : topicIds) {
			listTopic.add(new Object[] { Integer.valueOf(topicId), acct_id, ut.currentTime() });
			listTopicIds.add(new Object[] { Integer.valueOf(topicId)});
		}
		String sql = "insert into xp_topic_attention(topic_id,acct_id,create_time) values(?,?,?)";
		String updateSql = "update xp_topic set total_collection =total_collection+1 where id = ?";
		try {
			int[] num = jdbcTemplate.batchUpdate(sql, listTopic);
			int[] addnum = jdbcTemplate.batchUpdate(updateSql,listTopicIds);
			if (num.equals(addnum)) {
				nnum = num;
			}
		} catch (Exception e) {
			System.err.println(e.getMessage());
			throw new RuntimeException();
		}finally {
			rw.writeLock().unlock();
		}
		return nnum;
	}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).