Struts must have already used it. . . ^ _ ^ Inadvertently read a bit of JPETStore, some usage is worth discussing. . JPETSTORE is a completely use OpenSource Demo, using Struts Ibatis 嘿嘿, did you have a J2EE version of PetStore Demo? ^ _ ^
JPETSTORE design makes me only one action in front of me, be careful not an actionServlet, of course, Struts is of course only 1 pre-controller.
Key code if (form! = NULL) {
// Explicit Method Mapping Method method = null; String methodName = mapping.getParameter ();. If (!!. MethodName = null && "*" equals (methodName)) {try {method = form.getClass () getMethod (methodName , NULL); Forward = (string) method.invoke (form, null);} catch (exception e) {throw new beanactionException ("Error Dispatching Bean Action Via Method Parameter). Cause:" E, E);}}
// path based method mapping if (Method == Null &&! "*". Equals (methodname)) {methodname = mapping.getPath (); if (MethodName.Length ()> 1) {int Slash = methodname.lastIndexof "/") 1; methodname = methodname.substring (Slash); if (MethodName.Length ()> 0) {Try {method = form.getClass (). GetMethod (MethodName, null); forward = (string) Method .invoke (form, null);} catch (exception e) {throw new beanactionException ("Error Dispatching Bean Action Via Url Pattern ('" MethodName "). Cause:" E, E);}} The key code of this beanaction, of course, this beanaction is inherited, and the normal action is nothing 2. This is also all the requests called by all the request .... Cool ....
At this point, let's talk about the Actionform design in JPETSTORE, in the JPETStore Form named XXXBean, 1 looks very strange .. Take a closer look, each specific xxxbean has inherited a basebean, and this BaseBean inherited The Actionform, and this xxxbean references the Domain domain object (corresponding to the database field), and adds a method of calling DAO, such as INSERT, UPDATE. The method is no, because the parameters used can be obtained from the BEAN's own field, which is also the key part of the part ^ _ ^ to see a Struts-config.xml configuration
Wonderful place is that this path of this path is a method name in Catalogbean. At this time, you can look back at this beanaction. He uses the principle of reflection, and it is called via Form (which is actually 1 BO) and URL. Methods.
Written 1 paragraph, ^ _ ^, how important it feels flexible to use the framework, do not stick to some fixed usage ....
Demo's homepage, interested friends can go see http://www.ibatis.com/jpetstore/jpetstore.html