springboot使用自带连接池连接postgre

Application配置
spring.datasource.url=jdbc:postgresql://***:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=123456
spring.datasource.driver-class-name=org.postgresql.Driver
#最大连接数
spring.datasource.tomcat.max-active=20
#最大空闲数
spring.datasource.tomcat.max-idle=8
#最小空闲数
spring.datasource.tomcat.min-idle=8
#初始化连接数
spring.datasource.tomcat.initial-size=10

注入jdbctemplate实现增删改查
@Autowired
JdbcTemplate jdbcTemplate;
List<Path> paths = jdbcTemplate.query(start, new Object[]{projectid, projectid}, new RowMapper<Path>() {
@Override
public Path mapRow(ResultSet rs, int rowNum) throws SQLException {
double slng = rs.getDouble("slng");
double slat = rs.getDouble("slat");
double elng = rs.getDouble("elng");
double elat = rs.getDouble("elat");
Node snode = new Node();
snode.setLng(slng);
snode.setLat(slat);
Node enode = new Node();
enode.setLng(elng);
enode.setLat(elat);
Path path = new Path();
path.setStart(snode);
path.setEnd(enode);
return path;
}
});
posted @ 2018-08-14 17:34  渔阳nice  阅读(5501)  评论(1编辑  收藏  举报