gpt4 book ai didi

mysql - 带有 Thymeleaf、Spring boot、Mysql 的 Ckeditor

转载 作者:行者123 更新时间:2023-11-30 21:39:46 25 4
gpt4 key购买 nike

当点击“保存”时,除了“内容”之外的所有字段都被插入到 MySQL 中。

当调试字段“Content”为空时

帮帮我,谢谢

这是我的代码:

form-post.html

<form action="#" th:action="@{/savepost}" th:object="${post}"
method="POST" novalidate="novalidate">
<!-- <input type="hidden" th:field="*{id}" /> -->
<div class="form-group">
<label>Title</label> <input type="text" class="form-control"
th:field="*{title}" th:errorclass="field-error" /> <em
th:if="${#fields.hasErrors('title')}" th:errors="*{title}"></em>
</div>
<div class="form-group">
<label>Description</label> <input type="text"
class="form-control" th:field="*{description}"
th:errorclass="field-error" /> <em
th:if="${#fields.hasErrors('description')}" th:errors="*{description}"></em>
</div>
<div class="form-group">
<label>Link Image</label> <input type="url"
class="form-control" th:field="*{image_title}" />
</div>
<div class="form-group">
<label>Category</label> <input type="number"
class="form-control" th:field="*{id_category}" />
</div>
<div class="form-group">
<label>Id Images</label> <input type="number"
class="form-control" th:field="*{id_images}" />
</div>
<!-- <input type="hidden" th:field="*{create_date}" /> -->
<div class="form-group">
<label>Create By</label> <input type="text"
class="form-control" th:field="*{create_by}" />
</div>
<!-- <input type="hidden" th:field="*{view}" /> -->
<div class="form-group">
<label>Source</label> <input type="text"
class="form-control" th:field="*{source_post}" />
</div>
<div class="form-group">
<label>Content</label> <input type="text" id="con" name="con"
class="form-control" th:field="*{content}" th:text="${content}"/>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<button type="reset" class="btn btn-primary">Reset</button>
<script>
CKEDITOR.replace('con');
</script>
</form>

Controller.java@ Controller

@GetMapping(value="/createpost")
public String create(Model model) {

model.addAttribute("post", new Post());
return "form-post.html";
}

@PostMapping(value="/savepost")
public String save(@Valid Post post, BindingResult result, RedirectAttributes redirect) {


if(post.getCreate_date() == null) {
Date date = new Date();
post.setCreate_date(date);
}
if(post.getView() == null) {
post.setView(1);
}
if(post.getContent() == null || post.getContent().isEmpty()) {
post.setContent("Error insert content!!!. Because input content null or empty.");
}
postService.savePost(post);
//redirect.addFlashAttribute("success", "Saved contact successfully!");
return "redirect:/index";
}

最佳答案

我找到了问题的答案。

<input type="text" id="con" name="con" class="form-control" th:field="*{content}"/>

替换为:

<textarea name="cont" id="cont" rows="10" cols="80" th:field="*{content}"></textarea>

关于mysql - 带有 Thymeleaf、Spring boot、Mysql 的 Ckeditor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52219764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com