springboot集成mybaties用oracle

集成mybaties

 <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

然后创建类
controller

  UserInfo userInfo=userService2.getUserByTel(telePhone);

services

public UserInfo getUserByTel(String telePhone) {
        return  user.getUserByTel(telePhone);
    }

最后是mapper和xml

@Mapper
public interface AppUser {

    UserInfo getUserByTel(String telePhone);

    void saveUserByTel();
}

然后xml

<mapper namespace="com.xxx.model.UserInfo" >
    <select id="getUserByTel" resultType="com.guangda.model.UserInfo">
        select * from t_gd_userinfo where usertel LIKE '%'#{name }'%'
    </select>
    <insert id="getUserByTel" parameterType="com.guangda.model.UserInfo">
        <selectKey keyProperty="id" resultType="java.lang.String"
                   order="BEFORE">
            select replace(uuid(),'-','') from dual
        </selectKey>
         insert into t_gd_userinfo(id,stuname,stuage) values(#{stuNo},#{stuName},#{stuAge})
    </insert>

</mapper>

最后在启动类头加上
@MapperScan({“com.guangda.mapper”})

@SpringBootApplication
@MapperScan({"com.guangda.mapper"})
public class Application {

**

集成oracle

添加依赖

<dependency>
             <groupId>com.oracle</groupId>
             <artifactId>ojdbc7</artifactId>
       		 <version>12.1.0.2</version>
</dependency>

**
然后application.properties配置数据库信息

#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521/orcl
spring.datasource.username=esp_dev
spring.datasource.password=esp_dev
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.exceptionSorter=true
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.filters=stat,log4j
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 
spring.datasource.useGlobalDataSourceStat=true

最后启动项目

你可能感兴趣的:(代码,配置,java,oracle,mybatis)