通常有兩種原因,配置原因,或者是mapper相關文件,mapper.java或 mapper.xml內部錯誤

如果是配置原因
解決方式1
統一配置mapper
//import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan("com.example.mybatisplus.mapper") //把這個加上,別寫上正確的路徑,如果是模塊化一般路徑為@MapperScan("com.kfit.*.mapper")
public class Application { public static void main(String[] args){ System.out.println("hahahaha"); SpringApplication.run(Application.class, args); } }
解決方式2
每個mapper文件配置@Mapper
package com.example.mybatisplus.mapper; //import org.apache.ibatis.annotations.Mapper; import com.baomidou.mybatisplus.mapper.BaseMapper; import com.example.mybatisplus.entity.Person; @Mapper //每個文件配置這個
public interface PersonMapper extends BaseMapper<Person> {
Integer listCount();
Person findPersonById(Integer id);
}
兩者可以結合使用
