Я новичок в Springboot и действительно нуждаюсь в вашем опыте. Пожалуйста, помогите мне.
Мне нужно передать данные в контроллер, когда кнопка нажата. Теперь я сталкиваюсь с ошибкой ниже, что на самом деле я делаю неправильно в моем коде?
'java.lang.String' to required type 'com.portal.dmtt.model.taskSchJob'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'TEST'; nested exception is java.lang.NumberFormatException: For input string: "TEST"
Контроллер
@RequestMapping(value="/runJob", method=RequestMethod.GET)
public String runJob(Model model, taskSchJob schJob) {
System.out.println("Start get request");
model.addAttribute("theTaskSchJobList", new taskSchJob());
schJob.getScript();
System.out.println("End get request");
return "redirect:/cronJob";
}
@RequestMapping(value="/runJob", method=RequestMethod.POST)
public String customerSubmit(@ModelAttribute taskSchJob schJob, Model model,@RequestParam String taskJobScript) {
System.out.println("Start post request");
System.out.println("End post request" + taskJobScript.toString());
return "redirect:/cronJob";
}
HTML
<tbody>
<tr th:each="taskJob : ${theTaskSchJobList}" style="text-align: center">
<form th:action="@{/runJob}" th:object="${theTaskSchJobList}" th:method="POST">
<td th:text="${taskJob.id}">Id</td>
<td th:text="${taskJob.title}">Username</td>
<td th:text="${taskJob.script}">Script</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<button type="submit" class="btn btn-success" th:value="${taskJob.script}" th:name="taskSchJob">
<span class="glyphicon glyphicon-play"></span>
</button>
</form>
</td>
</tr>
</tbody>
Модель
@Entity
@Table (name = "task_Sch_Job")
public class taskSchJob {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "title")
private String title;
@Column(name = "username")
private String username;
@Column(name = "script")
private String script;
@Column(name = "date_create")
private String date_create;
@Column(name = "cron_job")
private String cron_job;
@Column(name = "status")
private String status;
//------
//setter and getter
//------
изображение ниже, когда пользователь нажимает кнопку, он отправляет данные «заголовок» в контроллер.
![enter image description here](https://i.stack.imgur.com/10uXr.png)