Spring Roo中SELECT的自定义标签

编程入门 行业动态 更新时间:2024-10-23 23:31:24
本文介绍了Spring Roo中SELECT的自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我从Spring Roo开始.在我的项目中,我必须拥有一对多关系的实体.在我的控制器中,当我编辑一个实体时,我得到一个HTML SELECT来选择另一个实体.我想在此SELECT中添加一个自定义标签.

I am starting with Spring Roo. In my project, I have to entities with a one-to-many relation. In my controller, when I edit one entity, I get an HTML SELECT to choose one of the other entity. I'd like to have a custom label in this SELECT.

我试图在ApplicationConversionServiceFactoryBean中注册一个Converter:

I tried to register a Converter in my ApplicationConversionServiceFactoryBean :

public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean { @Override protected void installFormatters(FormatterRegistry registry) { super.installFormatters(registry); // Register application converters and formatters registry.addConverter(getApplicationConverter()); } public Converter<Application, String> getApplicationConverter() { return new Converter<Application, String>() { @Override public String convert(Application source) { return "toto" + source.getName(); } }; } }

这似乎不起作用,SELECT仍然充满着类似于Application.toString()的结果.

This doesnt seem to work, the SELECT is still filled with what looks like the result of Application.toString().

我想念什么?

推荐答案

我确实找到了解决方案.我仍然不知道这是不是对的...

I did find a solution. I still dont know if it is the right one ...

public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean { static class ApplicationConverter implements Converter<Application, String> { @Override public String convert(Application source) { return "toto" + source.getName(); } } @Override protected void installFormatters(FormatterRegistry registry) { super.installFormatters(registry); // Register application converters and formatters registry.addConverter(new ApplicationConverter()); } }

这似乎适用于SELECT中的标签.是推荐的方法吗?

This seems to work for the labels in a SELECT. Is it the recommended way ?

更多推荐

Spring Roo中SELECT的自定义标签

本文发布于:2023-10-23 22:52:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522241.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   标签   Spring   Roo   SELECT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!