1. 程式人生 > >jdbctemplate中用in查詢用法

jdbctemplate中用in查詢用法

試了半天,終於找到了
JdbcTemplate中in的用法,
JdbcTemplate自己不能使用in,藉助
NamedParameterJdbcTemplate 能實現in的用法
@Autowired
private DataSource dataSource;//資料來源注入即可使用

public void assignBatch(List<String> todoIds, String teamMemberId) {
    todoDao.assignBatch(todoIds,teamMemberId);
    //批量指派新增訊息提醒
String sql = "select fm.id,sa.username,td.TODO_CONTENT from todo td 
\n" + "INNER JOIN ORG_MEMBER_INFO omi on td.TEAM_MEMBER_ID = OMI.id\n" + "INNER JOIN SYS_ACCOUNT sa on omi.sys_account_id = sa.id\n" + "INNER JOIN FAMILY_MEMBER fm on td.family_member_id = fm.id\n" + "where td.todo_id in (:todoIds)"; Map<String, Object> paramMap = new
HashMap<>(); paramMap.put("todoIds", todoIds); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); List<Map<String, Object>> mapList = namedParameterJdbcTemplate.queryForList(sql,paramMap); List<String> familyMemberIds = new
ArrayList<>(); List<String> executorNames = new ArrayList<>(); List<String> todoContents = new ArrayList<>(); for(Map<String, Object> map : mapList){ for(String key : map.keySet()){ if(key.equals("ID")){ familyMemberIds.add(map.get(key).toString()); }else if(key.equals("USERNAME")){ executorNames.add(map.get(key).toString()); }else if(key.equals("TODO_CONTENT")){ todoContents.add(map.get(key).toString()); } } } for(int i = 0; i < familyMemberIds.size(); i ++){ iMessageService.addAdminMessage(familyMemberIds.get(i),"1","團隊長已指派醫生"+ executorNames.get(i) +"為你服務,內容為:"+todoContents.get(i),"指派服務"); } }