Excelbatis-an ORM framework that reads an Excel file into a list of entities, resolves an entity list into an Excel file, and is simple, easy to configure and extensible.

Source: Internet
Author: User

Welcome to Excelbatis!github Address: Advantages of Https://github.com/log4leo/ExcelbatisExcelbatis
    • Natural combination with spring for easy access
    • XSD support, which makes the configuration more concise and does not need to be configured according to the bean verbose syntax
    • Follow the "convention greater than configuration" principle and automatically infer the field type (the functionality provided by the ORM Framework) if not configured
    • By implementing Convertor and transfer interfaces, you can customize the conversion of Excel data to your field type, such as by defining a mapconvertor to convert the data in an Excel file into a field of type map. (See Convertor section for details)
    • Reading from Excel to an object, reading into an Excel file from the list of objects, can be reused by using the field scope to distinguish whether a field is for reading or writing.
Principle
    1. Read and write Excel files using Apache poi to read and write Excel files, poi dependency is Org.apache.poi poi 3.9
    2. Field mapping write, read out you need to configure the corresponding table header name, field names for each column so that the framework reads the Excel file according to this configuration to find the corresponding field, and through Java reflection to find the corresponding get and set method, so this place needs your entity class to follow the JavaBean specification. At the same time you need to configure the Readentitytype and Writeentitytype properties, the framework based on this to determine what object to build and write, Writeentitytype is optional, if not configured, the default is the same as Readentitytype, which is also "Convention is greater than configuration" is a situation, because many times we read and write the same type.
    3. Data content and type conversion when reading into Excel cells, we read in the text type, need to be replaced by corresponding field data (such as int, long, map, etc.), Here we provide the Exceldatatransfer and exceldataconvertor two interfaces to allow you to customize this process by implementing the Dotransfer method of the Exceldatatransfer interface, You can first convert the contents of the cell to the correct content, for example, in a cell you fill in a code code, you need to call the name of a remote query. By implementing Exceldataconvertor's Doconvert method, you can convert string type strings to field types, such as long, which are divided into transfer and convertor to improve the reusability of these two modules. Of course, it would be cumbersome to specify transfer and convertor for each type, so here are two features:
    4. Configure Builtinconvertor to specify some common convertor
    5. Automatic inference based on field type convertor ease of use also provides some extensibility.
Configuration uses

The following is a simple example configuration

<?Xmlversion="1.0"encoding="UTF-8"?><Beansxmlns="Http://www.springframework.org/schema/beans"xmlns:Xsi="Http://www.w3.org/2001/XMLSchema-instance"xmlns:excelbatis="Http://www.taobao.com/excelbatis/orm"XSi:schemalocation="Http://www.springframework.org/schema/beansHttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdHttp://www.taobao.com/excelbatis/orm http://www.taobao.com/excelbatis/orm.xsd"Default-autowire="ByName"> <Excelbatis:ProcessorId="Processor"Readentitytype="Com.excel.orm.demo.PersonInfo"> <Excelbatis:Columnattrs> <Excelbatis:ColumnattrColumnname="Name"Columnfield="Name"/> <Excelbatis:ColumnattrColumnname= "Age" columnfield=  "Age"/> <excelbatis:< Span class= "pl-ent" >columnattr columnname= birthday< Span class= "Pl-pds" > "columnfield=" Birthday "builtinconvertor=" Dateconvertor "/> </excelbatis: columnattrs> </excelbatis:processor> </BEANS>            

Here are a few steps:

    • Configure the Excelbatis namespace and the location of the XSD
       xmlns:excelbatis= "Http://www.taobao.com/excelbatis/orm"       http://www.taobao.com/excelbatis/orm/http Www.taobao.com/excelbatis/orm.xsd
    • Define a processor, which requires a configuration ID, which is also the ID of the bean you rely on elsewhere
    • Define Readentitytype and Writeentitytype, which are required, the latter is optional, and the default is the same as Readentitytype
<excelbatis:id="Processorreadentitytype=" Com.excel.orm.demo.PersonInfo"> 
    • Configure each column:

      • Column name ColumnName, same as Excel file table header
      • column field Columnfield, field of the corresponding entity
      • Transfer, as an extension point, if you customize transfer words, The Com.excel.orm.transfer.ExcelDataTransfer interface needs to be implemented, and the framework will call this transfer Dotransfer method to transform the contents of the data after parsing the contents of the Excel cell.
      • Convertor, as an extension point, if you customize Convertor words, The Com.excel.orm.convertor.ExcelDataConvertor interface needs to be implemented, and the framework will call Convertor's Doconvert method to transform the type of data into a field and then call the set method to inject data into the entity after transfer executes.
      • Builtinconvertor, the default Convertor implementation within the framework, is currently only available in the following categories:
        • Intconvertor
        • Longconvertor
        • Mapconvertor
        • Listconvertor
        • DateConvertor
        • Boolconvertor
    • Rely on the processor bean you defined earlier and then call the Com.excel.orm.processor.excelbatisprocessor#parse method to parse the Excel file into the entity list, Call the Com.excel.orm.processor.excelbatisprocessor#write method to write the list of entities to an Excel file

Excelbatis-an ORM framework that reads an Excel file into a list of entities, resolves an entity list into an Excel file, and is simple, easy to configure and extensible.

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.