To execute the query using jdbcTemplate, you can use the query method with a RowMapper to map the result set to objects. Here's an example of how you can write the query using jdbcTemplate:

String selectDsDept = "SELECT id, un_code FROM t_dept WHERE un_code IN (:values)";

List<String> values = Arrays.asList("value1", "value2", "value3"); // Set the values for the IN clause

List<Dept> deptList = jdbcTemplate.query(selectDsDept, Collections.singletonMap("values", values), new RowMapper<Dept>() {
    @Override
    public Dept mapRow(ResultSet rs, int rowNum) throws SQLException {
        Dept dept = new Dept();
        dept.setId(rs.getInt("id"));
        dept.setUnCode(rs.getString("un_code"));
        return dept;
    }
});

// Dept class represents the structure of the t_dept table
class Dept {
    private int id;
    private String unCode;

    // Getters and setters
}

In the above example, jdbcTemplate.query method is used to execute the query. The first parameter is the SQL query string, the second parameter is a map containing the named parameter and its value, and the third parameter is the RowMapper implementation to map the result set rows to Java objects.

Make sure to replace the Dept class with the appropriate class that represents the structure of the t_dept table

String selectDsDept = select idun_code from t_dept where un_code in values; jdbcTemplate怎么写查询

原文地址: https://www.cveoy.top/t/topic/iUkI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录