Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 百里香叶+;Spring将单独的输入存储到一个数组中_Javascript_Html_Textarea_Separator_Thymeleaf - Fatal编程技术网

Javascript 百里香叶+;Spring将单独的输入存储到一个数组中

Javascript 百里香叶+;Spring将单独的输入存储到一个数组中,javascript,html,textarea,separator,thymeleaf,Javascript,Html,Textarea,Separator,Thymeleaf,弹簧型号: @Service public class Test { private List<String> keyphrases; } @服务 公开课考试{ 私有列表关键词; } Thymeleaf html: <form role="form" action="#" method="post" th:object="${test} th:action="@{/test}"> <div class="form-group">

弹簧型号:

@Service
public class Test {
    private List<String> keyphrases;
}
@服务
公开课考试{
私有列表关键词;
}
Thymeleaf html:

<form role="form" action="#" method="post" th:object="${test} th:action="@{/test}">
    <div class="form-group">
        <label for="words" class="control-label">Keyphrases</label>
        <textarea type="text" class="form-control" id="keyphrases" placeholder="Zoektermen" th:field="*{keyphrases}"/>
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-primary pull-right" name="add">
            Go
        </button>
    </div>
</form>
我有一个解决方案:

创建一个实现转换器的新类

然后添加此方法

 List<String> result = new ArrayList<String>();
    for (String part : source.split("[\n\t:;,]")) {            
        if (!part.trim().isEmpty()) {
            result.add(part.trim());
        }
    }
    return result;
List result=new ArrayList();
对于(字符串部分:source.split([\n\t:;,]){
如果(!part.trim().isEmpty()){
结果.添加(part.trim());
}
}
返回结果;
然后将其添加到spring servlet:

<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="YOUR.PACKAGE.TextAreaSetConverter" />
        </list>
    </property> 
</bean>


要理解这个问题有点困难。。。您在填写文本区或将表单发送到服务器时有任何问题吗?没有,没有任何问题。我试图找出如何区分文本区域中输入的单词。默认情况下,只有,会被视为一个分隔符,你看。但在我的回答中,可以用显示的符号分隔每个单词