github地址:https://github.com/SpringStudent/GyJdbc
使用效果
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserDao userDao;
@Override
public void create(String name, Integer age)throws Exception {
userDao.insertWithSql(new SQL().insertInto(User.class,User::getName,User::getAge).values(name,age));
}
@Override
public void deleteByName(String name) throws Exception{
userDao.deleteWithCriteria(new Criteria().where(User::getName,name));
}
@Override
public Integer getAllUsers() throws Exception{
return userDao.queryIntegerWithSql(new SQL().select(count("*")).from(User.class));
}
@Override
public void deleteAllUsers() throws Exception{
userDao.deleteWithCriteria(new Criteria());
}
@Override
public List<User> getUserList() throws Exception {
return userDao.queryAll();
}
}