spring/spring boot+mybatis+phoenix
This commit is contained in:
		| @@ -0,0 +1,4 @@ | ||||
| # <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD> | ||||
| phoenix.driverClassName=org.apache.phoenix.jdbc.PhoenixDriver | ||||
| # zookeeper<65><72>ַ | ||||
| phoenix.url=jdbc:phoenix:192.168.0.105:2181 | ||||
| @@ -0,0 +1,24 @@ | ||||
| <!DOCTYPE mapper | ||||
|         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||||
|         "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
|  | ||||
| <mapper namespace="com.heibaiying.dao.PopulationDao"> | ||||
|  | ||||
|  | ||||
|     <select id="queryAll" resultType="com.heibaiying.bean.USPopulation"> | ||||
|         SELECT * FROM us_population | ||||
|     </select> | ||||
|  | ||||
|     <insert id="save"> | ||||
|         UPSERT INTO us_population VALUES( #{state}, #{city}, #{population} ) | ||||
|     </insert> | ||||
|  | ||||
|     <select id="queryByStateAndCity" resultType="com.heibaiying.bean.USPopulation"> | ||||
|         SELECT * FROM us_population WHERE state=#{state} AND city = #{city} | ||||
|     </select> | ||||
|  | ||||
|     <delete id="deleteByStateAndCity"> | ||||
|         DELETE FROM us_population WHERE state=#{state} AND city = #{city} | ||||
|     </delete> | ||||
|  | ||||
| </mapper> | ||||
| @@ -0,0 +1,17 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE configuration | ||||
|         PUBLIC "-//mybatis.org//DTD Config 3.0//EN" | ||||
|         "http://mybatis.org/dtd/mybatis-3-config.dtd"> | ||||
|  | ||||
| <!-- mybatis 配置文件 --> | ||||
| <configuration> | ||||
|     <settings> | ||||
|         <!-- 开启驼峰命名 --> | ||||
|         <setting name="mapUnderscoreToCamelCase" value="true"/> | ||||
|         <!-- 打印查询sql --> | ||||
|         <setting name="logImpl" value="STDOUT_LOGGING"/> | ||||
|     </settings> | ||||
|  | ||||
| </configuration> | ||||
|  | ||||
| <!--更多settings配置项可以参考官方文档: <a href="http://www.mybatis.org/mybatis-3/zh/configuration.html"/>--> | ||||
| @@ -0,0 +1,38 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <beans xmlns="http://www.springframework.org/schema/beans" | ||||
|        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|        xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" | ||||
|        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||||
|         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> | ||||
|  | ||||
|     <!-- 开启注解包扫描--> | ||||
|     <context:component-scan base-package="com.heibaiying.*"/> | ||||
|  | ||||
|     <!--指定配置文件的位置--> | ||||
|     <context:property-placeholder location="classpath:jdbc.properties"/> | ||||
|  | ||||
|     <!--配置数据源--> | ||||
|     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> | ||||
|         <!--Phoenix配置--> | ||||
|         <property name="driverClassName" value="${phoenix.driverClassName}"/> | ||||
|         <property name="url" value="${phoenix.url}"/> | ||||
|     </bean> | ||||
|  | ||||
|     <!--配置 mybatis 会话工厂 --> | ||||
|     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> | ||||
|         <property name="dataSource" ref="dataSource"/> | ||||
|         <!--指定mapper文件所在的位置--> | ||||
|         <property name="mapperLocations" value="classpath*:/mappers/**/*.xml"/> | ||||
|         <property name="configLocation" value="classpath:mybatisConfig.xml"/> | ||||
|     </bean> | ||||
|  | ||||
|     <!--扫描注册接口 --> | ||||
|     <!--作用:从接口的基础包开始递归搜索,并将它们注册为 MapperFactoryBean(只有至少一种方法的接口才会被注册;, 具体类将被忽略)--> | ||||
|     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> | ||||
|         <!--指定会话工厂 --> | ||||
|         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> | ||||
|         <!-- 指定mybatis接口所在的包 --> | ||||
|         <property name="basePackage" value="com.heibaiying.dao"/> | ||||
|     </bean> | ||||
|  | ||||
| </beans> | ||||
		Reference in New Issue
	
	Block a user