0329 ~ 0403


# 0329 ~ 0403

# 0329 - @RequestMapping

์š”์ฒญ์„ ํŠน์ • ๋ฉ”์„œ๋“œ์™€ ๋งคํ•‘ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ.

  • name : ํ•ด๋‹น ์–ด๋…ธํ…Œ์ด์…˜์—๊ฒŒ ๋ณ„์นญ์„ ๋ถ™์ด๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • value : ์ฒ˜๋ฆฌํ•  uri ํŒจํ„ด๋“ค(String ๋ฐฐ์—ด)์„ ๊ธฐ์ž…
?: matches one character
*: matches zero or more characters within a path segment
**: match zero or more path segments
  • path : value์™€ ๊ฐ™์€ ๋ชฉ์ 
  • method : ํŠน์ • http method๋งŒ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ
  • params : ํŠน์ • ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ๋งŒ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ
RequestMapping(value="hello", params="id"): /hello?id=123 ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
RequestMapping(value="hello", params="id=1234"): /hello?id=123 ์ฒ˜๋ฆฌ ๋ถˆ๊ฐ€๋Šฅ, /hello?id=1234 ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
  • headers : ํŠน์ • ํ—ค๋”๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ๋งŒ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ
  • consumes : ํŠน์ • ํƒ€์ž…์˜ ๋ฐ”๋””๋ฅผ ๊ฐ€์ง€๋Š” ์š”์ฒญ๋งŒ์„ ์ฒ˜๋ฆฌํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ
  • produces : ์‘๋‹ต์˜ ํƒ€์ž…์„ ํŠน์ • ํƒ€์ž…์œผ๋กœ ์„ค์ •ํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ

# 0330 - query dsl ์„ธํŒ… by gradle

query dsl ์„ค์ •์€ ๋Œ€ํ‘œ์ ์œผ๋กœ 2๊ฐ€์ง€์ด๋‹ค. querydsl plugin์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ annotationProcessor์„ ์ด์šฉํ•˜์—ฌ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

# querydsl plugin

ext {
    set('queryDSL', '4.3.1')
}

dependencies {
    implementation "com.querydsl:querydsl-jpa:${queryDSL}"
    
    annotationProcessor "com.querydsl:querydsl-apt:${queryDSL}:jpa"
    // ๋˜๋Š”
    annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa"

    annotationProcessor 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final'
    annotationProcessor 'javax.annotation:javax.annotation-api:1.3.2'
    ...
}

# annotationProcessor

plugins {
    ...
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

compileQuerydsl{
    options.annotationProcessorPath = configurations.querydsl
}

configurations {
    ...
    querydsl.extendsFrom compileClasspath
}

def querydslSrcDir = 'src/querydsl/generated'

querydsl {
    library = "com.querydsl:querydsl-apt"
    jpa = true
    querydslSourcesDir = querydslSrcDir
}

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', querydslSrcDir]
        }
    }
}

project.afterEvaluate {
    project.tasks.compileQuerydsl.options.compilerArgs = [
            "-proc:only",
            "-processor", project.querydsl.processors() +
                    ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
    ]
}

dependencies {
    implementation("com.querydsl:querydsl-jpa") // querydsl
    implementation("com.querydsl:querydsl-apt") // querydsl
    ...
}

# ์ฐจ์ด์ 

# complieQuerydsl ์‹œ์ 

  • querydsl plugin์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด, querydsl์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์€ gradle option์— ์žˆ๋Š” compileQuerydsl ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, build๋ฅผ ํ†ตํ•ด์„œ compile์ด ๋˜์–ด์•ผ ์ƒ์„ฑ๋œ๋‹ค.
  • ํ•ด๋‹น ๋ฐฉ์‹์„ ์ด์šฉํ•˜๊ฒŒ ๋˜๋ฉด, compileJava ์‹œ์ ์— querydsl QModel์ด ์ƒ์„ฑ์ด ๋œ๋‹ค.
  • ์ฆ‰, intellij์— Run, Debug๋ฅผ ํ†ตํ•ด์„œ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋„ ์ž๋™์œผ๋กœ ์ตœ์‹  querydsl QModel์„ ์ƒ์„ฑํ•˜๊ฒŒ ๋œ๋‹ค.

# Cache ์œ ๋ฌด

  • gradle์˜ cache๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” org.gradle.caching=true ์„ค์ •์„ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
  • querydsl plugin์„ ์ด์šฉํ•ด์„œ๋„ cache๊ฐ€ ๊ฐ€๋Šฅํ•œ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ annotationProcessor ๋ฐฉ์‹์„ ์ด์šฉํ•˜๋ฉด Cache๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ๊ทธ ์ด์œ ๋Š” compileJava ๋ถ€๋ถ„์— QModel์„ ์ƒ์„ฑํ•˜๊ธฐ์— ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด gradle์—์„œ ์ฆ๋ถ„ ์ปดํŒŒ์ผ ์˜ต์…”์— ์˜ํ•ด์„œ cache key๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

# ๋งˆ์น˜๋ฉฐ

  • cache๋ฅผ ํƒ€๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ™์€ ๋ถ€๋ถ„์— ๋ณ€๊ฒฝ์ด ์—†์–ด์•ผ์ง€๋งŒ cache๋ฅผ ์ด์šฉํ•˜๊ธฐ์— ๋ฌด์กฐ๊ฑด ์ข‹์•„์ง€๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค.
  • ๋˜ํ•œ, build์‹œ์— gradle cache key๋ฅผ ๋งค๋ฒˆ ๋ณ€๊ฒฝ์‹œํ‚ค๋Š” ๋กœ์ง์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๋ฉด, cache๋ฅผ ์ด์šฉํ•˜์ง€ ๋ชป ํ•œ๋‹ค.(ex: download files, springboot-buildInfo etc)
  • querydsl plugin์€ ๋” ์ด์ƒ ๊ฐœ๋ฐœ์ด ๋˜๊ณ  ์žˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๊ณ , gradle์—์„œ deprecated๋œ compile์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด ์ถ”ํ›„ gradle version์„ ์˜ฌ๋ฆด๋•Œ ์ œ์•ฝ์‚ฌํ•ญ์ด ๋ ๊บผ ๊ฐ™์•„ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด ์ข‹์•„๋ณด์ธ๋‹ค.
Last update: September 13, 2022 21:44
Contributors: ahnjs