大数据全系列 教程
1869个小节阅读:465.4k
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。
注意:
从上面可以看出来,我们每次都要做大量的相同的操作,并且还要对执行sql语句过程中所出现的各种异常和资源释放进行处理,而真正涉及到业务功能的代码其实很少,这明显影响了效率。
xxxxxxxxxx
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>2.4.4</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- phoenix相关依赖配置 -->
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>5.1.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-hbase-compat-2.2.5</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.14</version>
</dependency>
xxxxxxxxxx
spring
datasource
#zookeeper地址
url jdbc phoenix node2,node3,node42181
#驱动
driver-class-name org.apache.phoenix.jdbc.PhoenixDriver
#指定mybatis映射文件的地址
mybatis
mapper-locations classpath mapper/*.xml
xxxxxxxxxx
public class UserActive {
private String ROW;
// 平台统计日活跃用户
private String DAU ;
// 统计本周活跃用户
private String WAU ;
// 统计30日活跃用户
private String MAU ;
}
xxxxxxxxxx
public interface ActiveUserDao {
// 查询活跃用户
List<ActiveUser> findByAll();
}
xxxxxxxxxx
<mapper namespace="com.itbaizhan.dao.ActiveUserDao">
<select id="findByAll" resultType="com.itbaizhan.pojo.ActiveUser">
select * from "active_user"
</select>
</mapper>
xxxxxxxxxx
"/user") (
public class UserController {
private ActiveUserDao activeUserDao;
/**
* 查询所有活跃用户
* @return
*/
"/findByAllActiveUser") (
public ResultMsg findByAllActiveUser() {
return ResultMsg.ok(activeUserDao.findByAll());
}
}