Я занимаюсь разработкой веб-приложения на основе весенней загрузки.Я использую тимелист для добавления содержимого на мою веб-страницу.Вот мой класс контроллера:
@GetMapping("/search")
public String searchPage(@RequestParam("q") String queryString) throws IOException, SolrServerException {
ModelMap model = new ModelMap();
SearchPageResult searchPageResult = tweelyzeConfig.getSearchResults(queryString);
System.out.println("Here are they==============================================");
System.out.println(searchPageResult.getCity());
System.out.println(searchPageResult.getHashtags());
System.out.println(searchPageResult.getLang());
System.out.println(searchPageResult.getText());
System.out.println(searchPageResult.getTopic());
System.out.println(searchPageResult.getTweet_urls());
model.addAttribute("searchresult",searchPageResult);
return "searchresult";
}
Здесь я принимаю запрос от пользовательского интерфейса для поиска в моем solr.Я использую Solrj, чтобы сделать остальные вызовы Solr, чтобы получить соответствующие результаты для этого запроса.Мой класс TweelyzeConfig:
private SolrQuery setSolrQuery(String query) {
solrQuery.setQuery(query);
return solrQuery;
}
public SearchPageResult getSearchResults(String query) throws IOException, SolrServerException {
QueryResponse queryResponse = solrClient.query(setSolrQuery(query));
List<SearchPageResult> sdList = queryResponse.getBeans(SearchPageResult.class);
return sdList.get(0);
}
Мой класс SearchResultPage:
public class SearchPageResult {
private List<String> city;
private List<String> topic;
private List<String> lang;
private List<String> text;
private List<String> tweet_urls;
private List<String> hashtags;
public SearchPageResult(){}
@Field("city")
public void setCity(List<String> city) {
this.city = city;
}
@Field("topic")
public void setTopic(List<String> topic) {
this.topic = topic;
}
@Field("lang")
public void setLang(List<String> lang) {
this.lang = lang;
}
@Field("text")
public void setText(List<String> text) {
this.text = text;
}
@Field("tweet_urls")
public void setTweet_urls(List<String> tweet_urls) {
this.tweet_urls = tweet_urls;
}
@Field("hashtags")
public void setHashtags(List<String> hashtags) {
this.hashtags = hashtags;
}
public List<String> getCity() {
return city;
}
public List<String> getTopic() {
return topic;
}
public List<String> getLang() {
return lang;
}
public List<String> getText() {
return text;
}
public List<String> getTweet_urls() {
return tweet_urls;
}
public List<String> getHashtags() {
return hashtags;
}
}
И вот как я пытаюсь встроить содержимое в html:
<p th:text="${searchresult.text[0]}">hhhhhhhhh</p>
Но яполучаю эту ошибку:
Исключительная ситуация при вычислении выражения SpringEL: "searchresult.text [0]" (шаблон: "searchresult" - строка 90, столбец 23)
IЯ не могу понять, что я делаю не так.Любая помощь приветствуется.
ОБНОВЛЕНИЕ: Вот трассировка стека для лучшей справки.
2018-12-01 11:57:08.390 ERROR 38681 --- [nio-8080-exec-5] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-5] Exception processing template "searchresult": Exception evaluating SpringEL expression: "searchPageResult.text[0]" (template: "searchresult" - line 90, col 23)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "searchPageResult.text[0]" (template: "searchresult" - line 90, col 23)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor.doProcess(AbstractStandardExpressionAttributeTagProcessor.java:144) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:661) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) [thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) [thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
<snip>
... 105 common frames omitted
2018-12-01 11:57:08.394 ERROR 38681 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "searchPageResult.text[0]" (template: "searchresult" - line 90, col 23)] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'text' cannot be found on null
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:59) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:89) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:111) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:328) ~[spring-expression-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor.doProcess(AbstractStandardExpressionAttributeTagProcessor.java:144) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
<snip>