예제 도메인) https://realyun99.tistory.com:8080/mange/newpost?type=post#yj

Properties

Property Description Example
hash 주소값에 붙어있는 anchor값 반환 #yj
host URL의 도메인과 포트 반환 realyun99.tistory.com:8080
hostname URL의 도메인 반환 realyun99.tistory.com
href URL 반환 https://realyun99.tistory.com:8080
origin 프로토콜 + URL의 도메인 + 포트 https://realyun99.tistory.com:8080
pathname URL 경로 반환 /mange/newpost
port 서버포트 반환 8080
protocol 프로토콜 반환 http:
search URL에 붙은 매개변수 반환(물음표 뒤의 값) ?type=post

Methods

Method Description
assign(url) 새로운 주소 이동
reload(forceget) 현재 페이지 새로고침
replace(url) 새로운 주소 이동(세션 히스토리 없이)

예제

  • 새 페이지로 이동하기
window.location.assign("http://www.naver.com"); //or
window.location = "http://www.naver.com";

 

  • 현재 페이지 새로고침
window.location.reload(true);

 

  • replace()를 사용해 새 페이지로 이동하기
function reloadPageWithHash() {
  var initialPage = window.location.pathname;
  window.location.replace('http://www.naver.com/#' + initialPage);
}

'Web > Front' 카테고리의 다른 글

[HTML, CSS] icon삽입  (0) 2021.08.02
[HTML] 템플릿 파일 적용 규칙  (0) 2021.07.30
[HTML] HTML 템플릿 다운로드 사이트  (0) 2021.07.30
[ERROR] 500에러 관련  (0) 2021.07.30
[ERROR] static파일 적용 관련  (0) 2021.07.30

Querydsl

  • SQL, JPQL을 코드로 작성할 수 있도록 도와주는 빌더 API
  • 오픈소스
  • 장점
    • 문자가 아닌 코드로 작성
    • 컴파일 시점에 문법 오류를 발견
    • 코드 자동완성(IDE 도움)
    • 동적 쿼리

사용법

1. pom.xml에 dependency 추가

    <!-- Querydsl -->
    <dependency>
      <groupId>com.querydsl</groupId>
      <artifactId>querydsl-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>com.querydsl</groupId>
      <artifactId>querydsl-apt</artifactId>
      <scope>provided</scope>
    </dependency>
 <plugins>
 	<plugin>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-maven-plugin</artifactId>
       <configuration>
         <excludes>
           <exclude>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
           </exclude>
         </excludes>
       </configuration>
    </plugin>
    <plugin>
       <groupId>com.mysema.maven</groupId>
       <artifactId>apt-maven-plugin</artifactId>
       <version>1.1.3</version>
       <executions>
         <execution>
           <goals>
             <goal>process</goal>
           </goals>
           <configuration>
             <outputDirectory>target/generated-sources/java</outputDirectory>
             <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
           </configuration>
         </execution>
       </executions>
     </plugin>
</plugins>

 

2. maven lifecycle을 이용해 "clean → compile" 하면 target 폴더 안에 Query Type 생성됨

3. repository/custom 안에 CustomRepository 생성 (Custom____Repository)

4. repository/support 안에 custom을 구현하는 Impl.java 파일 생성 (____RepositoryImpl.java)

5. 기존의 Repository에 CustomRepository를 extends에 추가 (____Repository)

 

❗ 복잡한 쿼리문은 querydsl을 통해서 코드 작성하는 게 보기에도 구현하기에도 편할 것 같다. ❗

❗ querydsl관련 : https://querydsl.com/

 

'Web > Spring' 카테고리의 다른 글

[ERROR] Querydsl import  (0) 2021.08.02
[Util] ControllerNameInterceptor  (0) 2021.07.30
[배경] JPA  (0) 2021.07.27
[배경] Maven  (0) 2021.07.27
[배경] Template Engine  (0) 2021.07.27

Persistence(영속성)

  • 데이터를 생성한 프로그램이 종료되더라도 사라지지 않는 데이터의 특성
  • Object Persistence : 메모리 상의 데이터를 파일 시스템, 관계형 데이터베이스 혹은 객체 데이터베이스 등을 활용하여 영구적으로 저장하여 영속성 부여
  • JDBC, Spring JDBC, Persistence Framework(Hibernate, Mybatis 등)

ORM(Object Relational Mapping)

  • 객체와 관계형 데이터베이스의 데이터를 자동으로 매핑해주는 것
  • DB 데이터 ← 매핑 → Object 필드
  • Persistant API (JPA, Hibernate 등)

❗ 참고 : https://gmlwjd9405.github.io/2019/02/01/orm.html

JPA(Java Persistence API)

  • Hibernate : ORM 프레임워크, Open Source SW
  • JPA : 현재 자바 진영의 ORM 기술 표준으로, 인터페이스의 모음
    • JPA 인터페이스를 구현한 대표적인 오픈소스가 Hibernate

JPA의 동작과정

  • JPA는 애플리케이션과 JDBC 사이에서 동작

JPA 사용이유

  • SQL 중심적인 개발에서 객체 중심으로 개발
  • 생산성
  • 유지보수
  • 성능 최적화 기능

❗ 참고 : https://gmlwjd9405.github.io/2019/08/04/what-is-jpa.html

 

사용법

Dependency추가

<dependency> 
	<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId> 
</dependency> 
<dependency> 
	<groupId>com.h2database</groupId> 
	<artifactId>h2</artifactId> 
</dependency> 
<dependency> 
	<groupId>org.springframework.boot</groupId> 
	<artifactId>spring-boot-starter-test</artifactId> 
	<scope>test</scope> 
</dependency> 
<dependency> 
	<groupId>org.projectlombok</groupId> 
	<artifactId>lombok</artifactId> 
	<optional>true</optional> 
</dependency>

 

Domain 생성 → Repository 생성 → Service 생성 → Controller 생성

 

properties 설정

<!--application.yml-->
jpa:
    database-platform: kr.co.userinsight.ams.dialect.CustomMariadbDialect
    hibernate:
      ddl-auto: update
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
    open-in-view: true
<!--application-local.yml-->
  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:

 

JpaRepository

(JpaRepository에서 엄청 많은 기능을 제공)

인터페이스를 상속 받아서 사용하면 된다.(extends)

public interface ItemRepository extends JpaRepository<Item, Long> {
    // 비어있음
}

 

 

공통 인터페이스 기능

  • JpaRepository 인터페이스 : 공통 CRUD 제공
  • <엔티티, 식별자>로 설정

 

자주 쓰는 정렬 기능을 위해 Sort 삽입 가능

public interface MemberRepository extends JpaRepository<Member, Long> {
    List<Member> findByName(String username, Sort sort);
}

 

추가로 페이징을 위한 기능도 존재

public interface MemberRepository extends JpaRepository<Member, Long> {
    Page<Member> findByName(String username, Pageable pageable);
}

 

@Query 어노테이션을 사용해서 직접 JPQL을 지정 가능

public interface MemberRepository extends JpaRepository<Member, Long> {
    
    @Query("select m from Member m where m.username = ?1")
    Member findByUsername(String username, Pageable pageable);
}

 

Web 페이징과 정렬 기능

  • /members?page=0&size=20&sort=name,desc
@RequestMapping(value = "/members", method = RequestMethod.GET)
String list(Pageable pageable, Model mobel) {}

 

 

❗ JPA를 적용하면 개발자는 인터페이스만 만들면 된다. 알아서 동적으로 객체를 생성해서 주입해줌 ❗

❗ JPA의 한계가 존재한다! 따라서 Querydsl도 연동해서 같이 사용한다.. 다음엔 Querydsl을 확인해야지 ❗

'Web > Spring' 카테고리의 다른 글

[Util] ControllerNameInterceptor  (0) 2021.07.30
[배경] Querydsl  (0) 2021.07.28
[배경] Maven  (0) 2021.07.27
[배경] Template Engine  (0) 2021.07.27
[배경] Spring Security  (0) 2021.07.27

"Apache Maven은 자바용 프로젝트 관리도구로 Apache Ant의 대안으로 만들어졌다. Apache License로 배포되는 오픈소스 소프트웨어"

 

"필요한 라이브러리를 특정 문서(pom.xml)에 정의해 놓으면 네트워크를 통해 라이브러리들을 자동으로 다운받아준다"

 

장점

  • 라이브러리의 관리를 매우 용이하게 해준다
  • 프로젝트의 작성부터 컴파일, 페트스 등 프로젝트 라이프사이클에 포함되는 각 테스트를 지원해준다
  • war파일 기반의 배포용으로도 자주 사용된다

LifeCycle

 

일련의 단계(Phase)에 연계된 Goal을 실행하는 과정 = Build

미리 정의되어있는 Build들의 순서를 LifeCycle이라 한다.

보통 "clean → compile" 순으로 클릭

 

 

 

 

 

❗자세한 내용을 알고 싶으면 https://jeong-pro.tistory.com/168

'Web > Spring' 카테고리의 다른 글

[배경] Querydsl  (0) 2021.07.28
[배경] JPA  (0) 2021.07.27
[배경] Template Engine  (0) 2021.07.27
[배경] Spring Security  (0) 2021.07.27
[배경] Spring 실행 순서  (0) 2021.07.27

표현식

  • 변수 : ${...}
  • 선택 변수 : *{...}
  • 메시지 : #{...}
  • Link URL : @{...}

text operation

  • 문자열 연결 : +
  • 문자 대체 : |이렇게 묶어주세요|

boolean 연산

  • Binary : and, or
  • 부정 : !, not

조건 연산

  • if-then : (if) ? (then)
  • if-then-else : (if) ? (then) : (else)
  • Default : (value) ?: (defaultValue)

 

'Web > Front' 카테고리의 다른 글

[ERROR] 500에러 관련  (0) 2021.07.30
[ERROR] static파일 적용 관련  (0) 2021.07.30
[HTML, Javascript] jQuery  (0) 2021.07.28
[HTML] Thymeleaf  (0) 2021.07.27
[HTML] 기본 태그  (0) 2021.07.27

Template Engine(템플릿 엔진)

  • 템플릿 양식과 특정 데이터 모델에 따른 입력 자료를 합성하여 결과 문서를 출력하는 소프트웨어
  • web template engine은 웹 문서가 출력되는 템플릿 엔진
  • view code(html)와 data logic code(DB connection)를 분리해줌

[출처] https://gmlwjd9405.github.io/2018/12/21/template-engine.html

종류

Layout Template Engine vs Text Template Engine

  • Layout Template Engine : 중복되는 include 코드를 사용하지 않고도 지정된 페이지 레이아웃에 따라 페이지 타일을 조합하여 완전한 페이지로 만들어줌
  • Text Template Engine : 템플릿 양식에 적절한 특정 데이터를 넣어 결과 문서를 출력(Thymeleaf, JSP)

ServerSide Template Engine vs ClientSide Template Engine

  • ServerSide Template Engine : 서버에서 DB 혹은 API에서 가져온 데이터를 미리 정의된 Template에 넣어 html을 그려 클라이언트에 전달
  • ClientSide Template Engine : html 형태로 코드를 작성할 수 있으며, 동적으로 DOM을 그리게 해주는 역할

 

필요성

  • 많은 코드를 줄일 수 있다.
  • 재사용성이 높다
  • 유지보수에 용이하다

'Web > Spring' 카테고리의 다른 글

[배경] JPA  (0) 2021.07.27
[배경] Maven  (0) 2021.07.27
[배경] Spring Security  (0) 2021.07.27
[배경] Spring 실행 순서  (0) 2021.07.27
[배경] MVC Pattern  (0) 2021.07.27

+ Recent posts