// === @ModelAttribute ===
@ReuestMapping(value=...)
public String m(
@ModelAttribute(ATTRIBUTE_MODEL) MyObject myObject) {
// 若 MyObject 前有宣告 @ModelAttribute(ATTRIBUTE_MODEL)
// 會受 prepare() 中對 MyObject o 操作的影響
// 若沒有宣告 則仍單純是 form bean
}
@ModelAttribute(ATTRIBUTE_MODEL)
public Object prepare() {
// 進入 m() 前會先經過這裡
MyObject o = new MyObject();
return o;
}
// === URL Mapping ===
@RequestMapping(value = URL_MAPPING, method = RequestMethod.POST)
public String m(
@RequestParam(value = ATTRIBUTE_ID, required = true) BigDecimal id) {
// 除了 RequestMapping 中的 value 要 mapping 到以外
// 若 RequestParam 中 required = true,request 中也必須帶有此 attribute
}
// === Mapping enum object to DB ===
// DB 內儲存的是 NAME1
// @Enumerated 便會儲存 MyObject 所對應的 name
@Enumerated (EnumType.STRING)
public MyObject getMyObject() {}
enum MyObject {
NAME1("value1");
}
// DB 內儲存的是 DB_VALUE
// 從 DB 取出後 可藉 valueOfCode 取得相對應 MyObject
enum MyObject {
NAME1("DB_VALUE");
private static volatile Map<String, MyObject> registry = new HashMap<String, MyObject>();
// Use DB_VALUE be the key of Map
// put value to Map and use key to get MyObject
public static MyObject valueOfCode (String code) {
if(0 == registry.size()) {
synchronized ( registry) {
if(0 == registry.size()) {
for(MyObject o: MyObject.values()) {
registry.put(o. code, o);
}
}
}
}
return registry.get(code);
}
}
2012年7月1日 星期日
[Spring] Mapping among jsp, controller and DB
[Apache] Directory setting
httpd.conf
Alias /virtualUrl /RealUrlAllowOverride None Options None Order allow,deny Allow from all
訂閱:
意見 (Atom)