搭建項(xiàng)目時(shí)使用了mybatisplus,項(xiàng)目能夠正常啟動(dòng),但在調(diào)用mapper方法查詢數(shù)據(jù)庫時(shí)報(bào)Invalid bound statement (not found)錯(cuò)誤。
以下為項(xiàng)目配置
pom文件
1
2
3
4
5
|
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version> 3.3 . 0 </version> </dependency> |
application.yml
1
2
3
4
5
6
7
8
9
10
11
|
mybatis-plus: configuration: map-underscore-to-camel- case : true # 雖然默認(rèn)為 true ,但是還是顯示去指定下。 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl global-config: db-config: id-type: AUTO logic-delete-value: "Y" # 邏輯已刪除值(默認(rèn)為 Y) logic-not-delete-value: "N" #邏輯未刪除值(默認(rèn)為 N) mapper-locations: classpath*:mapper/*.xml type-aliases- package : com.test.model |
啟動(dòng)類
1
2
3
4
5
6
7
8
|
@MapperScan (basePackages = { "com.test.dao" }) public class MyApplication { public static void main(String[] args) throws Exception { SpringApplication.run(MyApplication. class , args); } } |
mapper接口
1
2
3
|
@Repository public interface PcToolMapper extends BaseMapper<PcToolNameDO> { } |
PcToolNameDO實(shí)體類
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@Data @TableName ( "pc_tool_name" ) public class PcToolNameDO { @TableId (value = "id" , type = IdType.AUTO) private Integer id; private String pcToolName; private Date createTime; private String createUser; private Date updateTime; private String updateUser; private Long tenantId; } |
出現(xiàn)問題的原因:
缺少mybatisplus的核心依賴
因?yàn)轫?xiàng)目啟動(dòng)并沒有報(bào)錯(cuò),所以沒往缺少依賴上想,項(xiàng)目中寫了mapper.xml,但沒有自定義sql,剛開始以為項(xiàng)目沒有加載mapper.xml文件,其實(shí)如果項(xiàng)目中用不到自己寫的sql語句,就沒有必要寫mqpper.xml文件,我把這個(gè)xml文件刪除了還是不行。
解決辦法:
在pom中添加mybatis的核心依賴
1
2
3
4
5
|
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version> 3.3 . 0 </version> </dependency> |
mybatis-plus-extension這個(gè)時(shí)擴(kuò)展依賴,像我在實(shí)體中使用到了@TableName注解,它是擴(kuò)展包中的,核心是mybatis-plus-boot-starter
總結(jié)
到此這篇關(guān)于mybatisplus報(bào)Invalid bound statement (not found)錯(cuò)誤的文章就介紹到這了,更多相關(guān)mybatisplus報(bào)Invalid bound statement 錯(cuò)誤內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/weixin_49456013/article/details/108244638