전체 글

ᗦ↞◃
온라인 강좌/유튜브 강의

Spring Boot 14. Mybatis 세팅하고 데이터 조회하기

pom.xml 추가 org.mybatis.spring.boot mybatis-spring-boot-starter 2.3.2 application.properties 필요한 것만 추가 mybatis.type-aliases-package=com.javalab.myhome.model mybatis.configuration.map-underscore-to-camel-case=true mybatis.mapper-locations=classpath:mapper/**/*.xml camel case 추가 시 user_age로 검색해도 userAge로 검색 mapper 경로 지정 mybatis 사용을 위해 mapper 패키지 추가 UserMapper @Mapper public interface UserMapper { L..

온라인 강좌/유튜브 강의

Spring Boot 13. JPA를 이용한 커스텀 쿼리 만들기

방법 1. @Query UserApiController @GetMapping("/users") List all(@RequestParam(required = false) String method, @RequestParam(required = false) String text){ List users = null; if("query".equals(method)) { users = repository.findByUsernameQuery(text); }else{ users = repository.findAll(); } return users; } UserRepository public interface UserRepository extends JpaRepository { @EntityGraph(attributeP..

온라인 강좌/유튜브 강의

Spring Boot 12. 권한에 맞는 화면 구성 및 API 호출

삭제 삭제 버튼을 사용자 권한에 따라 구성 (관리자만 삭제 버튼이 보이도록 함) js로 구성, 실제 삭제를 위해 API 호출 BoardApiController @DeleteMapping("/boards/{id}") void deleteBoard(@PathVariable Long id) { repository.deleteById(id); } form.html 버튼만 가리면 postman에서 delete요청을 보냈을 때 삭제가 되기 때문에 보안에 취약하므로 서버단에서 설정을 해줘야 한다. MethodSecurityConfig @Configuration @EnableMethodSecurity( prePostEnabled = true, securedEnabled = true, jsr250Enabled = tru..

온라인 강좌/유튜브 강의

Spring Boot 11. JPA로 조회방법(FetchType) 설정하기

FetchType - Eager : boards 클래스를 같이 가져온다. - OneToOne, ManyToOne - Lazy :필요할 때 가져온다. - OneToMany, ManyToMany User.java @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) private List boards = new ArrayList();

온라인 강좌/유튜브 강의

Spring Boot 10. JPA를 이용하여 @OneToMany 관계 설정하기

Board.java @Entity @Data public class Board { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Valid @Size(min=2, max=30, message = "제목은 2자이상 30자 이하입니다.") private String title; private String content; @ManyToOne @JoinColumn(name = "user_id") @JsonIgnore private User user; } 게시글 입장에서 User와 다대일 관계이기 때문에 @ManyToOne 어노테이션 설정 join할 컬럼명은 Board테이블의 user_id @JsonIgnore를 통해 직렬화할 ..

범박사
범박사의 코딩 노트