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 Spring Data MongoDB remove the _ class attribute field

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article shows you how to remove the _ class attribute field from Spring Data MongoDB. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Oyhk study notes

Spring Data MongoDB removes the _ class attribute field

I believe that if you use java to operate mongodb, many people will choose spring data mongodb. I am also one of them who chose spring data mongodb. I also like spring things very much. Ha

In the beginning, I used spring data mongodb, and when I added a piece of data, I used MongoVUE to query the data. As shown in the picture

See the _ class property?

Briefly talk about this field, why should spring data mongodb be added, probably in order to query the type conversion of the data. Let's check it out again.

However, you will find that with and without this field, when querying data, it can also be converted into an object. So... It's better not to, not only the data is big, but only a little..

But it seems that I am not used to this field. Get rid of it.

The following two properties are removed from the _ class field. Personally, I like to use xml configuration.

The first is annotation.

@ Configuration public class SpringMongoConfig {public @ Bean MongoDbFactory mongoDbFactory () throws Exception {return new SimpleMongoDbFactory (new Mongo (), "database");} public @ Bean MongoTemplate mongoTemplate () throws Exception {/ / remove _ class MappingMongoConverter converter = new MappingMongoConverter (mongoDbFactory (), new MongoMappingContext ()); converter.setTypeMapper (new DefaultMongoTypeMapper (null)); MongoTemplate mongoTemplate = new MongoTemplate (mongoDbFactory (), converter); return mongoTemplate;}}

The second way: xml configuration

All right, now that the configuration is complete, I'll run the code that inserts the data again, and then take a look at the situation. Okay, the following figure

Are you comfortable now? the field of _ class is gone. OK, it's done.

The above is how Spring Data MongoDB removes the _ class attribute field. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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

Database

Wechat

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

12
Report