mybatis-patterns
यह क्या करती है
यह टूल MyBatis तकनीक से डेटाबेस के साथ काम करने वाले कोड को व्यवस्थित और बेहतर बनाने में मदद करता है। यह पक्का करता है कि आपकी queries सुरक्षित, तेज़ और समझने में आसान हों।
कब इस्तेमाल करें
- ✓जब आप डेटा एक्सेस करने वाला प्रोग्राम लिख रहे हों या उसका रिव्यू कर रहे हों।
- ✓डेटाबेस कमांड लिखने के अलग-अलग तरीकों में से चुनते समय।
- ✓प्रोग्राम को डेटा तेज़ी से लाने लायक बनाने की कोशिश में।
Skill का लिंक
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/mybatis-patterns/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरी MyBatis डेटाबेस queries को हमलों से सुरक्षित कैसे रखूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह आपके MyBatis कोड का विश्लेषण करता है, ताकि आम पैटर्न पहचाने जा सकें और सुधार सुझाए जा सकें। इसमें यह भी देखा जाता है कि डेटा कैसे भेजा और लिया जाता है, और transactions कैसे संभाले जाते हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
MyBatis Patterns
Use MyBatis when SQL control and explicit mappings matter. Keep SQL readable,
make mapper contracts small, and put business transactions in the service layer.
Pair this skill with springboot-patterns for application structure,
database-migrations for schema changes, postgres-patterns or
mysql-patterns for engine-specific SQL, and security-review for untrusted
input and access-control concerns.
When to Activate
- Adding or reviewing MyBatis mapper interfaces or XML files
- Choosing between XML mappers, annotation mappers, and generated SQL
- Designing
resultMapmappings, joins, nested collections, or projections - Reviewing dynamic SQL, parameter binding, pagination, or batch writes
- Debugging N+1 queries, slow statements, connection use, or transaction bugs
- Integrating MyBatis-Spring into Spring Boot or an XML-first legacy application
How It Works
Use a thin mapper for persistence operations and keep business rules in a service. A typical flow is:
Controller / batch job -> Service (@Transactional) -> Mapper -> Database
- Register mappers once, either with
@Mapperon each interface or with@MapperScanfor a package. Do not mix registration approaches casually. - Keep the XML
namespaceequal to the mapper interface's fully qualified name. - Give each statement a stable, descriptive
id; treat mapper methods as a persistence API that can be tested independently. - Return a domain DTO or projection for read paths instead of exposing a large mutable map when the shape is known.
- Keep schema changes in migrations. Do not make mapper startup silently create or alter production tables.
Examples
@MapperScan("com.example.user.persistence")
@Configuration
class MyBatisConfig {
}
public interface UserMapper {
UserSummary findSummaryById(long userId);
}
<mapper namespace="com.example.user.persistence.UserMapper">
<select id="findSummaryById"
parameterType="long"
resultType="com.example.user.persistence.UserSummary">
SELECT id, display_name AS displayName, status
FROM users
WHERE id = #{userId}
</select>
</mapper>
Parameter Binding and SQL Safety
Use #{...} for values. MyBatis binds it as a prepared-statement parameter.
Treat ${...} as raw SQL text: it is only appropriate for a value selected
from a closed, application-owned allowlist such as a sort-column map.
private static final Map<String, String> SORT_COLUMNS = createSortColumns();
private static Map<String, String> createSortColumns() {
Map<String, String> columns = new HashMap<>();
columns.put("name", "display_name");
columns.put("created", "created_at");
return Collections.unmodifiableMap(columns);
}
String sortColumn = SORT_COLUMNS.getOrDefault(request.sort(), "created_at");
String sortDirection = request.descending() ? "DESC" : "ASC";
// The mapper receives only an allowlisted identifier; user input is never
// passed directly to ${sortColumn} or ${sortDirection}.
<select id="findPage" resultType="com.example.user.persistence.UserSummary">
SELECT id AS id,
display_name AS displayName,
status AS status,
created_at AS createdAt
FROM users
WHERE tenant_id = #{tenantId}
ORDER BY ${sortColumn} ${sortDirection}
LIMIT #{limit}
</select>
Derive tenantId from the authenticated principal or a server-side tenant
context, never from a request field. Authenticate the principal and verify
that it is authorized for the tenant before invoking the mapper; keep the
tenant_id predicate in SQL as defense in depth.
If possible, avoid ${} entirely by selecting among fixed statements or by
using a database-specific query builder. Never interpolate user input into a
table name, column name, ORDER BY, WHERE fragment, or SQL expression.
For multiple parameters, use a request object or explicit @Param names:
List<UserSummary> findActive(
@Param("tenantId") long tenantId,
@Param("statuses") Set<UserStatus> statuses
);
Do not use the deprecated external parameterMap element. Prefer inline
parameter mappings and explicit jdbcType for nullable values when the JDBC
driver needs it.
XML, Result Types, and Result Maps
- Use
resultTypefor a simple one-to-one mapping whose column labels already match the target properties. - Use
resultMapwhen aliases, type handlers, nested objects, or collections need explicit mapping.
…
अक्सर पूछे जाने वाले सवाल
MyBatis क्या है?
MyBatis एक टूल है जो Java प्रोग्राम को डेटाबेस से बात करने में मदद करता है, और इससे SQL कमांड ज़्यादा व्यवस्थित तरीके से लिखे जा सकते हैं।
'mappers' क्या होते हैं?
Mappers आपके प्रोग्राम के कोड और SQL कमांड के बीच अनुवादक की तरह होते हैं। वे तय करते हैं कि कौन सा डेटा लाना है और उसे कैसे दिखाना है।
queries की सुरक्षा क्यों ज़रूरी है?
कमज़ोर queries से गलत लोग आपका डेटा देख या बदल सकते हैं। यह टूल ऐसा होने से बचने में मदद करता है।
जानकारी
लेखक का मूल विवरण
MyBatis and MyBatis-Spring patterns for mapper design, XML and annotation SQL, result mapping, dynamic SQL safety, transactions, batching, pagination, and query performance. Use when building or reviewing Java persistence code with MyBatis, Spring Boot, MyBatis-Spring, or MyBatis-based legacy applications.
repo: affaan-m/ECC
लोकप्रियता
- GitHub स्टार
- 280k
- रैंकिंग में स्थान
- #214
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
accessibility
280kयह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।
agent-architecture-audit
280kयह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।
agent-eval
280kयह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।
agent-harness-construction
280kयह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।