MapperRegistry 不知道映射器文件

我试图在 Spring Boot 上使用 mybatis 显示 mysql 数据库中的所有数据。但是,MapperRegistry 不知道 mapper.xml 文件。


我试过更改 application.yaml 的类路径。


应用程序.yaml


mybatis:

  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


慕桂英4014372
浏览 83回答 1
1回答

MYYA

你需要添加一个接口来匹配 ShopMapper.xml@Mapperpublic interface ShopMapper {&nbsp; &nbsp; Shop get(Long shopId);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java