billc.cn
billc.cn

Reputation: 7317

Can I reuse a Spring MVC View instance?

I created a custom view that uses Json.Simple to serialize the model and write the JSON to the response directly.

For some requests, I need to send back a static JSON message, so I am wondering can I reuse a View instance I created earlier (with the message already set)?

My View class is thread-safe.

Upvotes: 1

Views: 233

Answers (2)

Arun P Johny
Arun P Johny

Reputation: 388406

I do not see any problem in reusing an already created view since the render method gets current response object.

Upvotes: 0

skaffman
skaffman

Reputation: 403551

Sure. As long as you make sure it's thread-safe, as you say, there's no reason that your controller can't return the same View object multiple times. Unorthodox, but valid.

Upvotes: 3

Related Questions