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)