Skip to content

Instantly share code, notes, and snippets.

View stella6767's full-sized avatar
๐ŸŽฏ
Focusing

Kang Min Kyu stella6767

๐ŸŽฏ
Focusing
View GitHub Profile
@stella6767
stella6767 / json object Array file reader.kt
Last active July 26, 2022 15:07
json object Array file reader
fun <T> readJsonArrayFile(filePath: String): List<Map<*, *>?>? {
val mapper = ObjectMapper()
//val readFileAsString = readFileAsString(filePath)
//println(readFileAsString)
val myObjects = mapper.readValue(File(filePath), object : TypeReference<List<Map<*, *>?>>() {})
// for (obj in myObjects) {
// println(obj)
// }
return myObjects
@stella6767
stella6767 / readDataFromCsv.kt
Last active July 27, 2022 03:26
readDataFromCsv
fun readDataFromCsv(filePath: String): List<List<String>?> {
var csvList: MutableList<List<String>?> = mutableListOf()
val csv = java.io.File(filePath)
try {
BufferedReader(FileReader(csv)).use { br ->
var line: String?
while (br.readLine().also { line = it } != null) {
//println("line $line")
val split: List<String>? = line?.split(",")
@stella6767
stella6767 / dynamicQuery.kt
Last active July 28, 2022 02:59
kotiln-jdsl ๋™์ ์ฟผ๋ฆฌ ์˜ˆ์‹œ
val fetch = queryFactory.listQuery<Song> {
select(entity(Song::class))
from(entity(Song::class))
fetch(Song::album, JoinType.LEFT)
offset(pageable.offset.toInt())
limit(pageable.pageSize)
where(
isSongSearchable(searchCondition, Song::deletedAt)
)
@stella6767
stella6767 / MockmultipartTest.kt
Created July 28, 2022 05:23
kotiln + junit5 with MockmultipartTest
@Test
@DisplayName("s3ํŒŒ์ผ ์—…๋กœ๋“œ ํ…Œ์ŠคํŠธ")
fun s3FileUploadTest(){
val imgPath = "src/main/resources/static/img"
val mockFile:MultipartFile = MockMultipartFile(
"test1",
"test1.png",
"image/png",
@stella6767
stella6767 / BeanRegistry.kt
Created July 28, 2022 05:31
Accessing spring beans in static method
@Configuration(proxyBeanMethods = false)
class BeanRegistry : ApplicationContextAware {
companion object {
private lateinit var applicationContext: ApplicationContext
// ํƒ€์ž…์œผ๋กœ ๋นˆ์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค
fun <T : Any> getBean(type: KClass<T>): T =
applicationContext.getBean(type.java)
// ์ด๋ฆ„๊ณผ ํƒ€์ž…์œผ๋กœ ๋นˆ์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค
fun <T : Any> getBean(name: String, type: KClass<T>): T =
@stella6767
stella6767 / categoryClosure.kt
Created July 29, 2022 10:47
closure table save ์ „๋žต
@Transactional
fun saveCategory(dto:CategorySaveReq, idAncestor: Long?): Category? {
val category = categoryRepository.saveCategory(dto.toEntity())
categoryRepository.saveCategoryClosure(category?.id!!, idAncestor )
return category
}
override fun saveCategoryClosure(idDescendant: Long, idAncestor: Long?) {
@stella6767
stella6767 / kcc.js
Created August 9, 2022 06:33
javascript ๋ฆฌํ„ฐ๋Ÿด ์˜ค๋ธŒ์ ํŠธ ํ™œ์šฉ
let rds = {
monUiCtl: [],
isRun: false,
ctlUIStart: function (idx, ch) {
console.log("ctlUIStart????", idx, ch);
this.monUiCtl[idx].value.changeLayout(
1,
@stella6767
stella6767 / pathParsingTest.kt
Created August 9, 2022 07:50
pathParsingTest
@Test
fun pathParsingTest() {
val path = "/v1/members"
log.info {
path.split(delimiters = arrayOf("/"," ")).filter { it.isNotEmpty() }.forEach {
println(" $it ")
}
}
@stella6767
stella6767 / ResponseBodyAdvice.kt
Created August 9, 2022 07:58
๊ณตํ†ต response body modify
@org.springframework.web.bind.annotation.RestControllerAdvice
class RestControllerAdvice<T>(
) : ResponseBodyAdvice<T>{
private val log = KotlinLogging.logger { }
override fun supports(returnType: MethodParameter, converterType: Class<out HttpMessageConverter<*>>): Boolean {
//log.info { "returnType: $returnType" }
return true
@stella6767
stella6767 / convertPojoToUrlEncodedFormData.kt
Last active August 11, 2022 01:25
convertPojoToUrlEncodedFormData
fun convertPojoToUrlEncodedFormData(obj: Any?): String {
/**
* ๊ฐ„๋‹จํ•œ ํ•จ์ˆ˜ input + output ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•˜๋ฏ€๋กœ, ObjectMapper๋ฅผ ์˜์กด์„ฑ ์ฃผ์ž…์‹œํ‚ค์ง€ ์•Š๊ฒ ๋‹ค.(์Šคํ”„๋ง๊ณผ๋Š” ๋…๋ฆฝ์ ์ธ)
* util function๋“ค์€ ์ตœ๋Œ€ํ•œ ์˜์กด์„ฑ ์—†์ด
*
*/
val map: Map<*, *>? = ObjectMapper().convertValue(obj, Map::class.java)