求助,ibatis动态表及参数传入

狼图腾-狼之传说 2013-11-02 11:47:45
网上看到这么一个帖子http://blog.csdn.net/a9529lty/article/details/6000726
内容如下:
Java code :
// just a releation to the table stored in db
public class Test {
public String name;
public Timestamp date;
public int id;
}
public class TestInsert {
// logger class you can replace it to System.out.println
static Log logger = LogFactory.getLog(TestInsert.class);

public static void main(String[] args) {
/*
* Test test = new Test(); test.date = new
* Timestamp(System.currentTimeMillis()); test.name = "fffff"; try {
* long num = (Long) EntityManager.getSqlMapper().insertArgs(
* "insertOperation", "fffff", new
* Timestamp(System.currentTimeMillis())); logger.info("ID is " + num);
* } catch (SQLException e) { e.printStackTrace(); }
*/
// try the dynamic table dealation
HashMap<String, Object> map = new HashMap<String, Object>();
// set the query value
map.put("ID", "dizhuang");
// set the col1 to be selected
map.put("col1", "*");
// set the table name
map.put("tablePrefix", "testsocevent");
// set the col name which you use
map.put("col2", "NAME");
// map.put("ID", 1000);
// map.put("id", "1005");
try {
// why args is error?
Test test = (Test) EntityManager.getSqlMapper().queryForObject(
"getTest", map);
logger.info("id : " + test.id);
logger.info("time :" + test.date);
logger.info("name : " + test.name);
} catch (SQLException e) {
logger.error(e.getMessage(), e);
// e.printStackTrace();
}
}

// ibatis sql
<select id="getTest" parameterClass="java.util.HashMap"
  resultClass="com.neusoft.soc.eventcenter.test.Test"
  remapResults="true">
  SELECT
  $col1$
  FROM
  $tablePrefix$
  WHERE
$col2$ = #ID#
</select>

如果我的map里面value是一个对象,如:
public class User{
private int id;
private String name;
}
那么Ibatis的sql怎么写呢?
如果是value是List<User> users;
那么Ibatis的sql怎么写呢?
谢谢!
...全文
242 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Defonds 2013-11-05
  • 打赏
  • 举报
回复
放到 map 里往里传

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧