第三章 处理表单和复杂的URL映射
1、“@{}”语法将会为资源构建完整的路径,它会将服务器上下文路径(在本例中,也就是localhost:8080)添加到它的参数上;
2、在controller中创建两个名为"/profile"映射时以参数来区分,否则会导致form表单在提交时报错,如下:
3、IDEA中创建getter/setter的快捷键为:Alt+Insert,然后选择"Getter and Setter"选项,最后选择要生成的变量点击"Finish"即可;
4、进行表单数据绑定时不能只按照书中给出的方式,只在HTML文件中添加,必须要在进行URL映射时传入一个ProfileForm对象,否则会编译不通过,因为在HTML中找不到profileForm变量。写法如下:
5、在最新(截止2018年8月4日)的Spring中书中提到的"WebMvcConfigurerAdapter"已经弃用,可改为"WebMvcConfigurationSupport"。代码如下:
6、来源于JSR-303规范的部分校验注解,如下:
7、自定义WebConfiguration之后静态资源的导入会发生404错误,需要在WebConfiguration类中添加如下方法:
8、3.2节中代码写法如下:
9、application.properties文件需要自己创建,其位置在“src/main/resources/config”下。Spring Boot中配置文件application.properties使用(转载)
10、“spring.messages.cache-seconds”在Spring Boot 2.0.4中已弃用,改用"spring.messages.cache-duration"。相关说明如下:
spring.messages.cache-duration= # Loaded resource bundle files cache duration. When not set, bundles are cached forever. If a duration suffix is not specified, seconds will be used.spring.messages.encoding=UTF-8 # Message bundles encoding.
11、3.3.1小节中导航栏设置时,书中的代码中"dataactivates"少写了"-",应为:data-activates。代码如下:
12、在进行3.3.3代码编写时,一直出现"#{}"标签无法读取"properties"中的内容的问题,后经查询发现是因为在最新(截止2018年8月6日)的Spring boot中不再自动配置MessageSourceAutoConfiguration,需要自己手动新增。代码如下:
附:
b、java.lang.Class说明(转载)