18910140161

java-在Thymeleaf中输入字段的id和name属性生成无效,带有JS-Stack溢出

顺晟科技

2022-10-19 13:02:36

216

我遇到了一个很奇怪的问题,我找不到原因。简单地说,当我试图在update.html中更新应用程序中以前给出的一些答案时,某些东西会为我的一个输入字段生成随机ID和随机名称值,因此这些特定的数据不会被发送到后端。

下面是我的update.html的控制器方法

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

这是我要发送到HTML的对象的类

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

问题类

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

我的答案类

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

我的更新HTML

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

最后,我的renderanswerform.js文件

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

在浏览器中检查ScaleQuestion输入时,我看到的不是正确的名称属性,而是以下内容。我在代码中没有提供任何id,并且name属性一开始就不应该包含“Question0.answers0”,只应该包含answers[0]。 启动应用程序时在HTML中使用ScaleQuestion(不正确)

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

RadioButton问题(正确):

 @GetMapping("/update/{questionFormId}/{appUserId}")
 public String updateAnswerFormCreatedByUser(@PathVariable long questionFormId, @PathVariable long appUserId, Model model) {
   log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " started");
   try {
     model.addAttribute("answerForm", answerFormService.createAnswerFormToUpdate(questionFormId, appUserId));
     log.info("GET answer-form/update/" + questionFormId + "/" + appUserId + " finished");
     return "answerform/update";

到目前为止我所尝试的内容:

  • 使用无效缓存重新启动Intellij
  • 从浏览器中删除缓存
  • 使用不同的浏览器
  • 将内容复制到其他html文件,并从控制器引用该文件

我的猜测是js代码以前的某个状态发生了干扰(因为在此之前所有的输入字段都是在js中生成的),但我看不出是如何或在哪里生成的。

提前感谢您的帮助!


顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航