我试图在 Spring Boot 上使用 mybatis 显示 mysql 数据库中的所有数据。但是,MapperRegistry 不知道 mapper.xml 文件。我试过更改 application.yaml 的类路径。应用程序.yamlmybatis: mapper-locations: classpath:com/example/demo/repository/mybatis/*.xml店铺类public class Shop { private String shopId; private String shopName; public Shop() { } public Shop(String shopId, String shopName) { this.shopId = shopId; this.shopName = shopName; }}ShopMapper.xml <!-- Mapping Shop Class to Shop tables --> <resultMap id="Shop" type="com.example.demo.domain.Shop"> <id property="shopId" column="SHOP_ID"/> <result property="shopName" column="SHOP_NAME"/> </resultMap> <!-- Show all shops with the designated shopid --> <select id="get" resultMap="Shop"> SELECT SHOP_ID, SHOP_NAME FROM SHOP WHERE SHOP_ID = #{shopId} </select></mapper>商店资料库public Shop findOne(String shopId) { Shop shop = this.sqlSessionTemplate.getMapper(ShopMapper.class).get(shopId); return shop;}控制器@RestController public class PageController { @GetMapping(path = "/{shopId}", produces = "application/json") public Shop get(@PathVariable String shopId) { return this.service.get(shopId); }}错误:org.apache.ibatis.binding.BindingException:MapperRegistry 不知道类型接口 com.example.demo.repository.mybatis.ShopMapper
1 回答
MYYA
TA贡献1868条经验 获得超4个赞
你需要添加一个接口来匹配 ShopMapper.xml
@Mapper
public interface ShopMapper {
Shop get(Long shopId);
}
添加回答
举报
0/150
提交
取消