@Test public void testGetReplyRate() { double rate = topicDao.getReplyRate(2); System.out.println("rate is:" + rate); }
public double getReplyRate(int userId) { String sql = "SELECT topic_replies,topic_views FROM t_topic WHERE user_id=?"; double rate = jdbcTemplate.queryForObject(sql, new Object[] { userId }, new RowMapper<Double>() { public Double mapRow(ResultSet rs, int index) throws SQLException { int replies = rs.getInt("topic_replies"); int views = rs.getInt("topic_views"); if (views > 0) return new Double((double) replies / views); else return new Double(0.0); } }); return rate; }
TopicDao { public double getReplyRate(int userId) { String sql = "SELECT topic_replies,topic_views FROM t_topic WHERE user_id=?"; double rate = jdbcTemplate.queryForObject(sql, new Object[] { userId }, new RowMapper<Double>() { public Double mapRow(ResultSet rs, int index) throws SQLException { int replies = rs.getInt("topic_replies"); int views = rs.getInt("topic_views"); if (views > 0) return new Double((double) replies / views); else return new Double(0.0); } }); return rate; } }
TopicDao { public double getReplyRate(int userId) { String sql = "SELECT topic_replies,topic_views FROM t_topic WHERE user_id=?"; double rate = jdbcTemplate.queryForObject(sql, new Object[] { userId }, new RowMapper<Double>() { public Double mapRow(ResultSet rs, int index) throws SQLException { int replies = rs.getInt("topic_replies"); int views = rs.getInt("topic_views"); if (views > 0) return new Double((double) replies / views); else return new Double(0.0); } }); return rate; }  }
TopicDao { public double getReplyRate(int userId) { String sql = "SELECT topic_replies,topic_views FROM t_topic WHERE user_id=?"; double rate = jdbcTemplate.queryForObject(sql, new Object[] { userId }, new RowMapper<Double>() { public Double mapRow(ResultSet rs, int index) throws SQLException { int replies = rs.getInt("topic_replies"); int views = rs.getInt("topic_views"); if (views > 0) return new Double((double) replies / views); else return new Double(0.0); } }); return rate; }  @Autowired void setJdbcTemplate(JdbcTemplate jdbcTemplate); double getReplyRate(int userId); int getUserTopicNum(final int userId); int getUserTopicNum2(int userId); SqlRowSet getTopicRowSet(int userId); }
TopicDao { public double getReplyRate(int userId) { String sql = "SELECT topic_replies,topic_views FROM t_topic WHERE user_id=?"; double rate = jdbcTemplate.queryForObject(sql, new Object[] { userId }, new RowMapper<Double>() { public Double mapRow(ResultSet rs, int index) throws SQLException { int replies = rs.getInt("topic_replies"); int views = rs.getInt("topic_views"); if (views > 0) return new Double((double) replies / views); else return new Double(0.0); } }); return rate; }  @Autowired void setJdbcTemplate(JdbcTemplate jdbcTemplate); double getReplyRate(int userId); int getUserTopicNum(final int userId); int getUserTopicNum2(int userId); SqlRowSet getTopicRowSet(int userId);  }