NutzCN Logo
精华 nutz有类似MyBatis的SQL模板吗?
发布于 3139天前 作者 wendal 3629 次浏览 复制 上一个帖子 下一个帖子
标签:

RT

13 回复

个人更喜欢这种:

QQ图片20150916112125.png

不喜欢<% %>这种,感觉象JSP

当前提供了beetl, freemarker, velocity 实现, 其他模板引擎也很容易实现出来

选你喜欢的模板引擎就好了

jetbrick-template实现的SqlTpl也加上了

支持宏调用吗?比如freemarker的macro,场景是公用的where条件。

@jellee 先试后问

来自炫酷的 NutzCN

<#marco where params>
<#if params?? && params?size gt 0>
where 1 = 1
<#if type??>
and o.type = ${type}
</#if>
<#if state??>
and o.state != ${state}
</#if>
</#if>
</#marco>
/* Table.query /
select
o.

from table o
<@where params=params />

不用宏是可以执行,用了宏就不行了。

@jellee 全局宏,得通过freemarker的配置文件单独引入吧

来自炫酷的 NutzCN

有没有类似ibatis的的引用效果?因为查询条件共用的情况挺多。

@jellee 你可以试试提交个增强版,发个pull req

来自炫酷的 NutzCN

@wendal Sqls.setSqlBorning(BeetlSqlTpl.class);
编译报错

Error:(22, 13) java: 无法将类 org.nutz.dao.Sqls中的方法 setSqlBorning应用到给定类型;
  需要: java.lang.Class<T>
  找到: java.lang.Class<org.nutz.plugins.sqltpl.impl.beetl.BeetlSqlTpl>
  原因: 推论变量 T 具有不兼容的限制范围
    等式约束条件: org.nutz.plugins.sqltpl.impl.beetl.BeetlSqlTpl
    上限: org.nutz.dao.sql.Sql

要最新快照版 1.r.62-SNAPSHOT

添加回复
请先登陆
回到顶部