Spring Boot 使用 mybatis 总提示@select@insert等 不存在,为什么?

pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>

<artifactId>demo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>

<name>demo</name>

<description>Demo project for Spring Boot</description>

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.8.RELEASE</version>

<relativePath/> <!-- lookup parent from repository -->

</parent>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>

<dependency>

<groupId>org.mybatis.spring.boot</groupId>

<artifactId>mybatis-spring-boot-starter</artifactId>

<version>1.3.1</version>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<scope>runtime</scope>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<version>1.5.8.RELEASE</version>

</plugin>

</plugins>

<defaultGoal>compile</defaultGoal>

</build>

</project>

UserMapper.java 文件:

package com.my.mapper;

import com.my.entity.UserEntity;

import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Component;

import java.util.List;

// @Mapper

public interface UserMapper {

@Select("SELECT * FROM users")

// @Results({

// @Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),

// @Result(property = "nickName", column = "nick_name")

// })

List<UserEntity> getAll();

@Select("SELECT * FROM users WHERE id = #{id}")

// @Results({

// @Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),

// @Result(property = "nickName", column = "nick_name")

// })

UserEntity getOne(Long id);

@Insert("INSERT INTO users(id,namge,age) VALUES(#{id}, #{name}, #{age})")

void insert(UserEntity user);

@Update("UPDATE users SET age=#{age},name=#{name} WHERE id =#{id}")

void update(UserEntity user);

@Delete("DELETE FROM users WHERE id =#{id}")

void delete(Long id);

}

我在 GitHub 上下载了几个 Spring Boot 使用 Mybatis 的 demo,但运行后都报类似的错误,请问为什么?

图片描述

补充:
UserMapper.java 文件中:
如果把:import org.apache.ibatis.annotations.*;
改成:
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert:
..
就会报import 的错,这是不是意味着import org.apache.ibatis.annotations 这个包存在,但其中并不存在Select和Insert .. 类?这可能吗?

回答:

先执行mvn clean install

回答:

你看看你的pom,完全没引入mybatis的依赖好吧

以上是 Spring Boot 使用 mybatis 总提示@select@insert等 不存在,为什么? 的全部内容, 来源链接: utcz.com/p/178811.html

回到顶部