springboot集成mybaties详细步骤

       关于springboot集成mybaites,虽然springboot支持mybaties的集成,但是在官方文档中并没有详细的配置说明。这里和大家分享一下,mybaties在springboot中集成的详细使用。

     第一:导入相关的包。

springboot集成mybaties详细步骤_第1张图片
相关包截图

2,配置相关的properties文件信息

spring.datasource.password=数据库密码

spring.datasource.username=数据库用户吗

spring.datasource.url=jdbc:mysql://ip:端口/库名?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE

mybatis.mapper-locations=classpath:mapper/*.xml(指定sql语句文件位置)

3,相关的sql文件和mapper文件(这里步细诉)

@Component

public interfaceTbTestMapper {

intinserts(@Param("tests")List tests);//@Param("tests")指定参数和参数名

}

4,启动类添加@MapperScan("text.mapper")指定mapper文件位置。

通过这个位置,可以知道所有mybaties相关信息。

/**

*@author:kewei.zhang

*@Date:2017/10/19

*@Time:下午2:33

* Description:

*/

@SpringBootApplication

@EnableScheduling

@MapperScan("me.ele.mapper")

public classSkynetApplication {

public static voidmain(String[] args){

SpringApplication.run(SkynetApplication.class,args);

}

}

通过上述配置即可完成mybaties的集成。

你可能感兴趣的:(springboot集成mybaties详细步骤)