jdbctemplate.query()性能不佳

qaxu7uf2  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(512)

我将JavaSpringBoot与jersey、SpringJDBC和mariadb一起使用,但性能非常差。我的目标是从一个表中查询25条记录,这需要2.7-3秒,而且mariadb服务器和应用程序都运行在同一台主机上。
该表有100条记录,我筛选的列被编入索引。使用mysql workbench,结果会立即显示出来。

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
final String SQL_SELECT_ALL_TEMPLATES = "SELECT uuid, owner, displayname, template, type, created_at, updated_at FROM templates WHERE owner = ? ORDER BY updated_at DESC, created_at DESC LIMIT ? OFFSET ?;";
List<Template> templates = jdbcTemplate.query(SQL_SELECT_ALL_TEMPLATES, new TemplateMapper(), '05e1e15a-5620-4330-b77f-0ac2fff106c5', 25, 0);
@Bean
DataSource dataSource() {
    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
    driverManagerDataSource.setUrl("jdbc:mysql://127.0.0.1:3306/mydatabase");
    driverManagerDataSource.setUsername("root");
    driverManagerDataSource.setPassword("");
    driverManagerDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
    return driverManagerDataSource;
}
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>at.favre.lib</groupId>
        <artifactId>bcrypt</artifactId>
        <version>0.9.0</version>
    </dependency>
    <dependency>
        <groupId>com.auth0</groupId>
        <artifactId>java-jwt</artifactId>
        <version>3.11.0</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.22</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.6</version>
    </dependency>
        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.test-framework</groupId>
        <artifactId>jersey-test-framework-core</artifactId>
        <version>2.27</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.test-framework.providers</groupId>
        <artifactId>jersey-test-framework-provider-inmemory</artifactId>
        <version>2.32</version>
        <scope>test</scope>
    </dependency>
</dependencies>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题