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);
        }
    }
  • 相关阅读:
    HDU
    矩形嵌套(DP)
    HDU
    HDU-1003 Max Sum
    Manacher算法—最长回文串
    Codeforces Round #460 (Div. 2) A B C D
    HDU 4540 威威猫系列故事——打地鼠 (简单DP)
    UVA 129 Krypton Factor(DFS 回溯)
    Codeforces 918A Eleven 918B Radio Station
    挑战程序设计竞赛(第2版)第112页勘误
  • 原文地址:https://www.cnblogs.com/proyuan/p/11802288.html
Copyright © 2011-2022 走看看