Recently the company has been doing projects, the main use of springmvc,eseayui,hibernate several large framework. Over the past one months, individuals have shared their knowledge of the present self.
Many companies use MyBatis products, combined with their greatest advantage is the full SQL operation, flexible and convenient.
The individual considers the Hibernate framework to be more prominent in its advantages. One is because it acts as a pure ORM product, and after the use of annotations or a configuration file is mapped to a data table, the operating entity is the equivalent of manipulating the data table. For ordinary business, most of them are based on adding and deleting operations, the more complex may be the query operation. Entity mapping is too complex to trigger the effect of a move, and business logic must do so. Well, SQL is the best choice.
The Org.hibernate.Query interface is available in Hibernate. The Sesson returned by the Org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession () method creates a
The Org.hibernate.Session.createSQLQuery (String arg0) throws Hibernateexception method, which operates a database table entirely in SQL mode, and throws away the mapping of the entity bean. The complete code is as follows:
Find ID
publicthrows Exception { = ' Select pk_id from decoration_type_info where title =:title '; This . GetSession (). createsqlquery (SQL); Query.setstring ("title", title); = (String) Query.uniqueresult (); return pkId; }
//Update Method Public voidUpdatetypebyid (Decorationtypeinfo typeinfo)throwsexception{String SQL= "Update Decoration_type_info set title =:title,remark =:remark,update_by =:updateby," + "update_date = t O_timestamp (To_char (sysdate, ' yyyy-mm-dd hh24:mi:ss '), ' Yyyy-mm-dd hh24:mi:ss:ff ') "+" where pk_id =:p Kid "; Query Query= This. GetSession (). createsqlquery (SQL); Query.setstring ("Title", Typeinfo.gettitle ()); Query.setstring ("Remark", Typeinfo.getremark ()); Query.setstring ("Updateby", Typeinfo.getupdateby ()); Query.setstring ("PkId", Typeinfo.getpkid ()); Query.executeupdate (); }
// Delete Method Public void Deltypebyid (String pkId)throws Exception { = "Delete from Unit_decoration_type_ Info where fk_decoration_type_id=? " ; This . GetSession (). createsqlquery (SQL); Query.setparameter (0, pkId); Query.executeupdate (); }
//New Method Public voidAddType (Decorationtypeinfo typeinfo,string Themeid)throwsexception{if(Stringutils.isblank (Typeinfo.getpkid ())) {String ID=Generatepkid.getpkid (); Typeinfo.setpkid (ID); } String SQL= "INSERT INTO Decoration_type_info (pk_id,title,price,remark,fk_theme_id,create_by,create_date,update_by,update_ DATE) "+" VALUES (?,?,?,?,?,?, to_timestamp (To_char (sysdate, ' yyyy-mm-dd hh24:mi:ss '), ' Yyyy-mm-dd Hh24:mi: Ss:ff '), "+"?, NULL) "; Query Query= This. GetSession (). createsqlquery (SQL); Query.setparameter (0, Typeinfo.getpkid ()); Query.setparameter (1, Typeinfo.gettitle ()); Query.setparameter (2, Typeinfo.getprice ()); Query.setparameter (3, Typeinfo.getremark ()); Query.setparameter (4, Themeid); Query.setparameter (5, Typeinfo.getcreateby ()); Query.setparameter (6, Typeinfo.getupdateby ()); Query.executeupdate (); }
// all imported Hibernate packages Import org.apache.commons.lang.StringUtils; Import Org.hibernate.Query; Import org.hibernate.transform.Transformers; import org.springframework.stereotype.Repository;
Note: The above is only as a personal learning point of view, does not involve any commercial or legal.
Let's talk about Springmvc.
The individual is currently understood as:
The @controller () and @requestmapping ("/xx/xx") annotations in the Controller act as a unique flag for the action request and do not allow duplicates to occur in a project.
The @service ("xxx1") annotation in the service serves as a globally unique service identity.
The @repository ("xx1") annotation in the Xxximpl class in DAO is the unique identifier for a global DAO.
injecting a reference DAO at the service layer requires @Autowired and @qualifier ("xx1"), which makes it easier to find the referenced DAO more accurately.
Controller Reference Service also uses @Autowired and @Qualifier ("xxx1") as a condition for the lookup.
Its advantages are summarized as follows: AOP programming can be arbitrary in any one of the classes to reference the resources of other packages, as long as the addition of @autowired automatic assembly annotations and @Qualifier ("") filter annotations can be achieved once written, used everywhere purpose.
In this way, we just write a common approach to business processing, so it can be called anywhere in the project. To a large extent, the workload and the amount of code redundancy are reduced.
//Controller Segment Code@Controller () @RequestMapping ("/xx/xxx") Public classTypecontroller {@Autowired @Qualifier ("Typeservice") PrivateTypeservice Typeservice; Private StaticLog log = Logfactory.getlog (Typecontroller.class); @RequestMapping ("/list") PublicModelandview bookcycleinfolist (httpservletrequest request, httpservletresponse response) {Modeland View View=NewModelandview (); Try{view.setviewname ("/bookcycleinfo/bookcycleinfo_list"); } Catch(Exception e) {log.error ("Typecontroller.list:" +e.getmessage ()); } returnview; }}
//Service Code@Service ("Typeservice") Public classTypeservice {@Autowired @Qualifier ("Typedao") PrivateTypedao type; PublicList<treelist> Queryroomtree (String Estateid)throwsexception{Try { returnBookcycleinfodao.queryroomtree (Estateid); } Catch(Exception e) {Throwe; } }
//There are only interface definitions in DAO, this code does not demonstrate@Repository ("Typedao") Public classTypedaoimpl {@Override PublicList findtypelist ()throwsexception{Try { //Code Body return NULL; } Catch(Exception e) {Throwe; } }}
Note: As a beginner, this shared knowledge is for reference only and cannot guarantee full accuracy.
Let's talk about the Easyui framework. First, the Easyui framework is entirely JS-based, and the individual thinks it is a complex of jquery and Ajax.
It contains a lot of interface controls and JS code control. Common controls are datagrid,treegrid,dialog,menu,textbox,numberbox,datetimebox and so on, Ajax is very simple, as shown in the following code
<script type= "Text/javascript" >$ (function () {var IDs= "${editid}"; $.ajax ({type:"POST", Async:false, URL:"${pagecontext.request.contextpath}/xx/xxx/findtypebyid.action", data: {pkid:ids}, DataType:"JSON", success:function (obj) {$ ("#pkId"). TextBox (' SetValue ', obj[0]. PKID); $("#title"). TextBox (' SetValue ', obj[0]. TITLE); $("#content"). TextBox (' SetValue ', obj[0]. CONTENT); } }); });</script>
More Easyui knowledge, please crossing network http://www.jeasyui.com/and Chinese network http://www.jeasyui.net/.
Personal feelings:
Although individuals have more than a year of development experience, but do the project and write very little code. One months into the new company fast, although tired, but learned a lot of useful things to use.
So very happy, after work to share their own results, is not only the test of self, but also for the young step difficult stage scholar's help.
Big Share-hibernate,springmvc,easyui Brief introduction