Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does SpringBoot use an entity to receive multiple parameters passed by a Get request

2025-03-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces SpringBoot how to use the entity to receive the multiple parameters passed through the Get request, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will get something after reading this article on how to use the entity to receive the multiple parameters passed through the Get request. Let's take a look.

1. The Controller layer does not take any annotation receiving parameters

The first method is the simplest. I seriously doubt why it didn't work before, who knows. But this time it really works, the easiest way is to enter the Controller interface without any comments! SpringBoot does the processing automatically. The code is as follows:

/ * * @ author zhangzhixiang * @ since v1.0.0 * / @ RestController@RequestMapping (path = "/ ui/institution") public class InstitutionManagementController {@ GetMapping (value = "/ pageQueryForAssign") public void pageQueryInstitutionsForAssign (InstitutionQueryDTO queryDTO) {}}

In fact, the key point is that there are no notes next to InstitutionQueryDTO, so it is good for the frontend to pass Get parameters normally. An example of the format for passing parameters from frontend is as follows:

Http://192.168.63.125/ui/institution/pageQueryForAssign?name='xxx'&sex=' Man'

The name and sex here are attributes in the InstitutionQueryDTO entity, and SpringBoot will automatically populate the entity for us.

Second, the Controller layer receives parameters through @ ModelAttribute

This method of writing is found in reading articles on the Internet, and I will also record this method.

/ * @ author zhangzhixiang * @ since v1.0.0 * / @ RestController@RequestMapping (path = "/ ui/institution") public class InstitutionManagementController {@ GetMapping (value = "/ test") public void test (@ ModelAttribute InstitutionQueryDTO queryDTO) {}}

The focus here is the @ ModelAttribute annotation, which also populates the parameters passed from the front end into the business entity, which is in the same format as method 1.

A year ago, I should have also had the parameters to accept Get requests in the first way, but failed. I failed because my Controller received multiple entity input parameters at the same time, so I failed.

This is the end of the article on "how SpringBoot uses entities to receive multiple parameters passed through Get requests". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how SpringBoot uses entities to receive multiple parameters passed through Get requests". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report