beetl+springBoot配置

不得不说beetl的使用人群太少了,资料查来查去都是那几个人写的,所以决定自己写一篇。

本文基于gradle教程,maven同理,只是导包方式不同,数据库为mysql

首先引入依赖

//    引入beetl 需要用到的jar
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
    implementation 'com.ibeetl:beetl-framework-starter:1.1.73.RELEASE'
//    implementation 'com.zaxxer:HikariCP:3.3.1'
    implementation 'mysql:mysql-connector-java:8.0.14'

 书写配置类,很多教程没有这一步

/**
 * @description:
 * @author: Blaze Jack
 * @create: 2019-11-08 21:10
 **/
@Configuration
public class BeetlConf {
        @Bean(name="datasource")
        public DataSource datasource(Environment env) {
            HikariDataSource ds = new HikariDataSource();
            ds.setJdbcUrl(env.getProperty("spring.datasource.url"));
            ds.setUsername(env.getProperty("spring.datasource.username"));
            ds.setPassword(env.getProperty("spring.datasource.password"));
            //ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
            return ds;
        }
}

dao层继承mapper

@SqlResource("student")
public interface StudentDao extends BaseMapper<Student> {
    List<Student> findStudents();
}

创建md文件

md文件书写语句

findStudents
===
select * from student

最后很关键,一定要在properties写明md文件的路径

beetlsql.sqlPath: /sql

使用方式很简单直接注入就可以了,本文演示的是自定义的sql查询,继承接口之后有很多自带的方法。

@RestController
public class TestController {
    @Autowired
    private StudentDao studentDao;
    @RequestMapping("/tt")
    public String tt() {
        System.out.println(studentDao.findStudents());
        return "i am tt";
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Blaze Jack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值