I. About SPRING boot
1.spring boot in short is to make spring start easier, its motto is "Just run", most spring applications need only a few configurations, using spring-boot will greatly reduce the amount of code and XML configuration files that write spring-related
2. Normally spring-boot will look for application.properties or application.yml configuration files under Classpath, most of which will be configured in this configuration file.
Two Spring boot integrated MyBatis
Gradle configuration:
// gradle Configuration: compile ("Org.springframework.boot:spring-boot-starter-web:1.4.2.release") compile (' org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0 ') { exclude group:' Org.springframework ' } compile ("mysql:mysql-connector-java:5.1.39")
APPLICATION.YML Configuration
Spring: Profiles: active:localmybatis: configuration: Log-impl: Org.apache.ibatis.logging.slf4j.Slf4jImpl cache-enabled:true interceptors: - Com.github.pagehelper.PageHelper Mapper-locations:classpath:mapper/*.xml
APPLICATION-LOCAL.YML Configuration
Spring: DataSource: username:root Password: driver-class-name:com.mysql.jdbc.driver URL: Jdbc:mysql://localhost:3306/house?characterencoding=utf8server: port:8082
Note that the configuration file is best in the root directory of Classpath
Three. Spring-boot Boot code:
PackageCom.lyhs.machineparts.run;ImportCom.lyhs.machineparts.entity.User;ImportCom.lyhs.machineparts.mapper.UserMapper;ImportOrg.mybatis.spring.annotation.MapperScan;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.annotation.ComponentScan;Importjava.sql.SQLException;Importjava.util.List;/*** 1. Note that @mapperscan annotations must be labeled at Spring-boot to scan the Mapper interface and create its proxy object, which acts like Mapperscannerconfigure * 2. Spring-boot object pooling automatically creates Sqlsessionfactorybean and Sqlsessiontemplate objects based on configuration files * 3.spring-boot benefits omit most code and configuration files * Created by Niechen on 17/7/16. */@SpringBootApplication @componentscan ("Com.lyhs") @MapperScan (basepackages= "Com.lyhs.machineparts.mapper") Public classPortalprovider { Public Static voidMain (string[] args)throwsSQLException {applicationcontext ApplicationContext= Springapplication.run (Portalprovider.class, args); Usermapper Usermapper= Applicationcontext.getbean (usermapper.class); //System.out.println (housemapper.tostring ());list<user> users =Usermapper.selectall (); for(User user:users) {System.out.println (User.getname ()); } }}
Integrated MyBatis of Spring-boot learning