下面就正式来讲一下开发步骤:
首先,在Tomcat5.X下建一个jdbc/edainfo的数据源,数据库可以是oracle、sql server、mysql。表的结构如下:
CREATE TABLE example (
id varchar(13) NOT NULL ,
name varchar(50) NULL ,
address varchar(50) NULL
) ON [PRIMARY]
其中,id为主键。
datasource.xml内容如下:
<?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前面已经介绍过,这里就不详细介绍了。
将以上两个文件都放置到WEB-INF目录下。
在web.xml中,建立一个net.edainfo.filter.SetCharacterEncodingFilter的过滤器。
建立一个ExampleModel.java,如下所示:
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);
}
public String getId() throws ModelException {
return getString("id");
}
public void setName(String name) throws ModelException {
set("name" ,name);
}
public String getName() throws ModelException {
return getString("name");
}
public void setAddress(String address) throws ModelException {
set("address" ,address);
}
public String getAddress() throws ModelException {
return getString("address");
}
}
建立一个异常类ExampleException.java:
package net.edainfo.example;
import net.edainfo.exception.BaseException;
public class ExampleException extends BaseException {
static public String createFailed = "exception.createFailed";
static public String retrieveFailed = "exception.retrieveFailed";
static public String updateFailed = "exception.updateFailed";
static public String deleteFailed = "exception.deleteFailed";
static public String[] exampleArgs = {"edainfo.example"};
}
再建立一个action,ExampleAction.java:
package net.edainfo.example;
import java.util.ArrayList;
import java.util.Map;
import javax.servl
首先,在Tomcat5.X下建一个jdbc/edainfo的数据源,数据库可以是oracle、sql server、mysql。表的结构如下:
CREATE TABLE example (
id varchar(13) NOT NULL ,
name varchar(50) NULL ,
address varchar(50) NULL
) ON [PRIMARY]
其中,id为主键。
datasource.xml内容如下:
<?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前面已经介绍过,这里就不详细介绍了。
将以上两个文件都放置到WEB-INF目录下。
在web.xml中,建立一个net.edainfo.filter.SetCharacterEncodingFilter的过滤器。
建立一个ExampleModel.java,如下所示:
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);
}
public String getId() throws ModelException {
return getString("id");
}
public void setName(String name) throws ModelException {
set("name" ,name);
}
public String getName() throws ModelException {
return getString("name");
}
public void setAddress(String address) throws ModelException {
set("address" ,address);
}
public String getAddress() throws ModelException {
return getString("address");
}
}
建立一个异常类ExampleException.java:
package net.edainfo.example;
import net.edainfo.exception.BaseException;
public class ExampleException extends BaseException {
static public String createFailed = "exception.createFailed";
static public String retrieveFailed = "exception.retrieveFailed";
static public String updateFailed = "exception.updateFailed";
static public String deleteFailed = "exception.deleteFailed";
static public String[] exampleArgs = {"edainfo.example"};
}
再建立一个action,ExampleAction.java:
package net.edainfo.example;
import java.util.ArrayList;
import java.util.Map;
import javax.servl
| 对此文章发表了评论 |
