मैं इंटेलिजे पर वसंत बूट और थाइमेलीफ का उपयोग करके एक छोटा वेब फॉर्म एप्लिकेशन लिख रहा हूं, लेकिन ऐसा लगता है कि एचटीएमएल फाइल में, मॉडल के सभी फ़ील्ड को हल नहीं किया जा सकता है। यहाँ मेरी कोड है:IntelliJ में स्प्रिंग बूट + थाइमेलीफ: वर्र्स को हल नहीं कर सकता
नियंत्रक वर्ग:
@Controller
public class IndexController{
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(){
return "index";
}
@RequestMapping(value="/", method = RequestMethod.POST)
public String addNewPost(@Valid Post post, BindingResult bindingResult, Model model){
if(bindingResult.hasErrors()){
return "index";
}
model.addAttribute("title",post.getTitle());
model.addAttribute("content",post.getContent());
return "hello";
}
}
मॉडल कक्षा:
public class Post {
@Size(min=4, max=35)
private String title;
@Size(min=30, max=1000)
private String content;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
तो index.html है:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<title>Spring Framework Leo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h3>Spring Boot and Thymeleaf</h3>
<form action="#" th:action="@{/}" th:object="${post}" method="post">
<table>
<tr>
<td>Title:</td>
<td><input type="text" th:field="*{title}" /></td>
<td th:if="${#fields.hasErrors('title')}" th:errors="*{title}">Title error message</td>
</tr>
<tr>
<td>Content:</td>
<td><input type="text" th:field="*{content}" /></td>
<td th:if="${#fields.hasErrors('content')}" th:errors="*{content}">Content error message</td>
</tr>
<tr>
<td><button type="submit">Submit post</button></td>
</tr>
</table>
</form>
हमेशा के तहत लाल लाइनों रहे हैं " पोस्ट "," शीर्षक "और" सामग्री ", लेकिन मुझे नहीं पता कि इसे कैसे हल किया जाए। क्या यह इंटेलिजे की समस्या है या सिर्फ मेरे कोड की समस्या है?
यह इंटेलिजे 2013.3 में तय किया जाना चाहिए, मेरा संपादित उत्तर देखें। –