The following describes the development steps:
First, create a jdbc/edainfo data source under Tomcat5.X. The databases can be oracle, SQL server, and mysql. The table structure is as follows:
Create table example (
Id varchar (13) not null,
Name varchar (50) NULL,
Address varchar (50) NULL
) ON [PRIMARY]
The id is the primary key.
The content of datasource. xml is as follows:
<? Xml version = "1.0" encoding = "gb2312"?>
<Database>
<Model name = "exampleModel">
<Tablename> example </tablename>
<Columns>
<Column type = "0" name = "id" tabColumn = "id"/>
<Column type = "0" name = "name" tabColumn = "name"/>
<Column type = "0" name = "address" tabColumn = "address"/>
<Column type = "2" name = "pageNum" tabColumn = "pageNum"/>
<Column type = "2" name = "operation" tabColumn = "operation"/>
</Columns>
<Relations>
</Relations>
<Pk tabColumn = "id"/>
<Pages>
<Page name = "fore" size = "20" viewPage = "5"/>
</Pages>
</Model>
</Database>
Init-config.xml has been introduced before, here is not detailed introduction.
Place both of the above files under the WEB-INF directory.
Create a net. edainfo. filter. SetCharacterEncodingFilter filter in web. xml.
Create ExampleModel. java as follows:
Package net. edainfo. example;
Import java. util. Map;
Import net. edainfo. db. DBModel;
Import net. edainfo. db. ModelException;
Import net. edainfo. util. format. Encode;
Import net. edainfo. util. format. StringProcessor;
Public class ExampleModel extends DBModel {
Public ExampleModel (Map dataBase) throws ModelException {
Super ("exampleModel", dataBase );
}
Public void setId (String id) throws ModelException {
Set ("id", id );
}