pom文件
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.1.1</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.23</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
注意hive-jdbc版本一定与hive目录下的lib目录当中的jdbc版本一致
application.yml
spring:
datasource:
driver-class-name: org.apache.hive.jdbc.HiveDriver
url: jdbc:hive2://自己的地址啦:10000/default
username: root
password:
logging:
level:
com.example.hive.mapper: debug
?Mapper
public interface CityWeatherMapper extends BaseMapper<CityWeather> {
/**
*
* @return
*/
List<CityWeather> getall();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.hive.mapper.CityWeatherMapper">
<select id="getall" resultType="com.example.hive.domain.CityWeather">
select key,cityname,humidity,pyName,state1,state2,stateDetailed,tem1,tem2,temNow,time,url,windDir,windPower,windState from weather_city_five_minutes_jinzhou_hive
</select>
</mapper>
注意一定不要写select? *? from tableName 返回的对应不上实体类要将所有字段写出
@RestController
@RequestMapping("/city")
public class CityWeatherController {
@Resource
CityWeatherMapper cityWeatherMapper;
@GetMapping("getWeather")
public List a(){
// List<CityWeather> cityWeathers = cityWeatherMapper.selectList(null);
List<CityWeather> getall = cityWeatherMapper.getall();
return getall;
}
}
?
|