์์
์์๊ฐ ํ์ํ ๊ฒฝ์ฐ Expressions.constant(์์)๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์์
/**
* ์์
* Expressions ์ฌ์ฉ
*/
@Test
fun testConstant() {
//given
val fetch = query
.select(member.username, Expressions.constant("A"))
.from(member)
.fetch()
fetch.forEach { println(it) }
}
๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.

๋ฌธ์ ๋ํ๊ธฐ
๊ฒฐ๊ณผ์ ๋ฌธ์์ด์ ๋ํ๊ณ ์ถ์ ๊ฒฝ์ฐ์ ๋ค์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
concat() : ๋ฌธ์์ด ๋ค์ ์ด์ด์ ๋ํฉ๋๋ค.
prepend() : ๋ฌธ์์ด์ ๋งจ ์์ ๋ํฉ๋๋ค.
/**
* ๋ฌธ์ ๋ํ๊ธฐ
* concat
* ์์ ๋ํ ๋๋ prepend
*/
@Test
fun testConcat() {
//given
val fetch = query
.select(member.username.concat("_").concat(member.age.stringValue()).prepend("HI_"))
.from(member)
.fetch()
fetch.forEach { println(it) }
}

๋ฌธ์๊ฐ ์๋ ํ์ ๋ค์ stringValue()๋ฅผ ํตํด ๋ฌธ์๋ก ๋ณํํ ์ ์์ต๋๋ค.
Enum ํ์ ์ ์ฒ๋ฆฌํ ๋ ์ ์ฉํฉ๋๋ค.
Reference
์ค์ ! Querydsl - ์ธํ๋ฐ | ๊ฐ์
Querydsl์ ๊ธฐ์ด๋ถํฐ ์ค๋ฌด ํ์ฉ๊น์ง, ํ๋ฒ์ ํด๊ฒฐํด๋ณด์ธ์!, ๋ณต์กํ ์ฟผ๋ฆฌ, ๋์ ์ฟผ๋ฆฌ๋ ์ด์ ์๋ ! Querydsl๋ก ์๋ฐ ๋ฐฑ์๋ ๊ธฐ์ ์ ๋จ๋จํ๊ฒ. ๐ฉ ๋ณธ ๊ฐ์๋ ๋ก๋๋งต ๊ณผ์ ์ ๋๋ค. ๋ณธ ๊ฐ์๋ ์๋ฐ ๋ฐฑ์
www.inflearn.com
'๐๏ธ Spring > QueryDsl' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[QueryDLS] ๋์ ์ฟผ๋ฆฌ ์์ฑ๋ฒ (0) | 2021.12.24 |
---|---|
[QueryDSL] @QueryProjection (feat. ํ๋ก์ ์ ) (0) | 2021.12.24 |
[QueryDSL] CASE ๋ฌธ (0) | 2021.12.23 |
[QueryDSL] ์๋ธ ์ฟผ๋ฆฌ (0) | 2021.12.23 |
[QueryDSL] ์กฐ์ธ, ํ์น์กฐ์ธ (0) | 2021.12.23 |
์์
์์๊ฐ ํ์ํ ๊ฒฝ์ฐ Expressions.constant(์์)๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์์
/**
* ์์
* Expressions ์ฌ์ฉ
*/
@Test
fun testConstant() {
//given
val fetch = query
.select(member.username, Expressions.constant("A"))
.from(member)
.fetch()
fetch.forEach { println(it) }
}
๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.

๋ฌธ์ ๋ํ๊ธฐ
๊ฒฐ๊ณผ์ ๋ฌธ์์ด์ ๋ํ๊ณ ์ถ์ ๊ฒฝ์ฐ์ ๋ค์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
concat() : ๋ฌธ์์ด ๋ค์ ์ด์ด์ ๋ํฉ๋๋ค.
prepend() : ๋ฌธ์์ด์ ๋งจ ์์ ๋ํฉ๋๋ค.
/**
* ๋ฌธ์ ๋ํ๊ธฐ
* concat
* ์์ ๋ํ ๋๋ prepend
*/
@Test
fun testConcat() {
//given
val fetch = query
.select(member.username.concat("_").concat(member.age.stringValue()).prepend("HI_"))
.from(member)
.fetch()
fetch.forEach { println(it) }
}

๋ฌธ์๊ฐ ์๋ ํ์ ๋ค์ stringValue()๋ฅผ ํตํด ๋ฌธ์๋ก ๋ณํํ ์ ์์ต๋๋ค.
Enum ํ์ ์ ์ฒ๋ฆฌํ ๋ ์ ์ฉํฉ๋๋ค.
Reference
์ค์ ! Querydsl - ์ธํ๋ฐ | ๊ฐ์
Querydsl์ ๊ธฐ์ด๋ถํฐ ์ค๋ฌด ํ์ฉ๊น์ง, ํ๋ฒ์ ํด๊ฒฐํด๋ณด์ธ์!, ๋ณต์กํ ์ฟผ๋ฆฌ, ๋์ ์ฟผ๋ฆฌ๋ ์ด์ ์๋ ! Querydsl๋ก ์๋ฐ ๋ฐฑ์๋ ๊ธฐ์ ์ ๋จ๋จํ๊ฒ. ๐ฉ ๋ณธ ๊ฐ์๋ ๋ก๋๋งต ๊ณผ์ ์ ๋๋ค. ๋ณธ ๊ฐ์๋ ์๋ฐ ๋ฐฑ์
www.inflearn.com
'๐๏ธ Spring > QueryDsl' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[QueryDLS] ๋์ ์ฟผ๋ฆฌ ์์ฑ๋ฒ (0) | 2021.12.24 |
---|---|
[QueryDSL] @QueryProjection (feat. ํ๋ก์ ์ ) (0) | 2021.12.24 |
[QueryDSL] CASE ๋ฌธ (0) | 2021.12.23 |
[QueryDSL] ์๋ธ ์ฟผ๋ฆฌ (0) | 2021.12.23 |
[QueryDSL] ์กฐ์ธ, ํ์น์กฐ์ธ (0) | 2021.12.23 |