Skip to content

jcasbin/mybatisplus-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mybatisplus-adapter

codebeat badge build codecov javadoc Maven Central Discord

Mybatis-Plus Adapter is the Mybatis-Plus adapter for jCasbin, which provides interfaces for loading policies from Mybatis-Plus and saving policies to it.

Installation

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>mybatisplus-adapter</artifactId>
    <version>1.0.0</version>
</dependency>

Example

package com.company.example;

import org.casbin.jcasbin.main.Enforcer;
import org.casbin.jcasbin.util.Util;
import org.casbin.adapter.MybatisPlusAdapter;

public class Example {
    public void test() {
        Enforcer e = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");
    
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/casbin";
        String username = "YourUsername";
        String password = "YourPassword";
        
        MybatisAdapter a = new MybatisAdapter(driver, url, username, password, true);
    
        // Save policy to DB
        a.savePolicy(e.getModel());
    
        // Load policy from DB
        a.loadPolicy(e.getModel());
    }
}

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.