의식주 해결된 사람들의 싸구려 감성소비를 위한 도구
아프리카 사람들은 순수하다는 말도 안되는 감성주의. 그냥 사람일 뿐이다. 당신도 나도 아프리카 사람도
관심을 주고 싶다면 책이라도 한권 자료라도 한번 찾아보자
2012년 9월 9일 일요일
2012년 8월 11일 토요일
SpringMVC Tip
서블릿 매칭을 제외한 스프링프레임웍으로부터 현재 매핑된 주소 동적으로 가져오기
Case1. 단순매칭시
@RequestMapping(value=[이부분], method={RequestMethod.GET,RequestMethod.POST})public ModelAndView index(HttpServletRequest request, HttpServletResponse reponse){
String mappingValue = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
System.out.println("Mapping Value = " + mappingValue);
return new ModelAndView("index");
}
Case2. url 변수 사용시
@RequestMapping(value=index. + "{val}", method={RequestMethod.GET,RequestMethod.POST})public ModelAndView index(HttpServletRequest request, HttpServletResponse reponse,
@PathVariable("val") final String val){
String mappingValue = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
Map<?, ?> mapping = (Map<?, ?>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
Iterator<?> iter = mapping.keySet().iterator();
while(iter.hasNext()){
String key = (String) iter.next();
Object value = mapping.get(key);
if(mappingValue.contains("{"+key+"}")){
mappingValue = mappingValue.replaceAll("\\{"+key+"\\}", value == null ? "" : value.toString());
}
}
System.out.println("Mapping Value = " + mappingValue);
return new ModelAndView("index");
}
참고
2012년 7월 9일 월요일
[JAVA] My .properties file loader
import java.io.IOException;
import java.net.URL;
import java.util.Calendar;
import java.util.Properties;
import java.util.TimeZone;
/**
*
* @author pig
*
*/
public class Loader {
public static String getPropertieValue(String key) {
String value=Loader.getInstance().getPropertie(key);
if(value == null){
System.out.println("not find ["+key+"] from init.properties file");
System.out.println("set "+key+" : null");
}else{
System.out.println("set "+key+" : " + value);
}
return value;
}
public static TimeZone getDefaultTimeZone() {
String timeZoneStr = Loader.getInstance().getPropertie("default.time.zone");
TimeZone timezone;
if(timeZoneStr == null){
timezone = Calendar.getInstance().getTimeZone();
System.out.println("not find [default.time.zone] from init.properties file");
System.out.println("set default timezone(take value from system) : " + timezone.getDisplayName());
}else{
timezone = TimeZone.getTimeZone(timeZoneStr);
System.out.println("set default timezone : " + timezone.getDisplayName());
}
return timezone;
}
private static final Loader loader = new Loader();
public static Loader getInstance() {
return loader;
}
private Properties properties = new Properties();
private Loader() {
try {
//System.out.println(this.getClass().getResource("/"));
URL url = new URL("file:" + this.getClass().getResource("").getFile().split("classes")[0] + "classes/init.properties");
System.out.println("--Load : init.properties-------------------------------------------------------------------");
System.out.println("--necessery properties file : init.properties");
System.out.println("--properties file location : " + url.getPath());
System.out.println("--develop by oneofworld.com");
//System.out.println("--v0.1");
properties.load(url.openStream());
System.out.println("--Load properties SUCCESS");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("--Load properties FAIL : " + e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("--Load properties FAIL : " + e.getMessage());
}
System.out.println("-------------------------------------------------------------------------------------------");
}
public Properties getProperties() {
return properties;
}
public String getPropertie(String key) {
return properties.getProperty(key);
}
}
피드 구독하기:
글 (Atom)