Featured image of post MyBatis快速配置檔

MyBatis快速配置檔

真他媽垃圾MyBatis 誰用誰傻B

每次他媽用MyBatis,都他媽出一些白癡問題,真的不懂他媽一堆公司抱著MyBatis這垃圾到底是要欉三小

MyBatis相關Dependency

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
       <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus -->
        <!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>4.2.3</version>
        </dependency>

Properties的配置

然後記得在properties中配置xml的位置

1
mybatis.mapper-locations=classpath:mapper/*.xml

image-20240313004154323

Mapper的寫法

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
package com.hoxton.urlshorter.mapper;

import com.hoxton.urlshorter.entity.Url;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.BaseMapper;


@Mapper
@Repository
public interface ShorterMapper
        extends BaseMapper<Url>
{
   String findByShortURL(@Param("url") String shortURL);



}

Licensed under CC BY-NC-SA 4.0