Skip to main content

Posts

Showing posts with the label Data Binding

SpringBoot : How to read Header from Request and bind to variable

How to read Headers in Spring Boot Controller How to Allow Custom Headers in Spring Boot  Suppose we have a controller and want to bind the Headers to a variable, then we can do the following @RequestHeader(value = "Accept-Language", defaultValue = "en") String locale This will bind the Header Accept-Language , to the variable locale. value="" It defines the name of the header to bind to the variable required= boolean It tells if this is mandatory header or not. default value is true defaultValue ="" It can be used to give a default value if the header is not present. Similarly you can bind Custom Headers like shown below // String @RequestHeader(value = "X-My-String-Header", defaultValue = "Hello World") String h1 // Long @RequestHeader(value = "X-My-Long-Header", defaultValue = 212) Long h2 Do not use " _ " underscore in header key or values, because they get neglected while htt...

SpringBoot : How to bind data from url to a variable

Binding data from URL to a variable Suppose you want to have bind some data from URL then you can do the following create the @RequestMapping annotation e.g /list/{id} /{version}/list/{id} bind the Url parameters using @PathVariable annotation e.g @PathVariable("id") Long id @PathVariable("version") int version,@PathVariable("id") Long id Complete code may look like this, @RequestMapping("list/{id}") public Object list(@PathVariable("id") Long id ){ // Logic goes here } @RequestMapping("/{version}/list/{id}") public Object list(@PathVariable("version") int version,@PathVariable("id") Long id ){ // Logic goes here }

Different ways to bind Elements to Model in AngularJs

Different ways to Bind Elements to Model/ Directives You can bind the Angular Elements to the Model in the following ways. <span ng-bind="name"></span> <br/> <span ng:bind="name"></span> <br/> <span ng_bind="name"></span> <br/> <span data-ng-bind="name"></span> <br/> <span x-ng-bind="name"></span> <br/> Remove the x- or data-  from the start of the element attributes. e.g data-ng-bind and x-ng-bind can be written as ng-bind Convert the delimiters like :, -, _  to camelCase . Since the Html is case insensitive you can not use camelCase and you can use delimiters like :, -, _ to write your directives/angular . So the above ways are Following example in the Plunk shows the various ways to write our angular directive. Loading plunk... Now most of the above code works perfectly with angular js but they may cause HTML validation to fa...