統合JDBC
1、基本的な操作
1.1プロジェクトの作成
1.2コンフィギュレーションパラメータ(application.properties)
spring.datasource.username =ルート spring.datasource.password = 123456 spring.datasource.url = JDBCます。mysql:// localhostを:?3306 / javas1 serverTimezone = UTC spring.datasource.driver-クラス名= com.mysql.cj .jdbc.Driver
1.3テスト
@Autowired データソースのdataSource。 @Test 公共ボイドTEST1()のSQLException {スロー するSystem.out.println(dataSource.getClass())。 System.out.println(dataSource.getConnection())。 }
図2に示すように、データベースの操作(JdbcTemplateを使用)
@Autowired JdbcTemplate jdbcTemplate。 @Test 公共ボイドTEST2(){ 一覧<ユーザー>クエリ= jdbcTemplate.query( "t_user SELECT * FROM"、BeanPropertyRowMapper.newInstance(User.class)); System.out.println(クエリ); }