<!--方式一: dbcp 数据源配置,在测试环境使用单连接 -->
	<bean >
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/police" />
		<property name="username" value="root" />
		<property name="password" value="root" />
	</bean>

  

    <!-- spring jdbcTemplate sql 查询-->
	<bean >
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean > <!-- dao 层使用 jdbcTemplate -->
		<property name="jdbcTemplate" ref="jdbcTemplate" />
	</bean>

  DAO底层使用 JdbcTemplate 

  JdbcTemplate jdbcTemplate;

    private JdbcTemplate jdbcTemplate;

    /*set get 封装方法*/
       //简单的列表
	public List<Map<String, Object>> queryForList(String sql) {
		return this.getJdbcTemplate().queryForList(sql);
	}	
	
	public Map<String, Object> queryForMap(String sql) {
		return this.getJdbcTemplate().queryForMap(sql);
	}

 query 方法:

 JdbcTemplate类对sql的操作使用

相关文章:

  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-10-21
  • 2021-10-07
猜你喜欢
  • 2022-01-11
  • 2022-03-05
  • 2021-05-16
  • 2022-12-23
  • 2021-10-07
相关资源
相似解决方案