JavaEE Spring~MyBatis是如何一步一步实现数据库查询的?

配置好一个SptingBoot项目配置好MyBatis

JavaEE Spring~MyBatis是什么? 它和Hibernate的区别有哪些?如何配置MyBatis?

SpringBoot配置文件application.properties简单介绍

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

确保MyBatis配置正确

在这里插入图片描述
在这里插入图片描述

手动实现一个xml文件

上面我是用的是一个自定义的接口 此时没有它对应的xml文件 此时我们需要
在这里插入图片描述
下图中column表示查询列, property表示返回类型中的属性
在这里插入图片描述
在这里插入图片描述

在Controller中进行测试

package listen.controller;

import listen.mapper.TestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description: If you don't work hard, you will a loser.
 * User: Listen-Y.
 * Date: 2020-08-21
 * Time: 23:14
 */
@RestController
@RequestMapping(value = "user")
public class MyselfTest {
    
    

    @Autowired
    private TestMapper testMapper;

    @RequestMapping(value = "test")
    public Object test() {
    
    
        return testMapper.query(1);
    }

}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Shangxingya/article/details/108161346