Summary of using grid ++ report in hibernate + spring + mvc + Easyui framework mode, easyuigrid

Source: Internet
Author: User

Summary of using grid ++ report in hibernate + spring + mvc + Easyui framework mode, easyuigrid

Recently, I started to access the hibernate + spring + mvc + Easyui framework and started my blog. I hope I can record what I have practiced and avoid detours for others.

The assignment is due to my personal understanding. hibernate's role to developers is mainly to save the time for writing SQL statements to connect to the database. According to the internal class provided by grid ++ report, however, you still need to write SQL statements to connect to the database directly through ajax. If we feel like we use grid ++ report in this framework, we feel like a fast horse and pulling an old car. Although the speed does not affect much, it is quite uncomfortable. As a perfectionist programmer, this is not allowed. Then I tried to get rid of it. I will not talk about the hibernate + spring + mvc + Easyui framework. I will only talk about the use of grid ++ report.

  

  

1. Open the grid ++ report client, connect to the database, and draw reports.

2. Use notepad to open the. grf file and clear the database connection.

3. Add three mvc files to load the. grf file in html. The demo of grid ++ is mostly described in detail.

4. Modify the url of the loaded Data Source

ReportViewer. stop (); ReportViewer. dataURL = "user/load"; // var BeginDate = document. getElementById ("txtBeginDate "). value; // var EndDate = document. getElementById ("txtEndDate "). value; // var DataURL = encodeURI ("xmlSummary. aspx? BeginDate = "+ BeginDate +" & EndDate = "+ EndDate); // ReportViewer. dataURL = DataURL; // update query parameters update report title, set the "Text" attribute of the corresponding static box // ReportViewer. report. controlByName ("SubTitle "). asStaticBox. text = "Date range:" + BeginDate + "to" + EndDate; ReportViewer. start ();


5. Compile the load method in control to obtain the data source. Because the data source format obtained by hibernate in the framework is IList <T>, the xml format is received in grid ++. So we need to convert this to another method.

Du Niang told me this is the case

Using System; using System. collections. generic; using System. linq; using System. text; using System. xml; namespace Common. toolsHelper {public class XMLHelperToList <T> where T: new () {# convert region object class to Xml /// <summary> // convert object instance to xml /// </summary> /// <param name = "item"> object instance </param> // <returns> </returns> public static string EntityToXml (T item) {IList <T> items = new List <T> (); items. add (item); return Ent ItyToXml (items );} /// <summary> /// convert the object instance set to xml /// </summary> /// <param name = "items"> object instance set </param>/ // <returns> </returns> public static string EntityToXml (IList <T> items) {// create XmlDocument doc = new XmlDocument (); // create the root element XmlElement root = doc. createElement (typeof (T ). name + "s"); // Add the sub-element set foreach (T item in items) {EntityToXml (doc, root, item );} // Add the root element doc to the XmlDocument. app EndChild (root); return doc. innerXml;} private static void EntityToXml (XmlDocument doc, XmlElement root, T item) {// create element XmlElement xmlItem = doc. createElement (typeof (T ). name); // The property set of the Object System. reflection. propertyInfo [] propertyInfo = typeof (T ). getProperties (System. reflection. bindingFlags. public | System. reflection. bindingFlags. instance); foreach (System. reflection. propertyInfo pinfo in propertyIn Fo) {if (pinfo! = Null) {// object property name string Name = pinfo. name; // object property value string value = String. Empty; if (pinfo. GetValue (item, null )! = Null) value = pinfo. getValue (item, null ). toString (); // get the object property value // set the element's property value xmlItem. setAttribute (name, value) ;}// Add the child element root to the root. appendChild (xmlItem );} # endregion # convert region Xml to an object class // <summary> // convert Xml to an object instance /// </summary> /// <param name = "xml"> xml </param> // <returns> </returns> public static T XmlToEntity (string xml) {IList <T> items = XmlToEntityList (xml); if (items! = Null & items. count> 0) return items [0]; else return default (T );} /// <summary> // convert Xml to an object instance set // </summary> /// <param name = "xml"> xml </param> /// <returns> </returns> public static IList <T> XmlToEntityList (string xml) {XmlDocument doc = new XmlDocument (); try {doc. loadXml (xml);} catch {return null;} if (doc. childNodes. count! = 1) return null; if (doc. ChildNodes [0]. Name. ToLower ()! = Typeof (T ). name. toLower () + "s") return null; XmlNode node = doc. childNodes [0]; IList <T> items = new List <T> (); foreach (XmlNode child in node. childNodes) {if (child. name. toLower () = typeof (T ). name. toLower () items. add (XmlNodeToEntity (child);} return items;} private static T XmlNodeToEntity (XmlNode node) {T item = new T (); if (node. nodeType = XmlNodeType. element) {XmlElement element = (Xml Element) node; System. reflection. propertyInfo [] propertyInfo = typeof (T ). getProperties (System. reflection. bindingFlags. public | System. reflection. bindingFlags. instance); foreach (XmlAttribute attr in element. attributes) {string attrName = attr. name. toLower (); string attrValue = attr. value. toString (); foreach (System. reflection. propertyInfo pinfo in propertyInfo) {if (pinfo! = Null) {string name = pinfo. name. toLower (); Type dbType = pinfo. propertyType; if (name = attrName) {if (String. isNullOrEmpty (attrValue) continue; switch (dbType. toString () {case "System. int32 ": pinfo. setValue (item, Convert. toInt32 (attrValue), null); break; case "System. boolean ": pinfo. setValue (item, Convert. toBoolean (attrValue), null); break; case "System. dateTime ": pinfo. setValue (item, Convert. toDateTime (attrValue), null); break; case "System. decimal ": pinfo. setValue (item, Convert. toDecimal (attrValue), null); break; case "System. double ": pinfo. setValue (item, Convert. toDouble (attrValue), null); break; default: pinfo. setValue (item, attrValue, null); break;} continue ;}}}return item ;}# endregion }}

 

Then retrieve the data and respond to the page.

The method is as follows.

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.IO;using CLGL.Web.Controllers;using System.Text;using Wat.Common;using Domain;using System.IO.Compression;using Newtonsoft.Json;using System.Globalization;using Common.ToolsHelper;namespace CLGL.Web.Areas.GrfDemo.Controllers{    public class UserController : Controller    {        //        // GET: /GrfDemo/User/        Service.IUserManager userManage { get; set; }        //User user = new User();        public ActionResult Index()        {            return View();        }        public ActionResult Load()        {            IList<User> list = userManage.LoadAll();            string str = XMLHelperToList<User>.EntityToXml(list);            Response.Write(str);            Response.End();            return View();        }    }}

Result:

 


Easyui + Spring MVC + Hibernate for Java Web, and the front-end easyui datagrid wants to dynamically obtain the column name

It should not be, but after all, it is far from thirst. I don't know what the problem is on your side, and you have to solve it yourself. You should consider whether the driver is correct for MySql and Oracle drivers. Calm down and keep a clear mind. Let's debug it carefully to see where the problem is? Calm down.
Hope to help you!

What are the purposes of struts, hibernate, and spring frameworks? Urgent

To put it simply, struts is used to obtain the value of the page text box, and verification becomes convenient.
Hibernate, which is convenient for adding, deleting, modifying, and querying databases.
Spring makes the first two combinations better. Dependency injection, etc. Thank you for your adoption.

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.