让beetlsql支持xml格式

原创
2023/03/30 10:52
阅读数 1.6K

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>


展开阅读全文
加载中
点击加入讨论🔥(2) 发布并加入讨论🔥
2 评论
0 收藏
1
分享
返回顶部
顶部