Google News
logo
Java Spring Boot - Interview Questions
How to save image in database using spring boot?
First configure mysql in your spring boot application.
Then you can map your entities with your db tables using JPA.
And with the help of save() method in JPA you can directly insert your data into your database
 
@RestController
@RequestMapping("/freetimelearning")
public class Controller {
@Autowired
private final FreeTimeLearningRepository freetimelearningRepository;
public Controller(FreeTimeLearningRepository freetimelearningRepository) {
}
 
In above case, your data which may be in JSON format can be inserted successfully into database.
 
@RequestMapping(method = RequestMethod.POST)
ResponseEntity<?> insert(@RequestBody Course course) {
greatLearningRepository.save(course);
 return ResponseEntity.accepted().build();
}
}

 

Advertisement