Ireport is a very easy to use free report production tool. It is small and easy to use, and there is no shortage of scales. The data is transmitted to the report using CustomDataSource is one aspect of its scalability. Implement CustomDataSource needs to implement interface JRDataSource. Here are two ways -Public boolean next () throws jrexception and public object getfieldValue (JRFIELD FIELD) THROWS JREXCEPTION needs to be implemented. Of course, since Datasource, you will have a place to have a pair of data. Here I use a list, an object in List encapsulates a record. Ireport uses next () to traverse this list, gain all data. GetfieldValue is used to take the corresponding value from the list. String FieldName = Field.getName (); ArchperInfoform API = New ArchperInfoform (); API = (ArchperInfoform) Data.Get (INDEX);
IF ("A01" .Equals (fieldname)) {value = api.getaac001 ();} else ife ("a02" .Equals (fieldname)) {value = api.getaac002 ();} else if ("A03". Equals (fieldname)) {value = api.getaac003 ();} return value; here a field can determine what fields in the FORM can be determined by judging FieldName. But this is not very scientific, and we have many reports need to be treated, and the DataSource here is not a reuse. Considering it, I decided to abstract an interface. That is ReportDataInterface, defining a method getfieldbyname (String FieldName). This way, I will handle the objects taken in the list to this interface, only to operate this interface. You don't have to rewrite this DataSource in other places, just define an object, implement the ReportDataInterface interface, then put these objects with data to the List to pass this Datasource, everything is OK. Yes, I seem to have forgotten it, "A01" in the above code is the name of the column I defined in the report.