#和$有什么区别,即select * from topic where id=#id#和select * from topic where id=$id$有区别吗?
还有我要执行这个语句select * from topic where boardid in (1,2,3),配置文件如下:
这样写会报错:
[code]
<select id= "getLists " resultMap= "topicListResult " parameterClass= "topicInfo ">
select * from topic
<dynamic prepend= "where ">
<isNotNull prepend= "and " property= "boardid ">
boardid in (#boardid#)
</isNotNull>
</dynamic>
</select>
[/code]
这样写就没事,即用$替换#
[code]
<select id= "getLists " resultMap= "topicListResult " parameterClass= "topicInfo ">
select * from topic
<dynamic prepend= "where ">
<isNotNull prepend= "and " property= "boardid ">
boardid in ($boardid$)
</isNotNull>
</dynamic>
</select>
[/code]
这是为什么?
用$$ 有点宏替换的意思,如下列映射:
<select id= "users " resultMap= "user "> select * from a $name$ </select> ,则在传入参数可以queryForList( "users ", "where name= '张三 ' ");
用##则是预编译处理,传入的是什么类型就是什么类型,如下列映射:
<select id= "users " resultMap= "user "> select * from a where a.name=#name# </select> ,
你在传入参数时可以queryForList( "users ", "张三 ");则生成的sql语句是select * from a where a.name= '张三 '。
#表示参数的方式传入类似于sql语句里的?,$就是简单的字符串替换,用相应的值替换$$里的内容。
还有我要执行这个语句select * from topic where boardid in (1,2,3),配置文件如下:
这样写会报错:
[code]
<select id= "getLists " resultMap= "topicListResult " parameterClass= "topicInfo ">
select * from topic
<dynamic prepend= "where ">
<isNotNull prepend= "and " property= "boardid ">
boardid in (#boardid#)
</isNotNull>
</dynamic>
</select>
[/code]
这样写就没事,即用$替换#
[code]
<select id= "getLists " resultMap= "topicListResult " parameterClass= "topicInfo ">
select * from topic
<dynamic prepend= "where ">
<isNotNull prepend= "and " property= "boardid ">
boardid in ($boardid$)
</isNotNull>
</dynamic>
</select>
[/code]
这是为什么?
用$$ 有点宏替换的意思,如下列映射:
<select id= "users " resultMap= "user "> select * from a $name$ </select> ,则在传入参数可以queryForList( "users ", "where name= '张三 ' ");
用##则是预编译处理,传入的是什么类型就是什么类型,如下列映射:
<select id= "users " resultMap= "user "> select * from a where a.name=#name# </select> ,
你在传入参数时可以queryForList( "users ", "张三 ");则生成的sql语句是select * from a where a.name= '张三 '。
#表示参数的方式传入类似于sql语句里的?,$就是简单的字符串替换,用相应的值替换$$里的内容。