Giter Site home page Giter Site logo

tufo830 / spring-boot-starter-aliyun-sls-ibatis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhangle1993/spring-boot-starter-aliyun-sls-ibatis

0.0 0.0 0.0 14 KB

一个类似mybatis的查询框架,功能是查询阿里云的sls日志。可快速继承到springboot的一个starter

Java 100.00%

spring-boot-starter-aliyun-sls-ibatis's Introduction

阿里云SLS日志查询框架

index.png

使用示例

本地安装 install
git clone https://github.com/ZhangLe1993/spring-boot-starter-aliyun-sls-ibatis.git
cd spring-boot-starter-aliyun-sls-ibatis
mvn install
springboot项目中引入
<dependency>
    <groupId>com.biubiu</groupId>
    <artifactId>spring-boot-starter-aliyun-sls-ibatis</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
在配置文件中配置sls的配置信息
# sls的 endpoint示例
sls.ibatis.endpoint=cn-beijing.log.aliyuncs.com
# sls.ibatis.endpoint=cn-hangzhou.log.aliyuncs.com
# sls的 ak/sk
sls.ibatis.accessKeyId=xxxxxx
sls.ibatis.accessKeySecret=xxxxxx
启动类上配置 mapper 扫描
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

// 包名就是自定义注解 SlsMapper的 mapper 的包路径 ,示例如下
@SpringBootApplication
@SlsMapperScan(basePackages = {"com.biubiu.sls.mapper1", "com.biubiu.sls.mapper2"})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}
定义一个对象
/**
 * @author :张音乐
 * @date :Created in 2021/5/30 下午12:46
 * @description:测试对象
 * @email: [email protected]
 * @version:
 */
public class User {

    private String id;

    private String name;

    public User() {
    }

    public User(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
定义一个Mapper接口
package com.biubiu.sls.mapper;

import com.biubiu.sls.annotation.*;

import java.util.List;

/**
 * @author :张音乐
 * @date :Created in 2021/5/30 下午12:45
 * @description: 测试 Mapper
 * @email: [email protected]
 * @version:
 */
@SlsMapper
public interface UserMapper {

    @SlsSelect("* | select userId, name from log ")
    @SlsTable(project = "dms-app", logStore = "dms-app-prod")
    List<User> select(@SlsFrom int from, @SlsTo int to);

    @SlsSelect("* | select userId, name from log where userId=#{userId} ")
    @SlsTable(project = "dms-app", logStore = "dms-app-prod")
    User getUserById(@SlsParam("userId") String userId, @SlsFrom int from, @SlsTo int to);

}
在 Service中使用
import com.biubiu.sls.mapper.User;
import com.biubiu.sls.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public void testSelect() {
        int start = new Date("2022-08-16 00:00:00").getTime() / 1000;
        int end = new Date("2022-08-17 00:00:00").getTime() / 1000;

        // 批量查询 示例
        List<User> list = userMapper.select(start, end);

        // 单条查询 示例
        User user = userMapper.getUserById("105281", start, end);
        
    }
}
其他文档: 阿里云sls官网文档

阿里云sls SQL语法文档地址

spring-boot-starter-aliyun-sls-ibatis's People

Contributors

zhangle1993 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.