There is spring mvc and a simple form (for example), respectively, I use this form to create and edit a contact (I pull data from the database).

<form> <input id="name" type="text"> ... <input id="photo" type="file"> <button type="submit">submit</button> </form> 

Trouble occurs if the user does not change the photo when editing, then when sending the form in the tag <input id="photo" type="file"> will be empty and the existing photo will be successfully replaced with NULL . Are there any solutions on the client side? and how to do things like that?

  • As the most banal / rough set the photo field value required. - Shezmu
  • Hmm, check for null and not update? - Igor

1 answer 1

If this is a required action, set the required field.

And if it is permissible (do not load the photo) - check the number of files, and if there are no files, then do not replace the photo

  • The field is optional, i.e. Option required is no longer required. After checking for the number of files, as well as for null, the following comes out here; in the controller, I collect the object from the form fields and then send it to the database (described abbreviated) If there is no photo field, check if it was, i.e. request to the database - we check what is written there and what we have, etc. It seems to me that somehow difficult. - rptsv
  • Check via zhsku if there are no files - set it to disabled. It seems if it does not send disabled - user190134