• Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring JPA POST Request Not Working  RSS feed

 
Mike London
Ranch Hand
Posts: 1499
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple Spring JPA application and my post request, though "working", is only adding blank lines to the database.

Wondering what I'm doing wrong.

---

Here's my POSTMAN POST request:
{
"pro_pk" : "null",
"mailer_name" : "xyz tansport"
}


I have the content type set as application/json

(MySQL is auto-incrmenting the primary key so I'm passing null for pro_pk)

-----

My Controller Class method is:

// save an order

-----

My Service class method is:



---

When I debug the service method or the controller method, both the pro_pk and mailer_name are null so they're not getting passed in.

What do I need to do? I tried a @PathVariable in the controller class method, but threw 500 errors.

Thanks in advance,

- mike




 
Mike London
Ranch Hand
Posts: 1499
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problems.

1. The JSON fields needed to look like the Java variables, NOT the database fields.

2. I needed a @RequestBody inside the save method (and update, too).

Now that I've solved these issues, it seems anyone with decent Spring background would spot these issues right away, leading me to believe nobody read my this post (or perhaps also the one I updated over a day ago).

---

Moreover, it's strange that there have been no replies from JR (from my two recent Spring postings) other than pointing out my formatting was incorrect or that I'd copied the same method twice. In years past, JR was alive with activity. Perhaps this is just how the Spring forum is? Or maybe other sites like Stack are more popular now? Not sure.

But using a framework like Spring makes me nervous. Why? Well, if everything "works", the sun is shining and the sky is blue and you're amazingly more productive. Yet, when something doesn't work, it can take frustrating days to figure it out. Maybe the forum folks here are too busy figuring out their own Spring problems?

- mike
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!