Jdbctemplate
@SpringBootTest
public class JdbcTemplateTest {
?
@Autowired
ObjectMapper objectMapper;
?
@Autowired
JdbcTemplate jdbcTemplate;
?
@Test
public void testCon() {
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
System.out.println(list);
}
?
//查询全部
@Test
public void testGetAll() {
String sql = "select * from student";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
System.out.println(list);
}
?
//查询单个
@Test
public void testGetOne() {
String sql = "select * from student where rownum <=1";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
System.out.println(list);
}
?
//根据单个Id查询
@Test
public void testGetOneById() {
String sql = "select * from student where id=?";
Object[] args = new Object[]{1};
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, args);
System.out.println(list);
}
?
//根据多个参数查询
@Test
public void testGetOneByIds() {
String sql = "select * from student where id = ? and name = ?";
Object[] args = new Object[]{1, 5};
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, args);
System.out.println(list);
}
?
@Test
public void testQueryForMap() {
String sql = "select * from student where id = ? and rownum<=1 ";
Map<String, Object> map = jdbcTemplate.queryForMap(sql, 1);
System.out.println(map);
}
?
@Test
public void testQueryForObject() {
String sql = "select count(*) from student";
Integer