当前位置: 首页 > 工具软件 > Ra-Ajax > 使用案例 >

thymeleaf ajax回传,如何将参数传递给Thymeleaf Ajax Fragment

宇文弘懿
2023-12-01

我有一个Spring MVC控制器,该控制器返回百里香叶片段的名称以查看解析器bean。问题在于此片段需要使用url作为参数。在这里我放片段:

我无法在没有错误的情况下传递该参数。控制器如下:

@RequestMapping(method = RequestMethod.GET)

public String show(@CurrentUser User user, Model model) {

logger.info(user.toString());

if(!model.containsAttribute(BINDING_RESULT_NAME)) {

model.addAttribute(ATTRIBUTE_NAME, user);

}

model.addAttribute("url", "/admin/users/self/profile");

return "admin/fragments/user/personal::form-basic({url})";

}

对于上面的示例,我得到以下错误:

06-Jan-2017 11:36:40.264 GRAVE [http-nio-8080-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke El Servlet.service() para el servlet [dispatcher] en el contexto con ruta [/ejercicio3] lanzó la excepción [Request processing failed; nested exception is java.lang.IllegalArgumentException: Invalid template name specification: 'admin/fragments/user/personal::form-basic({url})'] con causa raíz

java.lang.IllegalArgumentException: Invalid template name specification: 'admin/fragments/user/personal::form-basic({url})'

at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:275)

at org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:189)

at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)

at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)

我已经做过这些测试:

"admin/fragments/user/personal::form-basic('{url}')";

"admin/fragments/user/personal::form-basic(@{/admin/users/self/profile})";

"admin/fragments/user/personal::form-basic(/admin/users/self/profile)";

"admin/fragments/user/personal::form-basic('/admin/users/self/profile')";

总之我得到了错误

 类似资料: