赞
踩
// 查询
@Override
public int selectCount() {
// 1创建sql语句
String sql = "select count(*) from t_user";
int count = jdbcTemplate.queryForObject(sql, Integer.class);
return count;
}
测试
// 查询
@Test
public void query() {
ApplicationContext context =
new ClassPathXmlApplicationContext("bean1.xml");
UserService userService = context.getBean("userService", UserService.class);
int count = userService.findCount();
System.out.println("表记录数"+count);
}
UserDaoImpl.java
@Override
public User findUserInfo(String id) {
// 1创建sql语句
String sql = "select * from t_user where userid=?";
User user = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class),id);
return user;
}
// 查询
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。