報錯截圖:

解決方法:
只能掃描到自定義的mapper,不能掃描到其他文件。
@MapperScan("com.streamax.s17.tms.dao.pper.repository")
1. 繼承通用Mapper
此接口不能同其他Mapper一起,該類不能被當做普通Mapper一樣被掃描,否則會出錯。
package com.streamax.s17.tms.dao.mapper.core; import tk.mybatis.mapper.common.BaseMapper; import tk.mybatis.mapper.common.MySqlMapper; /** * @author cf * @date 2018/11/21 */ public interface CoreMapper<T> extends BaseMapper<T>, MySqlMapper<T> { }
2. 自定義Mapper繼承CoreMapper
自定義的 Mapper 通過對應有xml的映射文件
自定義Mapper.java要特別注意,不能同上面的Mapper定義在同一個包下
package com.streamax.s17.tms.dao.mapper.repository; import com.streamax.s17.tms.dao.entity.TokenEntity; import com.streamax.s17.tms.dao.mapper.core.CoreMapper; /** * @author cf * @date 2018/11/21 */ public interface TokenMapper extends CoreMapper<TokenEntity> { /** * 根據 entityId 查詢token * * @param entityId */ TokenEntity selectByEntityId(String entityId); }
3. MapperScan
package com.streamax.s17.tms; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
// 只掃描自定義mapper所在包,不能掃描到繼承通用mapper所在包 @MapperScan("com.streamax.s17.tms.dao.mapper.repository") public class TmsApplication { public static void main(String[] args) { SpringApplication.run(TmsApplication.class, args); } }
