use of jakarta.mvc.Controller in project org.openntf.xsp.jakartaee by OpenNTF.
the class NoSQLExample method createPerson.
@Path("create")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Controller
public String createPerson(@FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("birthday") String birthday, @FormParam("favoriteTime") String favoriteTime, @FormParam("added") String added) {
Person person = new Person();
person.setFirstName(firstName);
person.setLastName(lastName);
if (StringUtil.isNotEmpty(birthday)) {
LocalDate bd = LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(birthday));
person.setBirthday(bd);
} else {
person.setBirthday(null);
}
if (StringUtil.isNotEmpty(favoriteTime)) {
LocalTime bd = LocalTime.from(DateTimeFormatter.ISO_LOCAL_TIME.parse(favoriteTime));
person.setFavoriteTime(bd);
} else {
person.setFavoriteTime(null);
}
if (StringUtil.isNotEmpty(added)) {
LocalDateTime dt = LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(added));
Instant bd = dt.toInstant(ZoneOffset.UTC);
person.setAdded(bd);
} else {
person.setAdded(null);
}
personRepository.save(person);
return "redirect:nosql/list";
}
use of jakarta.mvc.Controller in project org.openntf.xsp.jakartaee by OpenNTF.
the class NoSQLExample method update.
@Path("{id}/update")
@PATCH
@Controller
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String update(@PathParam("id") String id, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("birthday") String birthday, @FormParam("favoriteTime") String favoriteTime, @FormParam("added") String added) {
Person person = personRepository.findById(id).get();
person.setFirstName(firstName);
person.setLastName(lastName);
if (StringUtil.isNotEmpty(birthday)) {
LocalDate bd = LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(birthday));
person.setBirthday(bd);
} else {
person.setBirthday(null);
}
if (StringUtil.isNotEmpty(favoriteTime)) {
LocalTime bd = LocalTime.from(DateTimeFormatter.ISO_LOCAL_TIME.parse(favoriteTime));
person.setFavoriteTime(bd);
} else {
person.setFavoriteTime(null);
}
if (StringUtil.isNotEmpty(added)) {
LocalDateTime dt = LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(added));
Instant bd = dt.toInstant(ZoneOffset.UTC);
person.setAdded(bd);
} else {
person.setAdded(null);
}
personRepository.save(person);
return "redirect:nosql/list";
}
Aggregations