Skip to content

Commit b28526c

Browse files
committed
feat: 관리자 관리 검색 조건 조회, 하이버네이트 의존성 추가
쿼리스트링으로 전달된 검색 조건, 키워드를 기반으로 관리자 데이터를 조회함 하이버네이트 버그로 같은 URL 두번 요청 실패 발생, 하이버네이트 버전 변경 spring-projects/spring-data-jpa#2472
1 parent 9735ed1 commit b28526c

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ dependencies {
2424
compileOnly 'org.projectlombok:lombok'
2525
annotationProcessor 'org.projectlombok:lombok'
2626
testImplementation 'org.springframework.boot:spring-boot-starter-test'
27+
implementation 'org.hibernate:hibernate-core:5.6.5.Final'
28+
2729

2830
implementation('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')
2931
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

src/main/java/com/epkorea/backoffice/controller/UserController.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import com.epkorea.backoffice.dto.UserLoginDto;
55
import com.epkorea.backoffice.service.UserService;
66
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.lang.Nullable;
78
import org.springframework.stereotype.Controller;
8-
import org.springframework.web.bind.annotation.GetMapping;
9-
import org.springframework.web.bind.annotation.ModelAttribute;
10-
import org.springframework.web.bind.annotation.PostMapping;
11-
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.*;
1210
import org.springframework.web.servlet.ModelAndView;
1311

1412
import javax.servlet.http.HttpServletRequest;
@@ -22,10 +20,10 @@ public class UserController {
2220
private UserService userService;
2321

2422
@GetMapping("/all")
25-
public ModelAndView getAllUsers() {
26-
ModelAndView modelAndView = new ModelAndView();
27-
List<UserDto.Response> users = userService.findAllUserInfo();
23+
public ModelAndView getAllUsers(@RequestParam @Nullable String condition, @RequestParam @Nullable String kwd) {
24+
List<UserDto.Response> users = userService.findAllUserInfo(condition, kwd);
2825

26+
ModelAndView modelAndView = new ModelAndView();
2927
modelAndView.addObject("admin_list", users);
3028
modelAndView.setViewName("admin_list");
3129
return modelAndView;

src/main/java/com/epkorea/backoffice/repository/UserRepository.java

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
public interface UserRepository extends JpaRepository<User, Long> {
1111
User findByUseridAndPassword(String userid, String password);
1212
List<UserMapper> findAllBy();
13+
List<UserMapper> findAllByUseridLike(String userid);
14+
1315
}

src/main/java/com/epkorea/backoffice/service/UserService.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.stereotype.Service;
1010

11+
import java.util.ArrayList;
1112
import java.util.List;
1213
import java.util.stream.Collectors;
1314

@@ -17,9 +18,16 @@ public class UserService {
1718
@Autowired
1819
private UserRepository userRepository;
1920

20-
public List<UserDto.Response> findAllUserInfo() {
21-
List<UserMapper> userList = userRepository.findAllBy();
21+
public List<UserDto.Response> findAllUserInfo(String condition, String kwd) {
22+
List<UserMapper> userList = new ArrayList<>();
2223

24+
if (condition != null && kwd != null && !condition.isBlank() && !kwd.isBlank()) {
25+
if (condition.equals("userid")) {
26+
userList = userRepository.findAllByUseridLike(kwd);
27+
}
28+
} else {
29+
userList = userRepository.findAllBy();
30+
}
2331
return userList.stream().map(UserDto.Response::new).collect(Collectors.toList());
2432
}
2533

0 commit comments

Comments
 (0)