
1private Long findByActivityId(String activityId) {
2 String selectSql = "select times_viewed from activity_stats where activity_id = ?";
3 Long timesViewed = this.jdbcTemplate.queryForObject(selectSql, Long.class,
4 activityId);
5 return timesViewed;
6}
1public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
2 throws DataAccessException {
3
4 List<T> results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
5 return DataAccessUtils.nullableSingleResult(results);
6}
1public static <T> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
2 if (CollectionUtils.isEmpty(results)) {
3 throw new EmptyResultDataAccessException(1);
4 } else if (results.size() > 1) {
5 throw new IncorrectResultSizeDataAccessException(1, results.size());
6 } else {
7 return results.iterator().next();
8 }
9}
1private Long queryByActivityId(String activityId) {
2 String selectSql = "select times_viewed from activity_stats where activity_id = ?";
3 Long timesViewed = null;
4 try {
5 timesViewed = this.jdbcTemplate.queryForObject(selectSql, Long.class,
6 activityId);
7 }
8 catch (EmptyResultDataAccessException ignored) {
9 }
10 return timesViewed;
11}
1private Long queryByActivityId(String activityId) {
2 String selectSql = "select times_viewed from activity_stats where activity_id = ?";
3 Long timesViewed = null;
4 try {
5 timesViewed = this.jdbcTemplate.queryForObject(selectSql, Long.class,
6 activityId);
7 }
8 catch (IncorrectResultSizeDataAccessException ignored) {
9 }
10 return timesViewed;
11}

文章转载自rookiedev,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




