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 use of pure java in weed3-2.1?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Today, I would like to talk to you about the use of pure java in weed3-2.1. many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Weed3 a mini ORM framework (only 0.1Mb)

When using pure java, there are three major interfaces available: db.table (..), db.call (..), and db.sql (). Generally use db.table (..) The interface is mostly used for chain operation. Its interface is named in a way that maps to SQL. For users, it is easy to think of what chain interfaces they can have. Like: .where (..) .and (..) .innerJoin (..) Wait.

The routine of chain operation: with db.table (..) Start. With .update (..) Or .insert (..) Or .delete (..) Or .select (..). Where .select (..) The IQuery interface is returned, providing a choice of various types of results.

First, add the meven dependency org.noear weed3 3.2.2.4 and then instantiate the database context object

All weed3 operations are based on DbContext. So it needs to be enumerated first.

If configuration is required, it can be obtained at application.properties, obtained through configuration service, and temporarily handwritten.

If it is a Spring framework, you can get the configuration through annotations. If it is a solon framework, you can get the configuration through annotations or Aop.prop (). Get ("xxx")

two。 After the configuration, the DbContext is instantiated. Here is a temporary handwriting.

/ example configuration using Properties DbContext db = new DbContext (properties); / example configuration using Map DbContext db = new DbContext (map); / example configuration using proxool thread pool (which seems to be out of fashion now) DbContext db = new DbContext ("user", "proxool.xxx_db"); / / example configuration using DataSource (commonly used when using connection pooling framework It is recommended that Hikari connection pool is used in downlink demo DbContext db = new DbContext ("user", new HikariDataSource (...)); / / and url,username,passwordDbContext db = new DbContext ("user", "jdbc:mysql://x.x.x:3306/user", "root", "1234"); / * I usually use configuration service, so the configuration provides database context objects directly. * / now, start doing simple data manipulation

General query operation

/ / count the number of users less than 10 long num = db.table ("user_info") .where ("user_id")

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

Internet Technology

Wechat

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

12
Report