让 beetlsql 支持 xml 格式
beetlsql 支持 md 格式,其实比 xml 更好,因为 xml 繁琐,且有很多符号需要 escape,比如 "<",“&&” 有人需要 xml 格式,那就给他弄一个,目前有点眉目了,评估如果全日制做,应该 2 天能做一个基于 BeetlSQL 高仿 mybatis 的插件
<?xml version="1.0" encoding="UTF-8" ?>
<beetlsql>
<sql id="select">
<!-- 测试sql -->
select * from sys_user where 1=1
<if test="has(user) and user.name=='a'" >
and name='3'
</if>
<include refid="commonWhere"/>
</sql>
<sql id="commonWhere">
and name='bdfdsf'
</sql>
</beetlsql>
if 标签实现需要自己写,这个很简单,Beetl 支持的很好,继承 Tag 写一个
public static class IfTag extends Tag{
public IfTag(){
}
@Override
public void render() {
boolean test = (Boolean)super.getHtmlAttribute("test");
if(test){
super.doBodyRender();
}else{
return ;
}
}
}
更新:下午又更新了一下,补上了其他类似 mybatis 的标签
<?xml version="1.0" encoding="UTF-8" ?>
<beetlsql>
<sql id="select">
<!-- 测试sql -->
select * from sys_user
<where>
<if test="has(user) and user.name=='a'">
and name='3'
</if>
<bind value="1+99" export="newValue"/>
<isNotEmpty value="'1'">
and name='5'
</isNotEmpty>
and name = #{newValue}
and name in
<foreach items="[1,2,3]" var="id,status" open="(" close=")" separator=",">
#{id+status.index}
</foreach>
<include refid="commonWhere"/>
</where>
</sql>
<sql id="commonWhere">
and name='bdfdsf'
</sql>
</beetlsql>
花了大概一周搞完