• SpringBoot整合mybatis


    引入依赖

            <!--整合mybatis-->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.4</version>
            </dependency>
    

    在application.yml添加配置

    # 配置mybatis规则
    mybatis:
    #  config-location: classpath:mybatis/mybatis-config.xml #config-location与configuration配置不能同时存在
      mapper-locations: classpath:mybatis/mapper/*.xml
      configuration: #指定mybatis全局配置文件中的相关配置项
        map-underscore-to-camel-case: true #开启驼峰命名规则
    

    测试访问

    准备测试代码

    @Data
    public class Account {
    
        private Integer id;
        private String contact;
        private String addressDesc;
        private String postCode;
        private String tel;
    }
    
    @Mapper
    public interface AccountMapper {
    
        public Account getAcct(Integer id);
    }
    
    <?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.atguigu.admin.mapper.AccountMapper">
        <select id="getAcct" resultType="com.atguigu.admin.bean.Account">
            select * from user_account where id = #{id}
        </select>
    </mapper>
    
    @Service
    public class AccountService {
    
        @Autowired
        AccountMapper accountMapper;
    
        public Account getAcctById(Integer id){
            return accountMapper.getAcct(id);
        }
    }
    
        @ResponseBody
        @GetMapping("/acct")
        public Account getById(@RequestParam("id") Integer id){
           return accountService.getAcctById(id);
        }
    

    localhost:8080/acct

  • 相关阅读:
    团队项目-Beta冲刺(第一周)
    个人第4次作业—Alpha项目测试
    团队项目——Alpha发布2
    优课堂考勤系统——Alpha发布1
    优课堂—系统设计
    优课堂—需求分析
    thrift学习笔记
    APP分享
    ActionBar
    ListView添加headview
  • 原文地址:https://www.cnblogs.com/kaka-qiqi/p/15150384.html
Copyright © 2020-2023  润新知