Spring Boot:1.3.2.RELEASE Vaadin:7.6.3 Mysql:mysql-java-connector-5.1.38 HikariCP:2.4.3
所以我创建了一个只有id和name列的表。然后是一个 vaadin 组件表来显示表的内容。直到现在一切都很好。然后我尝试使用 vaadin 过滤器过滤表,如果连接池是com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool,它可以工作,如果它是com.vaadin.data.util.sqlcontainer.connection .J2EEConnectionPool我使用 HikariCP 作为数据源。
DBConfig.java
@Configuration
@EnableTransactionManagement
public class DatabaseConfig {
@Bean
public HikariConfig hikariConfig() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl("jdbc:mysql://localhost:3306/test?autoReconnect=true&useSSL=false");
config.setUsername("root");
config.setPassword("root");
config.setMaximumPoolSize(20);
config.setPoolName("connectionPool");
return config;
}
@Bean
public DataSource dataSource() {
HikariDataSource dataSource = new HikariDataSource(hikariConfig());
return dataSource;
}
应用程序UI.java
@Autowired
private J2EEConnectionPool connectionPool;
@Override
protected void init(VaadinRequest arg0) {
TableQuery tq = new TableQuery("medecine", connectionPool);// it does not work if I use HikariCP as the J2EEConnectionPool
JDBCConnectionPool pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver",
"jdbc:mysql://localhost:3306/test?autoReconnect=true&useSSL=false", "root", "root");
TableQuery tq = new TableQuery("medecine", connectionPool);// it works if I use **SimpleJDBCConnectionPool**.
container = new SQLContainer(tq);
table = new Table();
table.setContainerDataSource(container);
table.setWidth(100, Unit.PERCENTAGE);
mainLayout.addComponent(table);
Button addFilter = new Button("filter", new ClickListener() {
private static final long serialVersionUID = -7071683058766115266L;
@Override
public void buttonClick(ClickEvent arg0) {
Filter filter = new SimpleStringFilter("name", "medecine2", true, false);
container.addContainerFilter(filter);
}
});
mainLayout.addComponent(addFilter);
}
我选择 HikariCP 作为数据源的原因是为了更好的性能,我不确定 vaadin 连接池是否会比 HikariCP 更好。或者,过滤功能仅限于vaadin连接池?