SpringBoot入门-集成mybatis(四)

pom.xml

org.springframework.boot
        spring-boot-starter-parent
        1.5.2.RELEASE

        UTF-8
        UTF-8
        1.8

            org.projectlombok
            lombok
            1.16.18

            org.springframework.boot
            spring-boot-starter-data-jpa

            mysql
            mysql-connector-java
            6.0.6

            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.1

            com.alibaba
            druid
            1.1.5

            org.springframework.boot
            spring-boot-starter-web

            org.springframework.boot
            spring-boot-starter-test
            test

            org.springframework.boot
            spring-boot-devtools

                org.springframework.boot
                spring-boot-maven-plugin

application.yml

config-location: classpath:mapper/mybatis-config.xml

undefined

mybatis-config.xml (打印预编译SQL语句)

DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
"logImpl" value="STDOUT_LOGGING" />

Dao

package com.vast.dao;

import com.vast.entity.Account;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface IAccountMybatisDao {

    public int saveAccount(Account account);

    public List queryAccountInfoById(Integer id);
}

资源文件夹下建立xml

SpringBoot入门-集成mybatis(四)
insert into account(id, name, money)
        values (#{id}, #{name}, #{money})

        select * from Account

Dao注入被调用类

@Autowired
    private IAccountMybatisDao accountMybatisDao;

Original: https://www.cnblogs.com/yanduanduan/p/12010739.html
Author: 风又奈何
Title: SpringBoot入门-集成mybatis(四)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/541174/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球