[英]Use custom typehandler on resulttype in myBatis
In our project we use mybatis and have a custom type handler on strings that strip html and other things from the result by default. 在我们的项目中,我们使用mybatis并在字符串上有一个自定义类型处理程序,默认情况下会从结果中剥离html和其他内容。 We can override this by setting a different typehandler in the resultmap.
我们可以通过在结果映射表中设置其他类型处理程序来覆盖它。
However I now have a situation where dynamic querys are used in a select so something like this 但是我现在有一种情况,其中在选择中使用了动态查询,所以像这样
<select id="executeQuery" resultType="String">
${sql}
</select>
Now I dont want the result to be stripped of its html, so I want to use a custom typehandler. 现在,我不希望将结果剥离其html,因此我想使用自定义类型处理程序。 Normally I would do this in a result map, but the problem is I dont know the name of the column that will be used in the query.
通常,我会在结果图中执行此操作,但是问题是我不知道将在查询中使用的列的名称。 Is there a solution for this problem where I can use another typehandler on this result?
有没有针对这个问题的解决方案,可以在此结果上使用另一个类型处理程序?
For others running into this problem. 对于其他遇到此问题的人。 In the end I used the following workaround:
最后,我使用了以下解决方法:
SELECT (${sql}) AS value
This has some limitation in what kind of queries can be used in the sql statement though. 但是,在sql语句中可以使用哪种查询方面存在一些限制。 For example in ms sql a query with an order by without a top, offset or for xml cannot be used.
例如,在ms sql中,不能使用顺序为无顶,偏移或xml的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.