Problems with spring inserting data using namedParameterJdbcTemplate

Why use Map < String, Object > when inserting data?

@Test
public void testNamedParameterJdbcTemplate() {
    String sql = "INSERT INTO employees(last_name,email,dept_id) VALUES(:ln,:email,:deptid)";
    Map<String, Object> paramMap = new HashMap<>();
    
    paramMap.put("ln", "FF");
    paramMap.put("email", "FF@qq.com");
    paramMap.put("deptid", 2);
    
    
    namedParameterJdbcTemplate.update(sql, paramMap);
    
    
}
May.22,2021

because jdbcTemplate will eventually be assigned through the precompiled statement ps.setObject (name,value) of jdbc , where name is the attribute name, so the key of Map is the type of String , but the type of value is not known, so the Map is fine.

Menu