SSM format format of export report time

Posted by palace on Thu, 26 Dec 2019 21:17:20 +0100

1, Data in the database

Time format is dateTime type

 

2, Corresponding Moddel entity class

 private Date goOutTicketTime;
 private Date returnOutTicketTime;
 private Date depositPayTime;
 private Date orderInvalidTime;

3, action of Export Report

The corresponding export field to display is a property in the Model.

If you export now:

4, Solutions

1. Create a new ext package (extension class package) under the Model

2. Create a new extension class of Model entity under this package. This extension class should inherit the original entity class.

Add the time to be formatted as the attribute of the extension class and change its name (add changed later), and set the corresponding get and set methods.

public class BusNotcompleteorderReportExt extends BusNotcompleteorderReport {
     //Bill export time format
  private String ReturnOutTicketTimeChanged;
  private String GoOutTicketTimeChanged;
  private String DepositPayTimeChanged;
  private String OrderInvalidTimeChanged;


  public String getReturnOutTicketTimeChanged() {
   if(getReturnOutTicketTime()!=null) {
    ReturnOutTicketTimeChanged=DateUtils.formatDate(getReturnOutTicketTime(), "yyyy-MM-dd HH:mm:ss");
   }
   return ReturnOutTicketTimeChanged;
  }
  public void setReturnOutTicketTimeChanged(String returnOutTicketTimeChanged) {
   ReturnOutTicketTimeChanged = returnOutTicketTimeChanged;
  }

The same is true for other omissions.

3. Modify mapper file

Find the mapper file corresponding to the query report data, and modify the added corresponding
Extended mapper file, where BaseResultMap is generated automatically using the code generation tool.

Here is the extended mapper file. The corresponding type should be modified to the extended entity Model. And inherit the automatically generated resultMap.

 <!-- Result set -->
    <resultMap id="BaseExtResultMap" type="**.model.ext.BusNotcompleteorderReportExt" extends="BaseResultMap">
  
   
  </resultMap>

      <!-- Query incomplete Report -->
  <select id="getBusNotcompleteorderReportByParam" parameterType="java.util.Map" resultMap="BaseExtResultMap">
   select
    * 
   from
   bus_notcompleteorder_report bnr
   where 1 = 1

   ......

4. Modify the return type of the corresponding action, service, serviceImpl and dao layers to the extended entity Model.

5. In the action of exporting report, modify the attribute of Excel to be exported as the attribute of extension class, which should be the same for the name.

Other attributes are omitted.

fieldNames.add(new String[] {

             "GoOutTicketTimeChanged",


             "ReturnOutTicketTimeChanged",

             "DepositPayTimeChanged",

             "OrderInvalidTimeChanged"
             
            
     });

 

6. The corresponding export is

Please leave a message if you have any questions.

Topics: Attribute Database Java Excel