springMVC 表单校验、日期类型的转换

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {

    private final AppointmentBook appointmentBook;

    @Autowired
    public AppointmentsController(AppointmentBook appointmentBook) {
        this.appointmentBook = appointmentBook;
    }

    @RequestMapping(method = RequestMethod.GET)
    public Map<String, Appointment> get() {
        return appointmentBook.getAppointmentsForToday();
    }

    @RequestMapping(path = "/{day}", method = RequestMethod.GET)
    public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
        return appointmentBook.getAppointmentsForDay(day);
    }

    @RequestMapping(path = "/new", method = RequestMethod.GET)
    public AppointmentForm getNewForm() {
        return new AppointmentForm();
    }

    @RequestMapping(method = RequestMethod.POST)
    public String add(@Valid AppointmentForm appointment, BindingResult result) {
        if (result.hasErrors()) {
            return "appointments/new";
        }
        appointmentBook.addAppointment(appointment);
        return "redirect:/appointments";
    }
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏一个会写诗的程序员的博客

Kotlin Compiler Plugins : All-open , Kotlin-spring,No-arg,Kotlin-jpaCompiler Plugins

Kotlin has classes and their members final by default, which makes it inconvenie...

2392
来自专栏Netkiller

Spring Boot 快速开始

节选自 《Netkiller Java 手札》 11.2. Spring Boot 11.2.1. pom.xml <project xmlns="http...

3535
来自专栏一个会写诗的程序员的博客

$ spring init --list

1142
来自专栏康怀帅的专栏

CoreOS 配置工具 Ignition v2.2

This pre-release version of the specification is experimental and is subject to ...

3656
来自专栏三杯水

CentOS 7.5安装部署Jewel版本Ceph集群

1、修改cpeh.conf文件 注意mon为奇数,如果为偶数,有一个不会安装,另外设置好public_network,并稍微增大mon之间时差允许范围(默认为...

1292
来自专栏运维

CentOS 7.5安装部署Jewel版本Ceph集群

1、修改cpeh.conf文件 注意mon为奇数,如果为偶数,有一个不会安装,另外设置好public_network,并稍微增大mon之间时差允许范围(默认为0...

1143
来自专栏一个会写诗的程序员的博客

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logba...

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Ei...

4655
来自专栏数据结构与算法

Codeforce GYM 100741 A. Queries

A. Queries time limit per test 0.25 s memory limit per test 64 MB input st...

28512
来自专栏Java帮帮-微信公众号-技术文章全总结

Java操作数据库Spring(2)

pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www...

3957
来自专栏增长技术

deploy to heroku

1201

扫码关注云+社区

领取腾讯云代金券