Thymelaf错误:模板分析过程中发生错误



我在url映射上遇到了一个问题,所以不要太关注方法中的代码。这是我的控制器:

@Autowired
ChannelService channelService;
@Autowired
RuleService ruleService;
@GetMapping("/config/{channelCode}/view/{ruleCode}")
public String viewTable(@PathVariable String channelCode, @PathVariable String ruleCode, Authentication  authentication, ModelMap model) {
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
ChannelDto channelDto = channelService.findByClientIdAndChannelCode(userPrincipal.getUser().getClient().getId(), channelCode);
List<RuleStoreDto> storeDtos = ruleService.findAllCustomRuleStoreByClientIdAndChannelCode(userPrincipal.getUser().getClient().getId(), channelCode);
model.addAttribute("channel", channelDto);
model.addAttribute("stores", storeDtos);
return "configuration/sales_channel_view";
}
@GetMapping("/config/{channelCode}/create")
public String createForm(@PathVariable String channelCode, Authentication authentication, ModelMap model) {     
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
ChannelDto channelDto = channelService.findByClientIdAndChannelCode(userPrincipal.getUser().getClient().getId(), channelCode);
model.addAttribute("channel", channelDto);
return "configuration/sales_channel_create";
}

@RequestMapping(value="/config/{channelCode}/create", method=RequestMethod.POST)
public String postForm(
@Valid @ModelAttribute("createForm") RuleStoreDto form, @PathVariable String channelCode, BindingResult result, Authentication  authentication, ModelMap model) {
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
ChannelDto channelDto = channelService.findByClientIdAndChannelCode(userPrincipal.getUser().getClient().getId(), form.getChannelCode());
model.addAttribute("channel", channelDto);

try {
form.setClientId(userPrincipal.getUser().getClient().getId());
if(result.hasErrors()) {
model.addAttribute("createForm", form);
return "configuration/sales_channel_create";
}
customRuleService.save(form);
}catch(Exception e) {
model.addAttribute("err", e.getClass().getSimpleName());
model.addAttribute("createForm", form);
return "configuration/sales_channel_create";
}
return "configuration/sales_channel_create";
}

这是我的sales_channel_view.html中的一个片段,用于表视图:

<div class="btn-group">
<a class="btn btn-success"
th:href="@{|/config/${channel.channelCode}/create|}">
<i class="fa fa-plus">&nbsp; Create New</i>
</a>
</div>

这是我的sales_channel_create.html中的一个片段,用于以下表单:

<form id="demo-form2" th:action="|@{/config/${channel.channelCode}/create}|" th:object="${createForm}" method="post" data-parsley-validate class="form-horizontal form-label-left">
//stuff
</form>

因此,当我试图从表(viewTable(访问表单(createForm(时,我的表单没有完全显示&我得到了这个错误:

ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-8080-exec-4] Exception processing template "configuration/sales_channel_create": An error happened during template parsing (template: "class path resource [templates/configuration/sales_channel_create.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/configuration/sales_channel_create.html]")

我的代码出了什么问题?

没有完全的例外,我只能推测。

此处的管道符号(|(似乎是错误的:

th:href="@{|/config/${channel.channelCode}/create|}">
th:action="|@{/config/${channel.channelCode}/create}|"

因为它们不是有效URL的一部分,并且可能需要作为%7C进行转义。

相关内容

最新更新