springboot2.0整合ali-phoenix,mybatis操作Hbase

其他整合mybatis查询很简单,就是保存需要拼接sql,不多说,直接贴代码

pom.xml


    org.springframework.boot
    spring-boot-starter-data-redis



    org.springframework.boot
    spring-boot-starter-web



    org.springframework.boot
    spring-boot-starter-test
    test



    org.projectlombok
    lombok
    true



    com.fasterxml.jackson.core
    jackson-databind
    2.8.9




    com.alibaba
    fastjson
    1.2.31



    com.aliyun.phoenix
    ali-phoenix-core
    4.12.0-AliHBase-1.1-0.2



    org.nutz
    nutz
    1.b.51




    com.alibaba
    druid
    1.1.12




    tk.mybatis
    mapper
    4.0.2




    org.mybatis.spring.boot
    mybatis-spring-boot-starter
    1.3.2




    mysql
    mysql-connector-java

application.yml

 

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    url: 
    username: 
    password: 
    driverClassName: org.apache.phoenix.jdbc.PhoenixDriver
server:
  port: 5858
mybatis:
  mapper-locations: classpath:mybatis/*Mapper.xml
  type-aliases-package: 

 

DataSourceConfig
@Value("${spring.datasource.driverClassName}")
private String driverClassName;

@Value("${spring.datasource.password}")
private String password;

@Value("${spring.datasource.username}")
private String username;

@Value("${spring.datasource.url}")
private String url;

@Bean(name = "druidDataSource")
public DruidDataSource druidDataSource() {
    DruidDataSource dds = new DruidDataSource();
    try {
        dds.setDriverClassName(driverClassName);
        dds.setUrl(url);
        dds.setUsername(username);
        dds.setPassword(password);
        dds.setInitialSize(1);
        dds.setMaxActive(10);
        dds.setMinIdle(1);
        dds.setMaxWait(6000);
        dds.setPoolPreparedStatements(true);
        dds.setMaxOpenPreparedStatements(50);
        dds.setValidationQuery("SELECT 1");
        dds.setTestOnBorrow(false);
        dds.setTestOnReturn(false);
        dds.setTestWhileIdle(true);
        dds.setTimeBetweenEvictionRunsMillis(60000);
        dds.setMinEvictableIdleTimeMillis(25200000);
        dds.setRemoveAbandoned(true);
        dds.setRemoveAbandonedTimeout(1800);
        dds.setLogAbandoned(false);
        dds.setFilters("stat");
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return dds;
}

@Bean(name = "phoenixJdbcTemplate")
public JdbcTemplate phoenixJdbcTemplate(@Qualifier("druidDataSource") DruidDataSource dataSource) {
    return new JdbcTemplate(dataSource);
}

按照上面的步骤配置,使用 String sql ="upsert into table (id,name,data) values ( NEXT VALUE FOR SEQ ,'name',TO_DATE('2019-01-10 16:39:30'))"; jdbcTemplate.execute(sql); 就可以保存了,查询使用mybatis中的查询就行

请大哥们尊重原创,谢谢
 

 

你可能感兴趣的