Search code examples
springspring-mvcspring-form

Change Spring form tag path value


I need to convert "lastModified" to millisecond.Normally it is Date() format.But i must send it as a millisecond.How I can change path variable from jsp or my controller ? Or you can suggest other way.

enter image description here

enter image description here

enter image description here

enter image description here


Solution

  • You can add a transient long field and use it like below inside your Organization entity class.

    public class Organization {
    
        --------------
        --------------
    
        @Transient
        private long lastModifiedMili;
    
        public long getLastModifiedMili() {
            return lastModified.getTime();
        }
    
        public void setLastModifiedMili(long lastModifiedMili) {
            this.lastModifiedMili = lastModifiedMili;
            this.lastModified = new Date(lastModifiedMili);
        }
    
        public Organization(Long id, String name, String address, long lastModifiedMili) {
            this.id = id;
            this.name=name;
            this.address = address;
            this.lastModifiedMili = lastModifiedMili;
            this.lastModified = new Date(lastModifiedMili);
        }
    }
    

    And inside your form use this:

    <form:hidden path="lastModifiedMili" />