Код: Выделить всё
Enter Todo Details
Target Date
Description
$('#targetDate').datepicker({
format: 'yyyy-mm-dd'
});
Код: Выделить всё
@RequestMapping(value="add-todo" , method = RequestMethod.GET)
public String showNewTodoPage(ModelMap model) {
String username = getLoggedinUsername();
Todo todo = new Todo(0,username,"kuch to bol vai",LocalDate.now().plusYears(1),false);
model.put("todo", todo);
return "todo";
}
@RequestMapping(value = "add-todo", method = RequestMethod.POST)
public String addNewTodoPage(ModelMap model,@Valid Todo todo,BindingResult result) {
if(result.hasErrors()) {
return "todo";
}
String username = getLoggedinUsername();
todo.setUsername(username);
System.out.println(todo.getDescription());
todoRepository.save(todo);
return "redirect:list-todos";
}
Код: Выделить всё
package com.in28minutes.springboot.myfirstwebapp.todo;
import java.time.LocalDate;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.validation.constraints.Size;
@Entity
public class Todo {
@Id
@GeneratedValue
private int id;
private String username;
@Size(min=10,message="Enter atleast 10 characters")
private String description;
private LocalDate targetDate;
private boolean done;
Todo(int id,String username,String description,LocalDate targetDate,boolean done){
this.id = id;
this.username=username;
this.description = description;
this.targetDate = targetDate;
this.done= done;
}
Todo(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id=id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username=username;
}
public String getDescription() {
return description;
}
void setDescription(String description) {
this.description=description;
}
public LocalDate getTargetDate() {
return targetDate;
}
public void setTargetDate(LocalDate targetDate) {
this.targetDate = targetDate;
}
public boolean getDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... springboot