My favorites | Sign in
Project Logo
                
Code license: Apache License 2.0
Labels: java, j2ee, beanutils, mvc
Feeds:
People details
Project owners:
  cokemi.zh

A very lightweight and useful utility for J2EE MVC coding;

There are some useful classes in the utility.

1, A TemplateDAO based on Commons.dbutils or Spring JdbcTemplate;

sample code:

DataSource ds = new TestDataSource();
QueryRunnerAdapter queryRunner = new QueryRunnerAdapter(ds);
JdbcTemplateAdapter jdbcTemplate = new JdbcTemplateAdapter(ds);
TemplateDAO dao = new TemplateDAO(queryRunner);
// for JdbcTemplate, like this:
// dao = new TemplateDAO(jdbcTemplate); / dao.setJdbcAdapter(jdbcTemplate);
SampleBean bean = (SampleBean)dao.queryForBean(SampleBean.class,"id=1");
List<SampleBean> list = dao.queryForBeanList(SampleBean.class);
// do update for bean 
// dao.updateForBean() / dao.insertForBean() / dao.deleteForBean() 	

Of course, you can implement another JdbcAdapter for the TemplateDAO.

2, Fill the value of properties of the POJO bean;

sample code:

SampleBean dest = new SampleBean()
Object src = ....;
ModelValueUtils.setValues(dest, src);
  1. Actually, this class is an extension from the commons.beanutils;
  2. The type of the source object can be Map / ResultSet / HttpServletRequest / String(in "key=value" format), or an another JavaBean;
  3. You can also set alias name for every property of the dest bean. Therefore, the value of properties in the source object can be flexibly bound into the dest bean;

3, Generate the common sql from the POJO bean;

sample code:

SampleBean dest = new SampleBean()
Object src = ....;
ModelValueUtils.setValues(dest, src);
String sql = ModelToSQLUtils.generateInsertSql(dest);
// .....other sql generating;

However, it's just for the simple sql generating. And, you should set some DB signatures for the bean by using Annotation, such as tableName/keyFieldName/...etc

4, A mini TemplateAction and ActionDispatcher;

Struts is pretty good, but i just don't like the XML config, so...

5, More?To be continued...

能写给国际友人的就先这么多,还是感觉英文得补补才行. 如果你对这个小工具包感兴趣,不妨到我的博客看看,有几篇专门的日志来介绍她的特性









Hosted by Google Code