This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def asJavaClass(x: Any): Class[_] = x match { | |
case x: scala.Boolean => java.lang.Boolean.TYPE | |
case x: scala.Char => java.lang.Character.TYPE | |
case x: scala.Byte => java.lang.Byte.TYPE | |
case x: scala.Short => java.lang.Short.TYPE | |
case x: scala.Int => java.lang.Integer.TYPE | |
case x: scala.Long => java.lang.Long.TYPE | |
case x: scala.Float => java.lang.Float.TYPE | |
case x: scala.Double => java.lang.Double.TYPE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def newInstanceWithTypes[T: ClassTag](initArgs: Any*)(initArgsTypes: Class[_]*): T = { | |
if (initArgs == null || initArgs.length == 0) | |
return newInstance[T]() | |
val parameterTypes = | |
if (initArgsTypes != null) initArgsTypes.toArray | |
else initArgs.map(asJavaClass(_)).toArray | |
val constructor = classTag[T].runtimeClass.getConstructor(parameterTypes: _*) | |
constructor.newInstance(initArgs.map(_.asInstanceOf[AnyRef]): _*).asInstanceOf[T] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass(var id: Int, var name: String) { | |
def this() { | |
this(0, "Unknown") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
def instancingByDefaultContructor() { | |
val instance = ScalaReflects.newInstance[MyClass]() | |
Assert.assertNotNull(instance) | |
Assert.assertTrue(instance.isInstanceOf[MyClass]) | |
} | |
@Test | |
def instancingByParameterizedContructor() { | |
val instance = ScalaReflects.newInstance[MyClass](100, "Dynamic") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 동적으로 객체의 속성, 메소드에 접근할 수 있는 접근자입니다. | |
* User: [email protected] | |
* Date: 13. 1. 21 | |
*/ | |
@Slf4j | |
public class DynamicAccessor<T> { | |
private final Class<T> targetType; | |
private final ConstructorAccess<T> ctorAccessor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* {@link DynamicAccessor} 의 생성자입니다. | |
* User: [email protected] | |
* Date: 13. 1. 21 | |
*/ | |
@Slf4j | |
public class DynamicAccessorFactory { | |
private static final CacheLoader<Class<?>, DynamicAccessor> loader; | |
private static final LoadingCache<Class<?>, DynamicAccessor> cache; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
public class DynamicAccessorTest { | |
@lombok.Getter | |
@lombok.Setter | |
static class User { | |
private String email; | |
private Double age; | |
public User() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mapAsOrdered[T <: Ordered[T], V](items: Iterable[T], mapper: T => V): Iterable[V] = { | |
items.par | |
.map(item => (item, mapper(item))) | |
.toList.sortWith(_._1 < _._1) | |
.map(_._2) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kr.nsoft.data.hibernate.springmvc; | |
import kr.nsoft.data.hibernate.unitofwork.IUnitOfWork; | |
import kr.nsoft.data.hibernate.unitofwork.UnitOfWorks; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.web.servlet.HandlerInterceptor; | |
import org.springframework.web.servlet.ModelAndView; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<context:annotation-config/> | |
<context:component-scan base-package="kr.nsoft.contact"/> | |
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | |
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> | |
<property name="prefix" value="/WEB-INF/view/"/> | |
<property name="suffix" value=".jsp"/> | |
<property name="contentType" value="text/html;charset=UTF-8"/> | |
</bean> |