您现在的位置是:首页 > 文章详情

介绍 Lazy Jpa 是 lazy orm 框架衍生出类似 Spring JPA 框架

日期:2024-05-16点击:185

介绍Lazy Jpa 是lazy orm框架衍生出类似Spring JPA 框架

非Spring项目使用

安装

  <dependency>  <groupId>top.wu2020groupId>  <artifactId>wu-database-lazy-jpaartifactId>  <version>1.2.6-JDK17-SNAPSHOTversion>  dependency>

声明接口

 public interface TestLazyJpaRepository extends LazyJpaRepository<SysUser,Long> { } 

接口调用(基础CRUD)

  public static void main(String[] args) {  LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream("jdbc:mysql://127.0.0.1:3306/wu_database_lazy_simple?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai",  "root", "wujiawei");  TestLazyJpaRepository lazyJpaRepository = LazyRepositoryFactorySupport.createLazyJpaRepository(lazyLambdaStream, TestLazyJpaRepository.class);    // 统计数据库数量  long count = lazyJpaRepository.count();  // 获取所有数据  Iterable<SysUser> all = lazyJpaRepository.findAll();  for (SysUser sysUser : all) {  System.out.println(sysUser);  }  }

Spring 项目使用

安装

  <dependency>  <groupId>top.wu2020groupId>  <artifactId>wu-framework-lazy-orm-spring-starterartifactId>  <version>1.2.6-JDK17-SNAPSHOTversion>  dependency>

声明接口

 @LazyRepository public interface TestLazyJpaRepository extends LazyJpaRepository<SysUser,Long> { }

接口配置

 @LazyRepositoryScan(scanBasePackages = "com.wu.xxx.mapper")// 扫描你使用的repository接口 @SpringBootApplication public class WuDatabaseLazyStarterSimpleApplication {  public static void main(String[] args) {  SpringApplication.run(WuDatabaseLazyStarterSimpleApplication.class, args);  } }

接口使用

 @LazyRepository public interface SysMenuLazyJpaRepository extends LazyJpaRepository<SysMenu, Integer> {    // 自定义查询  @LazySelect("select * from sys_menu where parent_id={parentId}")  List<SysMenu> findListByParentId(Integer parentId);  @LazySelect("select * from sys_menu where id ={id}")  SysMenu findMenuById(@LazyParam("id") Integer menuId);  @LazySelect("select * from sys_menu where id ={id}")  List<Map ?>> findListMapByParentId(@LazyParam("id") Integer menuId);  @LazyInsert("INSERT Ignore INTO `sys_menu` ( `id`, `name`, `url`, `icon`, `parent_id`,`parent_name`,`sort`,`status`) VALUES ({id},{name},{url},{icon},{parentId},{parentName},{sort},{status});")  void insert(Integer id,  String name,  String url,  String icon,  Integer parentId,  String parentName,  Integer sort,  Integer status  );  @LazyUpdate("UPDATE `sys_menu` SET `name` = {name} WHERE `id` = {id};")  void updateNameById(Integer id, String name);  @LazyDelete("DELETE FROM sys_menu WHERE `id` = {id};")  void removeById(int id);  /**  * 执行sql select * from sys_menu where id={id}  * 根据ID获取数据  * @param id 数据ID  */  SysMenu findById(int id);  /**  * 执行sql select id,name,url,icon from sys_menu where id={id}  * 获取ID、名称、url、icon  * @param id 主键ID  * @return 查询信息  */  SysMenu findIdAndNameAndUrlAndIconById(int id); }

当前项目地址

测试案例地址

原文链接:https://www.oschina.net/news/292734
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章