| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |
// {key1:value1,key2:value2}
public static <K,V> Map<K,V> hashMapCorvertor(String str){
Map<K, V> map = (Map<K, V>) new HashMap<K,V>();
String s = str.replaceAll("\\{", "").replaceAll("\\}", "");
String[] entryes = s.split(",");
for (int i = 0; i < entryes.length; i++) {
Object[] entry = entryes[i].split(":");
map.put((K)entry[0], (V) entry[1]);
}
return map;
}
context.put("Utils", Utils.class);
String s = "{key1:value1,key2:value2}";
String s1 = "{key1:true,key2:false}";
context.put("s", s);
context.put("s1", s1);
Map<String,Boolean> map = new HashMap<String,Boolean>();
map.put("k1", true);
map.put("k2", false);
context.put("map", map);
Map<String,Integer> map1 = new HashMap<String,Integer>();
map1.put("k1", 12);
map1.put("k2", 13);
context.put("map1", map1);
Hello $name! Welcome to Velocity!
## #set($map={"key1":"1","key2":"2"})
$map.k1
#set($m = $Utils.hashMapCorvertor($s))
#set($m1 = $Utils.hashMapCorvertor($s1))
$m.key1
$m.key2
#set( $monkey = {"banana" : "good", "roast beef" : "bad"})
$monkey.banana
#set( $monkey.Number = 123 )
$monkey.Number
$m.key1
#if($m.key1)
lala - lala
#end
#if($m1.key1)
11111lala - lala
#end
$map1.k1
$m1.key1
$m1.key2
$root
Map<String,Boolean> map = new HashMap<String,Boolean>(){
@Override
public Boolean get(Object key) {
Boolean value = super.get(key);
if (value == null) {
return Boolean.TRUE;
}
return value;
}
};
map.put("k1", true);
map.put("k2", false);
System.out.println(" --> "+map.get("k3"));
System.out.println(map);
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |