一.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. 《高级软件测试》云平台Jira的配置

    首先点击进入以下网址: https://www.atlassian.com/ondemand/signup/form?product=jira-software.ondemand 填写好信息,Star ...

  2. LR之error(一)

    1 录制时频繁卡死的解决方案 添加数据保护 路径:计算机--高级系统设置(环境变量设置的上级窗口)--高级--设置--数据执行保护 更改LR录制设置,将run-time setting的brower改 ...

  3. Hey,man,are you ok? -- 关于心跳、故障监测、lease机制

    电话之于短信.微信的一个很大的不同点在于,前者更加及时,有更快速直接的反馈:而后面两个虽然称之为instant message,但经常时发出去了就得等对方回复,等多久是不确定的.打电话能明确知道对方在 ...

  4. linux下xargs和管道的区别

    管道将前面的标准输出作为后面的标准输入,xargs则将标准输入作为命令的参数 一.简介 1.背景 之所以能用到这个命令,关键是由于很多命令不支持|管道来传递参数,而日常工作中有有这个必要,所以就有了x ...

  5. 大数据学习总结(5)参考elk技术架构

  6. GIT入门笔记(11)- 多种撤销修改场景和对策--实战练习

    1.检查发现目前没有变化$ git statusOn branch masternothing to commit, working tree clean $ cat lsq.txt2222 2.修改 ...

  7. J2ee入门:servlet-mapping的映射配置

    <servlet-mapping>元素在Servlet和URL样式之间定义一个映射.它包含了两个子元素<servlet- name>和<url-pattern> & ...

  8. PL/SQL Developer 导入导出操作

    一.PL/SQL Developer数据导入 Tools->Import Tables

  9. 详解Ajax请求(二)——异步请求原理的分析

    在上一文章里,我们分析了同步请求的原理.当浏览器向服务器发送同步请求时,服务处理同步请求的过程中,浏览器会处于等待的状态,服务器处理完请求把数据响应给浏览器并覆盖浏览器内存中原有的数据,浏览器重新加载 ...

  10. Stanford依存句法关系解释

    ROOT:要处理文本的语句 IP:简单从句 NP:名词短语 VP:动词短语 PU:断句符,通常是句号.问号.感叹号等标点符号 LCP:方位词短语 PP:介词短语 CP:由'的'构成的表示修饰性关系的短 ...