The method of using hibernate in JSP is thought by tile.

Source: Internet
Author: User
Tags define sql
Js
From the beginning of learning JSP has been affected by the MVC2 mode. It might be a bit more of a chance to write code before. Rarely do pages of things. So always feel the way to launch JSP pages, has been the first choice for development. Because this can realize the function, code and the separation of the page. And because the individual just work, still in theory >> practice stage. Therefore, in the project special first recommendation of the standardized design. MVC is everything. During this period of time to learn tile. The feeling that this is not entirely simple in the action of the preparation of data, and then launched a JSP development mode. It seems that tile's control function has broken the push mode. You can pull the data out of the JSP page by using the control feature. Like a userlist operation. If you don't use tile, you might read the data in the action and then encapsulate it in the Actionform by the JSP page. With tiles, you can use a tiles  control to read the required data from the database in the JSP. This can be more flexible, not everything is from the actionform. What if there is no corresponding data in the Actionform when the page is adjusted? Although the design of Actionform is recommended for coarse grained design, no matter how thick it is, it will not change all business. Maybe it's all a small project now, so pay special attention to the development efficiency. To easily and flexibly pull out the required data on the page. Instead of writing too many scripts or tiles control, you define a label that runs HQL. This can be directly in the page to run HQL, what cache ah, move, performance, SQL, and so on all to the hibernate deal with this is to maximize the play of the role of hibernate it. The label design uses the <bean:define/> in struts similar to the following: ---run a hql--- <page:hibernate id= "test" hql= "from Com.cms.model.TbaseEnumlist a "   page=" 2 "pagesize=" 4 ">   result size:  //Direct use by <page: hibernate> defined script variables    <%=test.size ()%><br>  //using STRUTS tag operations &LT;PAGE:HIBERNATE&Gt; the PageContext attribute defined.    <logic:iterate id= "element" name= "test" type= "Com.cms.model.TbaseEnumlist" >      <bean:write name= "element" property= "Enumcode"/><br>   </logic:iterate>  </page:hibernate>---Load a po--- <page:hibernate id= "test" type= "Com.cms.model.TbaseEnumlist" primary= "A" >    enumeration name:    <%=test.getenumname ()%> </page:hibernate> This makes it easy to read data from the database in the JSP page. Also be satisfied with those habits in the JSP write SQL query development habits. Although there are many bad places to do it. But for the current project, this is the best way.

There's one more thing I'm not going to use. Tags: (implement PO's crud operations directly in JSP)   <%    com.cms.budget.data.tsysschemetestdetail Detail = new        com.cms.budget.data.tsysschemetestdetail ();     Detail.setbcrate (java.math.BigDecimal.valueOf);      Pagecontext.setattribute (" Detail ", detail); %>  <page:hibernate id=" Detail "action=" save "/>  <%    Detail.setbxyzxs (java.math.BigDecimal.valueOf); %>  <page:hibernate id= "Detail" Update >    <% //If there is an error in hibernate processing.      if (hibernateerror = null)      {      out.println (" Update successful ");     }else      {        Out.println (hibernateerror);     }   %>  </page:hibernate >  <%     Pagecontext.sEtattribute ("detail", ""); %>  <page:hibernate id= "detail" action= "Delete" >    <%         out.println (hibernateerror);   %>  </page:hibernate>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.