快速搭建一个Spring+Mybaties框架

最近上手项目发现自己大框架都忘了,于是好好整理下搭框架的过程


前言

在这里插入图片描述

值得注意的是:

1、配置文件Application.yaml 中 指定sql映射文件位置

  • classPath:是以Resource为根目录。 而且一定开头要带“/”
  • 该路径是xml写增删改查的地方的
    # 指定sql映射文件位置
  mapper-locations: classpath:/mapper/*.xml

2、xml文件中

  • namespace:填写映射当前的Mapper接口
  • select id=“seeAll” 是当前sql方法的名字,在映射的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">
<!-- namespace:填写映射当前的Mapper接口,所有的增删改查的参数和返回值类型,
		就可以直接填写缩写,不区分大小写,直接通过方法名去找类型-->
<mapper namespace="com.hkvision.hire.mapper.UserMapper">
    <select id="seeAll" resultType="com.hkvision.hire.pojo.User">
        select * from user
    </select>
</mapper>

总结

路漫漫其修远兮;踏实的走好每一步!

猜你喜欢

转载自blog.csdn.net/qq_36737214/article/details/118033009