UsersService层添加

This commit is contained in:
myh 2023-10-25 18:14:59 +08:00
parent 632c7b96e6
commit 8180141994
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.example.springdemo.service;
import com.example.springdemo.entities.Users;
import java.util.List;
import java.util.Optional;
public interface UsersService {
Users insetUsers(Users user);
void deleteUsersById(Long id);
Users updateUsers(Users user);
List<Users> findAllUsers();
Optional<Users> findById(Long id);
Users findByName(String name);
}

View File

@ -0,0 +1,45 @@
package com.example.springdemo.service;
import com.example.springdemo.dao.UsersRepository;
import com.example.springdemo.entities.Users;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class UsersServiceImpl implements UsersService {
@Resource
private UsersRepository usersRepository;
@Override
public Users insetUsers(Users user) {
return usersRepository.save(user);
}
@Override
public void deleteUsersById(Long id) {
usersRepository.deleteById(id);
}
@Override
public Users updateUsers(Users user) {
return usersRepository.save(user);
}
@Override
public List<Users> findAllUsers() {
return usersRepository.findAll();
}
@Override
public Optional<Users> findById(Long id) {
return usersRepository.findById(id);
}
@Override
public Users findByName(String name) {
return usersRepository.findByName(name);
}
}