zoukankan      html  css  js  c++  java
  • springboot整合mybatis

    添加mybatis依赖

    <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.1.1</version>
            </dependency>

    配置文件中配置数据源信息

    spring:
      datasource:
        driverClassName: com.mysql.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3306/springboot
        username: root
        password: root
      jpa:
        database: MySQL
        show-sql: true
        generate-ddl: true
    View Code

    编写pojo mapper接口 以及mapper映射文件

    pojo

    public class MUser implements Serializable {
        private int id;
        private String username;
        private String password;
        private String name;
    View Code

     mapper接口

    public interface UserMapper {
        List<MUser> getUserList();
    }

    mapper映射文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.offcn.mapper.UserMapper">
        <select id="getUserList" resultType="com.offcn.pojo.MUser">
            select * from user
        </select>
    </mapper>

    手动配置mybatis包扫描

      主启动类中添加@MapperScan

    @SpringBootApplication
    @MapperScan(basePackages = "com.offcn.mapper")
    public class HelloApplication {
        public static void main(String[] args){
            SpringApplication.run(HelloApplication.class,args);
        }
    }
  • 相关阅读:
    尚筹网11阿里云OSS对象存储
    阿里云的OSS对象存储
    尚筹网10用户登录
    尚筹网09用户注册
    尚筹网08环境搭建
    实体类的进一步划分
    尚筹网07分布式架构
    临时弹出一个QQ对话窗口
    Input框改placeholder中字体的颜色
    判断银行卡号的正则
  • 原文地址:https://www.cnblogs.com/proyuan/p/11802288.html
Copyright © 2011-2022 走看看