- 以字串型態傳遞物件。
- 不能跨平台。
- 像物件的 version control id。
- 當物件屬性改變此 id 就會改變。
- 當 B side 接收到 Serialize id,會根據此 id 去 new 相對應的物件將值設定進去。
2012年8月27日 星期一
[Java] Serialize
[Spring] enum type attribute
// 如果物件中有 enum type 的屬性。
public class User {
private MyEnumType name;
......
}
<%--
JSP 中 form 欄位的 value 必須放入 MyEnumType 才能對回物件。
使用 List options
--%>
2012年8月26日 星期日
[Spring] Type not matched when String is "" and is tried to convert to date
ERROR MESSAGE
Type not matched when String is "" and is tried to convert to date
Solution
因為 form 中的 date 為 "" (空字串) 因為要轉成 Date 時會出錯。
Type not matched when String is "" and is tried to convert to date
Solution
因為 form 中的 date 為 "" (空字串) 因為要轉成 Date 時會出錯。
@InitBinder
protected void initializeBinder (WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd" );
dateFormat.setLenient(false);
CustomDateEditor dateEditor = new CustomDateEditor(dateFormat, true);
binder.registerCustomEditor(Date. class, dateEditor);
binder.registerCustomEditor(ModelEntity.class, customPropertyEditor);
}
2012年8月25日 星期六
[JPA] @ModelAttribute("xxx")
// entity: request 中的值對設定到物件中。
@RequestMapping(...)
public void methodName(@ModelAttribute("model") EntityType entity) {}
---- Update on 2013/08/25 ----
// @ModelAttribute("xxx") 會建立 EntityType 的物件,並且將此物件放入 request.
@ModelAttribute("model")
public Object prepare(...) {
Object model = new EntityType();
return model;
}
[Android] MSISDN, ICCID, IMEI, IMSI
下列值在以下情況會被改變或是取不到正確值:
Related
MSISDN, ICCID, IMEI, IMSI
- ICCID
- 換了 SIM card
- IMEI
- 山寨機
- ANDROID_ID
- 恢復原廠設定
Related
MSISDN, ICCID, IMEI, IMSI
[ORM] Date and Timestamp
DB 中時間的 type 有:
對應到 java 中的 type 皆是宣告為 Date
DB 都是收到相同的值 然後再依欄位 type 決定存入的值
例如若是 date 會被 truncate 掉 millisecond 後再存入
- Date
- Timestamp
對應到 java 中的 type 皆是宣告為 Date
DB 都是收到相同的值 然後再依欄位 type 決定存入的值
例如若是 date 會被 truncate 掉 millisecond 後再存入
[Animation] Property Animation (>= 11)
Supported from API Level 11.
Property Animation
TypeEvaluator
ValueAnimator
ObjectAnimator
AnimatorSet
* Reference
- Property Animation | Android Developers
Property Animation
- A property animation changes a property's (a field in an object) value over a specified length of time.
- 以某項 attribute 進行動畫。ex: x-axis 使物件橫向移動。
- 分為兩部份:
- 計算產生動畫的值。
- 設定動畫值於物件的 property 中。
- The view animation system
- View animation 是藉由重繪 view 來顯示動畫,而此動作是由每個 view 自己的 container 來做(because the View itself had no properties to manipulate)。
- 雖然結果可以看到 view 出現在不同位置,但實際上沒有改變到 view object 的任何 property,所以關於 view object 的設定卻還停留在原位 (ex: 點擊原始位置才會觸發 view 的事件)。
- The property animation system
- Property animation 則是改善了這個問題,因為它是改變 view object 的 property 來顯示動畫。
- 而當 view object 的 property 改變,會自動呼叫
invalidate()。
TypeEvaluator
- 決定如何去計算進行動畫的 attribute 的值。
- An interface that allows you to create your own evaluator.
- If you are animating an object property that is not an int, float, or color, you must implement the TypeEvaluator interface to specify how to compute the object property's animated values.
- You can also specify a custom TypeEvaluator for int, float, and color values as well, if you want to process those types differently than the default behavior.
ValueAnimator
- Keeps track of your animation's timing.
- How long the animation has been running.
- The current value of the property that it is animating.
- 管理 object 動畫中的 attribute 在動畫過程中的值,包含資訊:
- 是否重複動畫。
- 接收更新動作通知的 listeners。
- 使用客制化的 evaluator。
- 但 ValueAnimator 並不會將計算後的值設給 property,因此要使用 listeners 接收計算後的值再自行去更新,例如需實作
ValueAnimator.AnimatorUpdateListener。
ObjectAnimator
- A subclass of ValueAnimator.
- 可以設定發生動畫的物件以及決定動畫內容的 property。
- 此 class 會更新 property 的值,所以大部份使用此 class 比較方便,不需自行處理更新這部份動作。
AnimatorSet
- 設定動畫效果於一群 view,他們能一起變化、有序的或是延遲的。
- Provides a mechanism to group animations together so that they run in relation to one another. You can set animations to play together, sequentially, or after a specified delay.
* Reference
- Property Animation | Android Developers
2012年7月1日 星期日
[Spring] Mapping among jsp, controller and DB
// === @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);
}
}
[Apache] Directory setting
httpd.conf
Alias /virtualUrl /RealUrlAllowOverride None Options None Order allow,deny Allow from all
2012年6月30日 星期六
[Spring] Spring Expression Language (SpEL)
Assume get this value from DB #{#root["valueB"]}/path
* Reference
- Spring Expression Language (SpEL)
// Using Expression parser, valueB should be found from DB, too.
Expression expression = parser.parseExpression(property.getValue(),
new TemplateParserContext());
property.setValue(expression.getValue(context, String.class));
* Reference
- Spring Expression Language (SpEL)
2012年6月22日 星期五
[Web] Brief notes
- slf4j
- 在 jar 檔時就 binding,比較好切換。
- framework
- 提供 pattern 的模組
- Spring framework
- 本身是個大 factory,將工作交給底下的 factory...
- Struts2
- #attribute 作用約是 ${attribute}
- iBatis
- $var$
- paraClass 中的 attribute
- #fieldName:fieldType#
- Table field
- HTML
- 由上而下 compiler,結果會是 DOM tree 結構。
- DTD
- 描述 HTML syntax
- <meta>
- 提供和 browser or search engine 相關的訊息。
- ex: 描述文檔的內容。
2012年6月15日 星期五
[Android] Context
public abstract class Context
getApplicationContext()
* Reference
- 求getApplicationContext用法-Android 问题&解答-eoeAndroid开发者社区 - Powered by Discuz!
- 谈谈Android里的Context的使用!!! - Android_Tutor的专栏 - 博客频道 - CSDN.NET
- 管理 global application 資訊的 interface,是由 Android System 實作。
- Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system.
- 可由此取得 application-specific 的 resources and classes。
- It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
getApplicationContext()
- 在啟動 app 時,預設會啟動 Application,也就是 AndroidManifest.xml 中的 <application>,因此也能自己實作指定在此 tag 中,替代此預設。
- 回傳所在 process 中的 global application context。
- Return the context of the single, global Application object of the current process.
- 應被使用在當 lifecycle 不和當前 component 綁在一起時。
- This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.
- registerReceiver(BroadcastReceiver, IntentFilter)
- 如果使用的是 Activity context,這個 receiver 就是被註冊在此 Activity,所以你必須在此 Activity destroy 前 unregister 此 receiver,若沒有這樣做則會發生 exception。
- If you use the Activity context to register a receiver that is static (global to the process, not associated with an Activity instance) then that registration will be removed on you at whatever point the activity you used is destroyed.
- 如果是使用 Application context,這個 receiver 是和 application 相關連,因此不會被 unregistered,但有可能會造成 leak。
- However using the ApplicationContext elsewhere can easily lead to serious leaks if you forget to unregister, unbind, etc.
- 使用在 DB 操作時。
* Reference
- 求getApplicationContext用法-Android 问题&解答-eoeAndroid开发者社区 - Powered by Discuz!
- 谈谈Android里的Context的使用!!! - Android_Tutor的专栏 - 博客频道 - CSDN.NET
[JPA] @OneToMany
// ObjectA many-to-one with ObjectB
// In ObjectA
// mappedBy 的值是在 ObjectB 中的 attribute
@OneToMany(fetch = FetchType.LAZY, mappedBy = "objectA")
public List<ObjectB> getObjectB() {
return objectBs;
}
// In ObjectB
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumns({
@JoinColumn(name = "FIELD_X", referencedColumnName = "FIELD_X", insertable = false, updatable = false )
})
public ObjectA getObjectA() { return objectA; }
[Database] BigDecimal
當 table 對應為物件時
若其 value 長度可能會超過 java int
這時候就會使用 BigDecimal type
ex: 流水號
* Reference
- How big is BigDecimal?
若其 value 長度可能會超過 java int
這時候就會使用 BigDecimal type
ex: 流水號
* Reference
- How big is BigDecimal?
[Graphic] Gif format
GIF 的版本有分
不會動的一定是 87a 格式
或是可以使用 Ultra Edit 查看 header
可分辨是何種格式的
* Reference
- wiki GIF
- GIF 87a: 不會動的
- GIF 89a: 此版本的格式才支援動態
不會動的一定是 87a 格式
或是可以使用 Ultra Edit 查看 header
可分辨是何種格式的
* Reference
- wiki GIF
訂閱:
文章 (Atom)