【发布时间】:2018-07-17 07:52:20
【问题描述】:
我正在测试一个使用 thymeleaf 的 Spring Boot 应用程序,但我找不到任何解释如何将选择选项值从 thymeleaf 发送到 Spring Boot 服务类的文档。
基本上,我想要实现的是从选择标签中获取值,以便我可以通过以下方法将它们插入数据库: 请注意:此方法在服务 class=> 它在控制器类中具有 get 和 post 映射。
public void addNewJob(JobPostEntity jobPostEntity, @RequestParam(value="selectCategory") String selectCategory) {
jobPostEntity.setJobcategory("test");
jobPostRepository.save(jobPostEntity);
}
百里香文件是:
<form th:action="@{/newjob}" th:object="${addNewJob}" method="post">
<div class="form-group">
<label for="">Offer Title</label>
<input type="text" th:field="*{jobtitle}" class="form-control" placeholder="Entre Offer Title">
<small class="form-text text-muted">We'll never share your email
with anyone else.</small>
</div>
<div class="form-group">
<label >Company Name</label>
<input type="text" th:field="*{jobcompany}" class="form-control" placeholder="Enter Company Name">
</div>
<div class="form-group dropdown">
<label for="sel1">Choose Category (select one):</label>
<select name="*selectCategory"
class="form-control" id="selectCategory"
onchange="getSelectedValue();" th:field="*{selectCategory}">
<option value="">Select Option</option>
<option value="software_engineer">Software Engineer</option>
<option value="graphic_design ">Graphic Design</option>
<option value="customer_service ">Customer Service</option>
<option value="marketing" >Marketing</option>
<option value="healthcare">Health Care</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Offer</label>
<textarea class="form-control" th:field="*{jobtext}" placeholder="Describe your job offer"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit Offer</button>
</form>
【问题讨论】:
-
你能粘贴包含 addNewJob(..) 方法的整个类吗?也许您在控制器中缺少注释
标签: java spring-boot thymeleaf