Spring queryformap method: query results are saved in the map collection
•
Java
Grammar 1
queryForMap(String sql)
Example
public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //加载配置文件 Dao dao = (Dao)context.getBean("dao"); //创建Dao JdbcTemplate jtm = dao.getJdbcTemplate(); String sql = "select*from tb_user where id=1"; //创建一条sql语句 Map map = jtm.queryForMap(sql); System.out.println(map); }
Grammar 2
queryForMap(String sql,Object[] args)
Example
public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //加载配置文件 Dao dao = (Dao)context.getBean("dao"); //创建Dao JdbcTemplate jtm = dao.getJdbcTemplate(); String sql = "select*from tb_user where age=?and sex=?limit 1"; //创建一条sql语句 Object[] sqlArgs = {27,"男"}; Map map = jtm.queryForMap(sql,sqlArgs); System.out.println(map); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码