DEV Community

Discussion on: Edit Item in Intellij IDEA

Collapse
raviyasas profile image
Ravi Yasas

You need to autowire the repository like below

@Autowired
    private ArtifactRepository artifactRepository;

    @RequestMapping(value="edit", method= RequestMethod.POST)
    public String processEditForm(@RequestParam(value="post_id") int post_id, @RequestParam(value="name") String name, @RequestParam(value="location") String location, @RequestParam(value="description") String description, Model model) {

        ThePost thePost = artifactRepository.findById(post_id).get();
        thePost.setName(name);
        thePost.setLocation(location);
        thePost.setDescription(description);
        artifactRepository.save(thePost);
        return "index";
    }

Collapse
declantreanor profile image
declanTreanor

in which case the OP would have gotten a Nullpointer, which wasn't shared. A bit more detail would be helpful but, certainly, not autowiring that dependency would cause problems.

Collapse
arotto8719 profile image
arotto8719 Author
Collapse
arotto8719 profile image
arotto8719 Author

Trying But I’m having trouble uploading photos. Any ideas?

Collapse
arotto8719 profile image
arotto8719 Author

I have no idea what a null pointer is

Collapse
arotto8719 profile image
arotto8719 Author

I already have that on top of home controller

Collapse
arotto8719 profile image
arotto8719 Author

github.com/arotto8719/app

The whole code is on here.

Collapse
raviyasas profile image
Ravi Yasas

When we are creating a Spring web application, the business logic should be in a separate layer as a Service. So we have Controller, Service, Repositories, and Models. Please check this github.com/raviyasas/spring-boot-hibernate-demo.git

Thread Thread
arotto8719 profile image
arotto8719 Author • Edited on

I have all that on there but I need to know what to put in the exact lines so I can save and edited item.

Something besides the Post or whatever.

I have artifact repository.

Am I supposed to copy and paste what you have or do I have to make mine similar to yours?

Thread Thread
raviyasas profile image
Ravi Yasas

It is better if you can write your own code like mine or you can use my one. It is the best practice to write code in mvc pattern. That is why I mentioned it.