一、hive表:
启动hiveserver2
二、添加mybatis starter和hive依赖
4.0.0 org.example hivejdbc 1.0-snapshot 8 8 org.springframework.boot spring-boot-starter-parent 2.6.6 org.springframework.boot spring-boot-starter-web org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 org.projectlombok lombok mysql mysql-connector-java org.apache.hive hive-jdbc 2.1.1 org.eclipse.jetty jetty-runner org.apache.hive hive-exec 3.0.0
三、配置文件application.properties中配置数据源:
server.port=9202 spring.datasource.driverclassname=org.apache.hive.jdbc.hivedriver spring.datasource.url=jdbc:hive2://xx.xx.xx.xx:10000/default spring.datasource.username= spring.datasource.password=
四、定义mapper
package cn.edu.tju.mapper; import cn.edu.tju.domain.userinfo; import org.apache.ibatis.annotations.mapper; import org.apache.ibatis.annotations.select; import java.util.list; import java.util.map; @mapper public interface userinfomapper { @select("select * from userinfo") list
五、定义controller,注入mapper并使用
package cn.edu.tju.controller; import cn.edu.tju.domain.userinfo; import cn.edu.tju.mapper.userinfomapper; import org.springframework.beans.factory.annotation.autowired; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.restcontroller; import java.util.list; import java.util.map; @restcontroller public class userinfocontroller { @autowired private userinfomapper userinfomapper; @requestmapping("/getuserinfo") public string getuserinfo() { list
到此这篇关于使用mybatis从hive中读取数据的文章就介绍到这了,更多相关mybatis hive读取内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!