0

I am trying to save my form data into database table drivers. And using springboot with spring Data JPA . By using .save() method, database is inserting as null values. But not showing any error. I am adding my controller fie below,

DriverRepository driverRepo;


@RequestMapping(value="/driverSubmit", method=RequestMethod.POST)
public ModelAndView driverSubmit(@ModelAttribute Driver driver, Model model) 
    {
        model.addAttribute("driver", driver);
        driverRepo.save(driver);
        return new ModelAndView("redirect:/dHome"); //to home page after insertoin 
    }
8
  • did you checked if driver object has values? What means inserting as null? You will save a new driver in the db but not values? Please describe your problem more. Commented Sep 28, 2017 at 6:27
  • I am submitting a form. By giving action "/driverSubmit".When I am accessing values through @RequestParam method, It getting properly. But I need the above method for receiving submitted object and need to save to database Commented Sep 28, 2017 at 6:37
  • I already know what you are doing. But have you checked by debugging if dirver really maps the values your are sending? And again -> What means inserting as null? You will save a new driver in the db but not values? Commented Sep 28, 2017 at 6:39
  • 1
    Changed tags, since from the comments it seems clear that it is related to the form submit not being resolved into a Driver object Commented Sep 28, 2017 at 10:02
  • 1
    Hint: Entity has attributes with names like name, age, etc., whereas form fields are named dname, dage, etc. Commented Sep 28, 2017 at 10:22

1 Answer 1

1

Try to test your api from swagger or postman first, and debug the code first whether you are getting values in your driver object or not. If you are getting the data in driver properly then it must be some error coming out of your form request from UI. I guess an entry of driver object is getting created in db but all the values are getting saved according to their default initial values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.