In eclipse, how does one insert pojo into the crystal report? This is what we need to do in the fourth article.
First, we should create an object class.
Here I use orderitems. Java as an example, code
Package com. jrc. beans;
Public class orderitems ...{
Public int ID; // the ID of the corresponding database table
Public int quantity; // number of products, which are not available in database tables
Public orderitems (int id, int quantity )...{
Super ();
This. ID = ID;
This. Quantity = quantity;
}
/***//**
* @ Return ID
*/
Public int GETID ()...{
Return ID;
}
/***//**
* @ Param ID: ID to be set
*/
Public void setid (int id )...{
This. ID = ID;
}
/***//**
* @ Return quantity
*/
Public int getquantity ()...{
Return quantity;
}
/***//**
* @ Param quantity the quantity to be set
*/
Public void setquantity (INT quantity )...{
This. Quantity = quantity;
}
}
If you have not created a report, create a report, such as report. Rpt, and open the report.
In the project resource manager, click orderitems. + (the image cannot be sent) in front of Java. You can see "Green Point orderitems". Right-click "Crystal Reports-" and add it to the current crystal report. Alternatively, you can directly pull "Green Point orderitems" to the report.
In this way, orderitems will be added to the report data and a database table will be added to the report data, such as products (product_id, product_name, product_price ,....,)
If there is no problem, report. the data in the RPT report contains the orderitems table and the products table, and left-click the ID of the orderitems table to pull it to the products_id of the Products table. You can find that there is a line between them.
In this way, orderitems. ID is associated with products. products_id. The default Line property in the middle is equal to or you can change it to another one.
Right-click report. rpt-Crystal Reports-create viewer JSP-select viewer API code insert-select use pojo to fill the report and connect to the Crystal Report page viewer-OK
A new Report-viewer.jsp page is coming out. However, it is useless now. You need to change a bit of stuff in it.
Note: The jrchelpersample class is used in the Report-viewer.jsp. This is a very good tool class in the CR project created in (1). Copy it to your project if it's okay, this class is used in many places. This class is included in the package com. businessobjects. samples.
String reportname = ""; // enter your report name
List dataset = new arraylist ();
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
You can use the orderitems constructor to add a dataset. You can use many methods to add a dataset. You only need to add an exact and effective orderitems object.
Remove /**/
Start Tomcat and run the Report-viewer.jsp.