文件名修正
This commit is contained in:
@ -7,19 +7,19 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import co.jp.app.entity.ErrorEntity;
|
||||
import co.jp.app.entity.UserEntity;
|
||||
import co.jp.app.service.erraService;
|
||||
import co.jp.app.service.userService;
|
||||
import co.jp.app.service.ErraService;
|
||||
import co.jp.app.service.UserService;
|
||||
|
||||
|
||||
@CrossOrigin("http://192.168.1.50:5173")
|
||||
@RestController("/api/login")
|
||||
public class loginController {
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private userService userService;
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private erraService erraService;
|
||||
private ErraService erraService;
|
||||
|
||||
@GetMapping("/status")
|
||||
public String getStatusByNameOrEmail() {
|
@ -9,14 +9,14 @@ import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import co.jp.app.entity.PetEntity;
|
||||
import co.jp.app.service.uploadService;
|
||||
import co.jp.app.service.UploadService;
|
||||
|
||||
@CrossOrigin("http://192.168.1.50:5173")
|
||||
@Controller
|
||||
public class uploadController {
|
||||
public class UploadController {
|
||||
|
||||
@Autowired
|
||||
private uploadService service;
|
||||
private UploadService service;
|
||||
|
||||
@PostMapping("/api/dogs/upload")
|
||||
public String upload() {
|
@ -31,6 +31,4 @@ public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import jakarta.persistence.Table;
|
||||
public class PetEntity{
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@Id
|
||||
private int ID;
|
||||
@Id
|
||||
private int ID;
|
||||
//犬の名前
|
||||
private String name;
|
||||
//犬の種類
|
||||
|
@ -11,6 +11,7 @@ public class UserEntity {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Id
|
||||
private int ID;
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
@ -7,7 +7,7 @@ import org.springframework.data.repository.query.Param;
|
||||
import co.jp.app.entity.ErrorEntity;
|
||||
|
||||
|
||||
public interface erraRepository extends JpaRepository<ErrorEntity, Integer>{
|
||||
public interface ErraRepository extends JpaRepository<ErrorEntity, Integer>{
|
||||
|
||||
public default ErrorEntity getById(@Param("id") int id) {
|
||||
return getById(id);
|
@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import co.jp.app.entity.PetEntity;
|
||||
|
||||
public interface uploadRepository extends JpaRepository<PetEntity, Integer>{
|
||||
public interface UploadRepository extends JpaRepository<PetEntity, Integer>{
|
||||
|
||||
@Override
|
||||
default <S extends PetEntity> List<S> saveAll(Iterable<S> entities) {
|
16
src/main/java/co/jp/app/repository/UserRepository.java
Normal file
16
src/main/java/co/jp/app/repository/UserRepository.java
Normal file
@ -0,0 +1,16 @@
|
||||
package co.jp.app.repository;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import co.jp.app.entity.UserEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<UserEntity, Integer> {
|
||||
|
||||
UserEntity getUserByEmail(@Param("email") String email);
|
||||
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package co.jp.app.repository;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import co.jp.app.entity.UserEntity;
|
||||
|
||||
public interface userRepository extends JpaRepository<UserEntity, String> {
|
||||
|
||||
public default UserEntity getByName(@Param("name") String name) {
|
||||
return getByName(name);
|
||||
}
|
||||
|
||||
public default UserEntity getByEmail(@Param("email")String email) {
|
||||
return getByEmail(email);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import co.jp.app.repository.erraRepository;
|
||||
|
||||
|
||||
@Service
|
||||
public class erraService {
|
||||
public class ErraService {
|
||||
|
||||
@Autowired
|
||||
erraRepository erraDao;
|
@ -6,13 +6,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import co.jp.app.entity.PetEntity;
|
||||
import co.jp.app.repository.uploadRepository;
|
||||
import co.jp.app.repository.UploadRepository;
|
||||
|
||||
@Service
|
||||
public class uploadService {
|
||||
public class UploadService {
|
||||
|
||||
@Autowired
|
||||
private uploadRepository uploadDao;
|
||||
private UploadRepository uploadDao;
|
||||
|
||||
public List<PetEntity> saveAll(Iterable<PetEntity> entities) {
|
||||
|
51
src/main/java/co/jp/app/service/UserService.java
Normal file
51
src/main/java/co/jp/app/service/UserService.java
Normal file
@ -0,0 +1,51 @@
|
||||
package co.jp.app.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import co.jp.app.entity.UserEntity;
|
||||
import co.jp.app.repository.UserRepository;
|
||||
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userEntityRepository;
|
||||
// private final PasswordEncoder passwordEncoder; // 注入密码编码器
|
||||
|
||||
@Autowired
|
||||
public UserService(UserRepository userEntityRepository /*, PasswordEncoder passwordEncoder */) {
|
||||
this.userEntityRepository = userEntityRepository;
|
||||
// this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@Transactional // 整个注册过程应该是一个事务
|
||||
public UserEntity registerNewUser(String name, String email, String rawPassword) throws Exception {
|
||||
// 1. 检查邮箱是否已被注册
|
||||
if (userEntityRepository.existsByEmail(email)) {
|
||||
throw new Exception("错误:该邮箱地址已被注册!"); // 或者自定义异常
|
||||
}
|
||||
|
||||
// (可选) 检查用户名是否已被注册 (如果您有用户名字段)
|
||||
// if (userEntityRepository.existsByUsername(username)) {
|
||||
// throw new Exception("错误:该用户名已被注册!");
|
||||
// }
|
||||
|
||||
// 2. 创建新的 UserEntity 对象
|
||||
UserEntity newUser = new UserEntity();
|
||||
newUser.setName(name);
|
||||
newUser.setEmail(email);
|
||||
|
||||
// 3. 对密码进行哈希加密 (非常重要!)
|
||||
// String hashedPassword = passwordEncoder.encode(rawPassword);
|
||||
// newUser.setPassword(hashedPassword);
|
||||
newUser.setPassword(rawPassword); // 实际项目中必须加密!这里为了简化先直接赋值
|
||||
|
||||
// 4. 设置其他默认属性,例如账户状态、角色等 (如果需要)
|
||||
// newUser.setActive(true);
|
||||
// newUser.setRoles(...);
|
||||
|
||||
// 5. 保存新用户到数据库
|
||||
return userEntityRepository.save(newUser);
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package co.jp.app.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import co.jp.app.entity.UserEntity;
|
||||
import co.jp.app.repository.userRepository;
|
||||
|
||||
|
||||
@Service
|
||||
public class userService {
|
||||
|
||||
@Autowired
|
||||
userRepository userdao;
|
||||
|
||||
public UserEntity getNameByEntity(String name) {
|
||||
return userdao.getByName(name);
|
||||
|
||||
}
|
||||
|
||||
public UserEntity getEmailByEntity(String email) {
|
||||
return userdao.getByEmail(email);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user