Spring MVC default value not working

Shahid Ghafoor picture Shahid Ghafoor · May 12, 2013 · Viewed 16.9k times · Source
@RequestMapping(value = "/Fin_AddBankAccount", method = RequestMethod.POST)
public @ResponseBody JsonResponse addCoaCategory(
    @RequestParam(value="code", required=true) long code,
    @RequestParam(value="startFrom", required=true) long startFrom,
    @RequestParam(value="name", required=true, defaultValue="N/A") String name)
    {

    }

defaultValue="N/A" not working , As I did not provide any text in name field , it store null in database instead of "N/A"?

Answer

Sanjaya Liyanage picture Sanjaya Liyanage · May 12, 2013

What is the point of setting a default value if you really want that parameter. if you mark it as required true(not needed as it is default) then no need of a default value. If that parameter is not mandatory then mark it as false and give a default value.