要通過LinkedHashMap獲取MyBatis查詢的鍵值對,你需要按照以下步驟操作:
user
的表,你可以創建一個名為getUserMap
的查詢: SELECT id, username, email
FROM user
</select>
這里,我們選擇了id
、username
和email
列,并將結果映射為一個LinkedHashMap。
public interface UserMapper {
List<LinkedHashMap<String, Object>> getUserMap();
}
getUserMap
方法來獲取查詢結果:@Autowired
private UserMapper userMapper;
public void getUserMap() {
List<LinkedHashMap<String, Object>> userMapList = userMapper.getUserMap();
for (LinkedHashMap<String, Object> userMap : userMapList) {
System.out.println("ID: " + userMap.get("id"));
System.out.println("Username: " + userMap.get("username"));
System.out.println("Email: " + userMap.get("email"));
}
}
這樣,你就可以通過LinkedHashMap獲取MyBatis查詢的鍵值對了。注意,這里的鍵是列名,值是對應的數據。