How to Pass Complex Objects as GET Request Parameters in Spring MVC?
Nov 24, 2024 am 08:14 AMPassing Complex Objects as GET Request Parameters in Spring MVC
In a scenario where you're filtering data from a table using Ajax GET requests, you may encounter the need to pass a complex object as a request parameter. Traditionally, this would require a plethora of @RequestParam annotations in your controller.
Problem:
You have a GET request to filter a table with query parameters like:
http://foo.com/system/controller/action?page=1&prop1=x&prop2=y&prop3=z
Your Controller's parameters would be:
@RequestMapping(value = "/action") public @ResponseBody List<MyObject> myAction( @RequestParam(value = "page", required = false) int page, @RequestParam(value = "prop1", required = false) String prop1, @RequestParam(value = "prop2", required = false) String prop2, @RequestParam(value = "prop3", required = false) String prop3) { ... }
Solution:
To simplify this process, you can pass the complex object directly as a request parameter without the @RequestParam annotation. Spring will automatically bind the request parameters to the instance of your class:
public @ResponseBody List<MyObject> myAction( @RequestParam(value = "page", required = false) int page, MyObject myObject)
The above is the detailed content of How to Pass Complex Objects as GET Request Parameters in Spring MVC?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Top 4 JavaScript Frameworks in 2025: React, Angular, Vue, Svelte

How does Java's classloading mechanism work, including different classloaders and their delegation models?

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?

Iceberg: The Future of Data Lake Tables

How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?

Spring Boot SnakeYAML 2.0 CVE-2022-1471 Issue Fixed

Node.js 20: Key Performance Boosts and New Features

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?
