spring
Spring 4 and Tiles 3 programmatic or annotation based configuration + mapping wildcard
Spring4 & tiles3 setting
출처 : http://springbybhimu.blogspot.kr/2015/01/spring-4-and-tiles-3-programmatic.html
public final class TilesDefinitionsConfig implements DefinitionsFactory {
private static Map tilesDefinitions = new HashMap();
private static Attribute BASE_TEMPLATE = new Attribute("/WEB-INF/views/layout/defaultLayout.jsp");
private WildcardHelper wildcardHelper = new WildcardHelper();
@Override
public Definition getDefinition(String name, Request tilesContext) {
Definition retVal = null;
if(!tilesDefinitions.containsKey(name)){
for(Map.Entry item : tilesDefinitions.entrySet()) {
int[] pattern = wildcardHelper.compilePattern(item.getKey());
List list = wildcardHelper.match(name, pattern);
if(list != null){
retVal = new Definition(item.getValue());
Map vars = new HashMap<>();
for(String layout : list){
vars.put(vars.size(), layout);
}
String contentAttr = (String) retVal.getAttribute("content").getValue();
String content = WildcardHelper.convertParam(contentAttr, vars);
retVal.setName(name);
retVal.putAttribute("content", new Attribute(content));
tilesDefinitions.put(name, retVal);
break;
}
}
}
return tilesDefinitions.get(name);
}
/**
* @param name
* Name of the view
* @param title
* Page title
* @param body
* Body JSP file path
*
* Adds default layout definitions
*/
private static void addDefaultLayoutDef(String name, String title, String content) {
Map attributes = new HashMap();
attributes.put("title", new Attribute(title));
attributes.put("header", new Attribute("/WEB-INF/views/layout/header.jsp"));
attributes.put("content", new Attribute(content));
attributes.put("footer", new Attribute("/WEB-INF/views/layout/footer.jsp"));
tilesDefinitions.put(name, new Definition(name, BASE_TEMPLATE, attributes));
}
/**
* Add Apache tiles definitions
*/
public static void addDefinitions() {
addDefaultLayoutDef("dddd/*", "Home", "/WEB-INF/views/{1}.jsp");
}
}
출처 : http://springbybhimu.blogspot.kr/2015/01/spring-4-and-tiles-3-programmatic.html
댓글 쓰기
0 댓글