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 to understand the use of weed3-4.1commenting sql

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

Share

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

How to understand the use of weed3-4.1Annotation sql. Aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Weed3 a mini ORM framework (only 0.1Mb)

Source code: https://github.com/noear/weed3 source code: https://gitee.com/noear/weed3

Use conventions *

1. Project start compilation parameter:-parameters

First a demo// declares mapperpublic interface DbMapper1 {@ Sql ("select * from appx where app_id = @ {app_id} limit 1") AppxModel appx_get (int app_id) throws Exception;} / / using mapperDbMapper1 dm = db.mapper (DbMapper1.class); AppxModel m = dm.appx_get (1); then a little bit more complicated demo1

1. Declare a mapper

/ / added replacement character / / added cache control public interface DbMapper1 {@ Sql (value = "select * from ${tb} where app_id = @ {app_id} limit 1", caching = "test", cacheTag = "app_$ {app_id}") AppxModel appx_get (String tb, int app_id) throws Exception;}

two。 Use it

DbContext db = new DbContext (...); DbMapper1 dm = db.mapper (DbMapper1.class); AppxModel m = dm.appx_get ("appx", 1); two variable forms + cache control

Two forms of variables

${} substitution variable (equivalent to placeholder for string concatenation)

@ {} compile variables (will be compiled to? and passed to jdbc through variables)

Cache control

Caching caching service

CacheTag cache tag (on top of key, the virtual tag; is established for easy cleaning)

UsingCache cache usage time

CacheClear cache cleanup (through cacheTag cleanup)

One more demo2.

After updating, clear the cache: app_$ {app_id}

Public interface DbMapper2 {@ Sql (value = "update appx set name=@ {name} where app_id = @ {app_id}", caching = "test", cacheClear = "app_$ {app_id}") void appx_set (int app_id, String name) throws Exception;} another demo3

Use query results to build cahce tag:app_type$ {type}

Public interface DbMapper3 {@ Sql (value = "select * from appx where app_id = @ {app_id} limit 1", caching = "test", cacheTag = "app_$ {app_id}, app_type$ {type}") AppxModel appx_get (int app_id) throws Exception;} add: build a cache service / / write anywhere / / 1. Initialize an ICacheServiceEx//2. Register to the cache / / 3 through nameSet ("test"). After that, it can be used by @ sql's caching (the same is true of xml sql's caching) / / new LocalCache ("test", 60). NameSet ("test"). This is the answer to the question on how to understand weed3-4.1. start annotating sql. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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