为了区分于服务器中现有的类,修改了User类名

This commit is contained in:
高子兴 2024-06-30 14:43:20 +08:00
parent 4f132490c6
commit 2ada18d2af
5 changed files with 36 additions and 47 deletions

View File

@ -1,6 +1,6 @@
package org.cmh.backend.authentication.controller; package org.cmh.backend.authentication.controller;
import org.cmh.backend.authentication.model.User; import org.cmh.backend.authentication.model.UserHS;
import org.cmh.backend.authentication.service.UserService; import org.cmh.backend.authentication.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -16,8 +16,8 @@ public class UserController {
private UserService userService; private UserService userService;
@GetMapping("/{username}") @GetMapping("/{username}")
public ResponseEntity<User> getUser(@PathVariable String username) { public ResponseEntity<UserHS> getUser(@PathVariable String username) {
User user = userService.getUserByUsername(username); UserHS user = userService.getUserByUsername(username);
return ResponseEntity.ok(user); return ResponseEntity.ok(user);
} }
} }

View File

@ -1,39 +0,0 @@
package org.cmh.backend.authentication.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@ -0,0 +1,28 @@
package org.cmh.backend.authentication.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
@Setter
@Getter
@Entity
public class UserHS {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
private String nickname;
private String gender;
private String phoneNumber;
private String email;
private String department;
private String role;
private LocalDateTime createdAt;
}

View File

@ -1,8 +1,8 @@
package org.cmh.backend.authentication.repository; package org.cmh.backend.authentication.repository;
import org.cmh.backend.authentication.model.User; import org.cmh.backend.authentication.model.UserHS;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Long> { public interface UserRepository extends JpaRepository<UserHS, Long> {
User findByUsername(String username); UserHS findByUsername(String username);
} }

View File

@ -1,6 +1,6 @@
package org.cmh.backend.authentication.service; package org.cmh.backend.authentication.service;
import org.cmh.backend.authentication.model.User; import org.cmh.backend.authentication.model.UserHS;
import org.cmh.backend.authentication.repository.UserRepository; import org.cmh.backend.authentication.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -10,7 +10,7 @@ public class UserService {
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
public User getUserByUsername(String username) { public UserHS getUserByUsername(String username) {
return userRepository.findByUsername(username); return userRepository.findByUsername(username);
} }
} }