我有个问题。当我使用 spring data jpa 时,我希望它返回 Map Collections,但它错了。然后我在互联网上搜索找到了解决方案。流动。
@Transactional(readOnly = true)
public interface GoodsRepository extends JpaRepository<TbGoodsEntity, Integer> {
@Query(value = "select new map(t.id as id, t.goodsName as goodsName) from TbGoodsEntity t group by t.goodsName")
public List<Map<String, Object>> getGoodsNames();// it`s ok,
@Query(value = "select * from tb_goods t group by t.goodsName", nativeQuery = true)
public List<Map<String, Object>> getGoods();//it`s error
}
但我不认为使用新地图方法是最好的解决方案,我想问一下是否有其他解决方案。谢谢。