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

What is the queryForList of jdbcTemplate in java?

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you what the queryForList of jdbcTemplate in java is like. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Do you really understand the queryForList in jdbcTemplate?

Is your imaginary queryForList supposed to look like this?

String sql = "select * from person"; List persons = jdbcTemplate.queryForList (sql, Person.class)

And then, you ordered run excitedly.

The program comes out of something you can't even dream of, isn't it list? Why is expected 1?

I have a total of 7 pieces of data, why actual 4?

I'm still young. Why didn't you put me through this?

There is only one truth:

Pass the corresponding class, create the singleColumnRowMapper, that is, take only one column of values, and then take a look at the documentation comments

You can see that you have used too many ORM frameworks. This thing does not support custom bean, and this class only supports basic types such as Integer,String.

Now do you understand what except 1 actually 4 means?

People expect to return one column, but you have returned four columns, do not understand? Let me give you an example.

String sql = "select id from person"; List ids = jdbcTemplate.queryForList (sql, Integer.class)

If you return the id column, you can use queryForList. The list is a collection of all the id.

This is what the queryForList of jdbcTemplate in java is like. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, 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