gpt4 book ai didi

java - Mybatis 结果声明重用

转载 作者:行者123 更新时间:2023-11-29 09:47:04 25 4
gpt4 key购买 nike

以下代码是工作映射器类,但它具有结果集声明的复制过去(在我的例子中这是巨大的)。
我如何重用@Results 声明?

@Mapper
public interface DailyMasterCurrentTradeDao {
@Select("select * from dly_mstr_curr_trd")
@Results({
@Result(property = "accAdsStC", column = "ACC_ADS_ST_C"),
...
})
List<DailyMasterCurrentTrade> selectDailyMasterCurrentTrades();

@Select("select * from dly_mstr_curr_trd where rownum < #{rownumThreshold}")
@Results({
@Result(property = "accAdsStC", column = "ACC_ADS_ST_C"),
...
})
List<DailyMasterCurrentTrade> selectFewDailyMasterCurrentTrades(long rownumThreshold);
}

最佳答案

您可以使用@ResultMap 来引用/重用另一个@Results 定义。

@Select("SELECT * FROM user where id = ${value}")
@ResultMap("userResult")
User findOne(Long id);

@Select("SELECT * FROM user")
@Results(id = "userResult", value = {
@Result(property = "id", column = "id", id = true),
@Result(property = "name", column = "name"),
@Result(property = "phone", column = "phone")
})
List<User> findAll();

详情请引用这里:https://github.com/mybatis/mybatis-3/issues/155

关于java - Mybatis 结果声明重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com