Skip to content

Instantly share code, notes, and snippets.

@smallsong
Created August 13, 2018 09:07
Show Gist options
  • Save smallsong/e7e38810d3ef299b968bed55ebec924b to your computer and use it in GitHub Desktop.
Save smallsong/e7e38810d3ef299b968bed55ebec924b to your computer and use it in GitHub Desktop.
直接把查询结果输出位Map
public List<?> findAllGameStateByUnitIdAndUserId(int unitId, int userId) {
Query query = entityManager.createNativeQuery("SELECT b.*, IF(c.id > 0, 1, 0) as is_finish FROM `wx_unit_game` a" +
" left join `wx_catalog` b on a.game_id = b.id" +
" left join `wx_unit_game_progress` c on c.game_id = a.game_id and c.user_id = :userId" +
" WHERE a.unit_id = :unitId and b.game_is_lock = 1");
query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
query.setParameter("userId", userId);
query.setParameter("unitId", unitId);
List result = query.getResultList();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment