一.spring boot集成Mybatis

gradle配置:

//gradle配置:
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配置

spring:
profiles:
active: local mybatis:
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
cache-enabled: true
mapper-locations: classpath:mapper/*.xml

application-local.yml配置

spring:
datasource:
username: root
password:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/house?characterEncoding=utf8
server:
port: 8082

注意此处配置文件最好在classpath的根目录下

三.spring-boot启动代码:

package com.lyhs.machineparts.run;

import com.lyhs.machineparts.entity.User;
import com.lyhs.machineparts.mapper.UserMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan; import java.sql.SQLException;
import java.util.List; /**
* 1.注意@MapperScan注解必须在spring-boot处标注,作用是扫描Mapper接口并创建其代理对象,作用类似于MapperScannerConfigure
* 2.spring-boot对象池自动将根据配置文件自动创建SqlSessionFactoryBean与SqlSessionTemplate对象
* 3.spring-boot的好处省略绝大多数代码及配置文件
* Created by niechen on 17/7/16.
*/
@SpringBootApplication
@ComponentScan("com.lyhs")
@MapperScan(basePackages = "com.lyhs.machineparts.mapper")
public class PortalProvider {
public static void main(String[] args) throws SQLException {
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());
}
}
}

SpringBoot学习之集成mybatis的更多相关文章

  1. SpringBoot系列之集成Mybatis教程

    SpringBoot系列之集成Mybatis教程 环境准备:IDEA + maven 本博客通过例子的方式,介绍Springboot集成Mybatis的两种方法,一种是通过注解实现,一种是通过xml的 ...

  2. springboot学习2 整合mybatis

    springboot整合mybatis 一.添加mybatis和数据库连接的依赖 <!--整合mybatis--> <dependency> <groupId>or ...

  3. SpringBoot学习之整合Mybatis

    本博客使用IDEA开发工具,通过Maven构建SpringBoot项目,初始化项目添加的依赖有:spring-boot-starter-jdbc.spring-boot-starter-web.mys ...

  4. SpringBoot学习之集成dubbo

    一.摘自官网的一段描述 1.背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 ...

  5. 尚硅谷springboot学习33-整合mybatis

    引入mybatis依赖(还要引入mysql和jdbc依赖) <dependency> <groupId>org.mybatis.spring.boot</groupId& ...

  6. SpringBoot(九)_springboot集成 MyBatis

    MyBatis 是一款标准的 ORM 框架,被广泛的应用于各企业开发中.具体细节这里就不在叙述,大家自行查找资料进行学习下. 加载依赖 <dependency> <groupId&g ...

  7. springboot 零xml集成mybatis

    maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  8. SpringBoot学习:整合Mybatis,使用HikariCP超高性能数据源

    一.添加pom依赖jar包: <!--整合mybatis--> <dependency> <groupId>org.mybatis.spring.boot</ ...

  9. SpringBoot学习:整合MyBatis,使用Druid连接池

    项目下载地址:http://download.csdn.NET/detail/aqsunkai/9805821 (一)添加pom依赖: <!-- https://mvnrepository.co ...

随机推荐

  1. zookeeper提示Unable to read additional data from server sessionid 0x

    配置zookeeper集群,一开始配置了两台机器server.1和server.2. 配置参数,在zoo.cfg中指定了整个zookeeper集群的server编号.地址和端口: server.1=1 ...

  2. SQL之Left Join 关联条件的探讨

    在测试工作中,有时需要测试数据库数据经过sql计算后的结果是否满足某一功能查询得到的返回值. 针对某些需要功能需要联查多张表,此时 关联 的作用就异常重要了,而针对多表关联,其中 关联条件的重要性不言 ...

  3. OpenShift实战(三):OpenShift持久化存储Redis

    1.模板定义 修改OpenShift自带模板 [root@master1 pv]# oc edit template redis-persistent 添加如下: 2.创建PV 编辑redis pv ...

  4. Hadoop2.6.0实践:001 伪分布式环境搭建

    ##################### Centos6.4VM_01_os.rar ################################################准备工作/opt ...

  5. 使用java 打印日历

    package hangshu; /* * 打印从1900年到2.year年的日历 */ import java.util.Scanner; public class Calender { publi ...

  6. python flask框架 tempates 模版的使用

    在py文件同级下 建立templates文件夹,再文件夹中编写html文件 1 向模版中传递参数: ''' 1 向模板传送 参数 ''' @app.route('/') def index(): na ...

  7. [BZOJ4011][HNOI2015] 落忆枫音(学习笔记) - 拓扑+DP

    其实就是贴一下防止自己忘了,毕竟看了题解才做出来 Orz PoPoQQQ 原文链接 Description 背景太长了 给定一个DAG,和一对点(x, y), 在DAG中由x到y连一条有向边,求生成树 ...

  8. 详解Class

    Classs是es6提供的类,相当于es5的构造函数. 写法: class Foo { constructor () { // new 的时候会调用该方法,可以通过return改变构造函数的返回值 r ...

  9. Tensorflow会话Session

    转载自: http://blog.csdn.net/Hanging_Gardens/article/details/72784392 https://www.cnblogs.com/hypnus-ly ...

  10. javascript获取表单的各项值

    何谓表单? 表单是html页面中负责数据采集功能的部件,它往往由三个部分组成: 表单标签:<form></form> 用于声明表单的范围,位于表单标签中的元素将被提交.属性有m ...