분류 전체보기

✔ Spring Security의 기본 id는 user 비밀번호는 콘솔에 적혀있다. ✔ localhost:8080/login은 아무설정도 안한상태에서는 springSecurity에서 가로채서 spring security login으로 연결된다. 이때 user와 콘솔에 나오는 비밀번호를 입력하지 않으면 url로 접근 할 수 없다. SecurityFilterChain을 넣게 되면 Spring security의 로그인은 더이상 나오지 않게 된다. @Configuration @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain configure(HttpSecurity http) throws Exception { http..
view로 이동시키는게 아니라 httpBody에 데이터를 담아서 보내는것 Spring's RequestBody and ResponseBody Annotations | Baeldung Learn about the Spring @RequestBody and @ResponseBody annotations. www.baeldung.com
@Bean을 등록하는 클래스에 붙여주는 어노테이션 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html Configuration (Spring Framework 5.3.23 API) Specify whether @Bean methods should get proxied in order to enforce bean lifecycle behavior, e.g. to return shared singleton bean instances even in case of direct @Bean method calls in user code. This f..
https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/config/EnableJpaRepositories.html EnableJpaRepositories (Spring Data JPA 2.7.3 API) enableDefaultTransactions public abstract boolean enableDefaultTransactions Configures whether to enable default transactions for Spring Data JPA repositories. Defaults to true. If disabled, repositories must be used b..
@Transactional @SpringBootTest @Rollback(value = false) class MemberTest { @PersistenceContext EntityManager em; @Test public void testEntity() { Team teamA = new Team("teamA"); Team teamB = new Team("teamB"); em.persist(teamA); em.persist(teamB); Member member1 = new Member("member1", 10, teamA); Member member2 = new Member("member2", 20, teamA); Member member3 = new Member("member3", 30, teamB..
public static Optional ofNullable(T value) { return value == null ? empty() : of(value); } If a value is present, returns the value, otherwise throws NoSuchElementException. Returns: the non-null value described by this Optional Throws: NoSuchElementException – if no value is present API Note: The preferred alternative to this method is orElseThrow(). Optional 설명을 보다 static 옆의 를 보고 관련 내용을 찾아봤다. ..
public Optional findById(Long id) { Member member = em.find(Member.class, id); return Optional.ofNullable(member); } Optional을 사용하여 Member를 감싸고 return으로 Optional.ofNullable(member)를 사용해준다. ofNullable: If a value is present, returns the value, otherwise throws NoSuchElementException. Member member = memberJpaRepository.findById(member1.getId()).get(); 꺼낼때는 꼭 .get()으로 꺼내는 것을 잊지말자
단건조회는 public Member find(Long id) { return em.find(Member.class, id); } 엔티티의 아이디로 찾을 수 있지만 where이나 all을 찾으려면 jpql을 사용해야한다. public List findAll() { return em.createQuery("select m from Member m", Member.class).getResultList(); }
키보드발
'분류 전체보기' 카테고리의 글 목록 (15 Page)