java - 如何使用弹簧在表格中显示日期?
问题描述
为了运行应用程序,我在战争中使用了 tomcat 8.5.50 包。我使用弹簧 5.2 版本。在所有操作中我都使用 JpaRepository。我没有在我的代码中使用日期时间转换器 - 也许这是一个错误?我想使用 jsp 在我的表中添加一个日期:
<div id="row">
<%--@elvariable id="mealsCreate" type=""--%>
<form:form action="${pageContext.request.contextPath}/create"
modelAttribute="mealsCreate" method="post">
<div class="col-md-9">
<input type="hidden"/>
<div class="form-group">
<div class="col-md-12">
<label for="datetime" type="table" class="table">DateTime</label>
<input id="datetime" type="datetime-local" name="datetime"/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="description" type="table" class="table">Description</label>
<input id="description" type="text" name="description"/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="calories" type="table" class="table">Calories</label>
<input id="calories" type="number" name="calories"/>
</div>
</div>
<button type="submit" class="btn btn-default" name="saveMeals">Save</button>
<button type="button" class="btn btn-default" name="cancelMeals" onclick="window.history.back()">Cancel</button>
</div>
</form:form>
</div>
但没有任何东西粘贴到我的表中:
我的模型:
@Entity
public class Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private int id;
@Column(name = "date_time", columnDefinition = "timestamp default new()")
private LocalDateTime dateTime;
@Column(name = "description")
private String description;
@Column(name = "calories")
private int calories;
public Meal() {
}
public Meal(int id) {
this.id = id;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public LocalDateTime getDateTime() {
return dateTime;
}
public void setDateTime(LocalDateTime dateTime) {
this.dateTime = dateTime;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getCalories() {
return calories;
}
public void setCalories(int calories) {
this.calories = calories;
}
}
也没有将任何内容加载到数据库中。我的sql查询:
CREATE TABLE meals
(
id integer NOT NULL,
date_time timestamp without time zone,
description text NOT NULL,
calories integer NOT NULL,
CONSTRAINT meals_pkey PRIMARY KEY (id)
);
控制器:
@Controller
public class Controller {
@Autowired
MealService mealService;
@GetMapping(value = "/list")
public String getAll(Model model) {
model.addAttribute("meals", mealService.getAll());
return "meals";
}
@GetMapping(value = "/createForm")
public String addForm(Model model) {
Meal meal = new Meal();
model.addAttribute("mealsCreate", meal);
return "createmealForm";
}
@PostMapping(value = "/create")
public String save(@ModelAttribute("mealsCreate") Meal meal) {
mealService.save(meal);
return "redirect:/list";
}
}
我的代码有什么问题?
解决方案
推荐阅读
- php - .htaccess 将尾随闪存添加到 URLS 中,其中包含句点
- scala - 将案例类列表连接到 kafka 生产者?
- excel - MacOs Excel 2011 VBA 宏在字符串模式后添加逗号和空格
- php - 如何在 PHP 中进行许可证验证
- django - FieldError 与管理计算字段上的自定义过滤器
- actionscript-3 - 当经典补间在第一秒不使用 stop() 时如何解决?
- php - 密码验证总是失败
- user-interface - DoubleSlider 4 自动热键 gui
- javascript - POST http://localhost:8080/storeSqlData.php 404(未找到)
- python - SVM、MLP 等可以对多变量时间序列问题进行分类吗?