Map Custom JdbcTemplate查询结果在一个对象中

Map Custom JdbcTemplate查询结果在一个对象中,第1张

Map Custom JdbcTemplate查询结果在一个对象中

创建一个合并两个表的POJO,如下所示

public class Employee {    private int id_employee;    private String name;    private int id_employee_product.    private String product_name    //getter and setters      //Don't create a constructor its Entiry}

现在,通过使用

BeanPropertyRowMapper
文档链接,将您的存储库写为

public List<Employee> fetchEmployeeProduct(){    JdbcTemplate jdbcTemplate = new JdbcTemplate("Your_DataSource");    StringBuilder query = new StringBuilder();    query.append("Your Query");    List<Employee> employeeProductList =         jdbcTemplate.query(query.toString(), new BeanPropertyRowMapper<Employee>(Employee.class));}

确保

SELECT
查询中的子句
Employee
POJO的文件名相同。

一旦执行查询,它将自动映射到POJO。您无需编写自定义映射器即可

BeanPropertyRowMapper
处理映射。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5011996.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存