I am trying to learn how to integrate Spring Boot(2.6.3) with FreeMarker(2.3.31). Everything works fine until I met an FreeMarker error while trying to get the value like ${myObject.pAram!} while the first or second letter of the param is capitalized.
So I did so test work and get the following conclusion:
While param name of an object is first letter or second letter capitalized, FreeMarker couldn`t get the param value. Some code here in case of my poor English:
@Data
public class TestBean {
String param; //no-capitalized param
String aParam; //second letter capitalized param
String Bparam; //first letter capitalized param
String cpRam; //third letter capitalized param
}
Here what I do some setter in controller:
@RequestMapping("/test")
public String insure(@PathVariable String module,HttpServletRequest request) {
TestBean testBean = new TestBean();
testBean.setParam("param-no capitalize");
testBean.setAParam("aParam-capitalize the second letter");
testBean.setBparam("Bparam-capitalize the first letter");
testBean.setCpAram("cpAram-capitalize the third letter");
request.setAttribute("testBean",testBean);
return "test";
}
And what the test.ftl looks like:
<body>
<body>
<div>${testBean.param!"missing param"}</div>
------------------------------
<div>${testBean.aParam!"missing aParam"}</div>
------------------------------
<div>${testBean.Bparam!"missing Bparam"}</div>
------------------------------
<div>${testBean.cpAram!"missing cpAram"}</div>
However, the final html result is:
param-no capitalize
------------------------------
missing aParam
------------------------------
missing Bparam
------------------------------
cpAram-capitalize the third letter
Since I`m new to FreeMarker and Spring Boot, I failed to figure out why.
Could someone tell me the exact reason? Am I missing some point?
Thanks a lot!