简体   繁体   English

在myBatis中的resulttype上使用自定义类型处理程序

[英]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.

相关问题 在MyBatis中使用基于resultType的隐式TypeHandler进行选择 - Use an implicit TypeHandler based on resultType for select in MyBatis Mybatis null 配置 object 里面自定义 TypeHandler - Mybatis null configuration object inside custom TypeHandler 如何在MyBatis中对INSERT语句使用TypeHandler - How to use TypeHandler for INSERT statements in MyBatis 如何在属性级别强制执行 MyBatis PSQL 自定义 TypeHandler - How to Enforce MyBatis PSQL custom TypeHandler on property level 放入<result>标记时,MyBatis自定义TypeHandler未执行 - MyBatis custom TypeHandler not executed when put in <result> tag 如何在Spring的xml中将&#39;EnumOrdinalTypeHandler&#39;与mybatis的typeHandler结合使用? - How to use 'EnumOrdinalTypeHandler' with mybatis's typeHandler in Spring's xml? Mybatis中没有类型处理程序异常 - No typehandler Exception in Mybatis 带有MyBatis TypeHandler的空对象模式 - Null Object pattern with a MyBatis TypeHandler Mybatis在使用自定义泛型typehandler并且bean属性名和表的列相同时,select会抛出ClassCastException - Mybatis when using custom generic typehandler and the bean property name and table's column are same, select will raise ClassCastException 如何为Set指定typeHandler <MyEnum> 在mybatis? - How to specify typeHandler for Set<MyEnum> in mybatis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM