• 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);
        }
    }
  • 相关阅读:
    Confluo: Distributed Monitoring and Diagnosis Stack for High-speed Networks
    kubernetes in action
    kubernetes in action
    kubernetes in action
    kubernetes in action
    kubernetes in action
    Kafka: Exactly-once Semantics
    Reinforcement Learning
    unity的 Social API
    hdu 4336 概率dp + 状压
  • 原文地址:https://www.cnblogs.com/proyuan/p/11802288.html
Copyright © 2020-2023  润新知