首页 文章 精选 留言 我的

精选列表

搜索[工作],共10000篇文章
优秀的个人博客,低调大师

Sqlbean1.5.4 发布,减少 Sql 语句,让你工作更高效的工具

Sqlbean 介绍 Sqlbean是一款使用Java面向对象思想来编写并生成Sql语句的工具,在此基础上对Mybatis和Spring Jdbc实现了类似于JPA的轻量级插件支持。其中内置大量常用SQL执行的方法,可以非常方便的达到你想要的目的,相对复杂的SQL语句也得以支持,在常规的项目开发几乎做到不写DAO层,可以有效的提高项目开发的效率,让开发者更专注于业务代码的编写。 🚀特点: 零入侵, 多数据源, 动态Schema, 读写分离, 自动建表, 连表查询, 乐观锁, 分页, 支持Mybatis和Spring Jdbc 💻环境: JDK8+, Mybatis3.2.4+, (Spring MVC 4.1.2+, Spring Boot 1.x, Spring Boot 2.x) 💿数据库: Mysql, MariaDB, Oracle, Sqlserver2008+, PostgreSQL, DB2, Derby, Sqlite, HSQL, H2 Sqlbean For Android请移步这里👉gitee,github 简单上手 1.引入Maven依赖 <dependency> <groupId>cn.vonce</groupId> <artifactId>vonce-sqlbean-spring</artifactId> <version>1.5.4</version> </dependency> 2.标注实体类 //标识表名 @SqlTable("d_essay") public class Essay { @SqlId(type = IdType.SNOWFLAKE_ID_16) private Long id; private String userId; private String content; private Date creationTime; @SqlVersion private Date updateTime; /**省略get set方法*/ } 3.无需Dao层,Service层接口只需继承SqlBeanService<实体类, ID> public interface EssayService extends SqlBeanService<Essay, Long> { //已内置大量常用查询、更新、删除、插入方法,这里可以写自己封装的方法 } 4.Service实现类只需继承MybatisSqlBeanServiceImpl<实体类, ID>和实现你的Service接口 //使用Spring Jdbc的话将继承的父类改成SpringJdbcSqlBeanServiceImpl即可 @Service public class EssayServiceImpl extends MybatisSqlBeanServiceImpl<Essay, Long> implements EssayService { } 5.Controller层 @RequestMapping("essay") @RestController public class EssayController { @Autowired private EssayService essayService; //查询 @GetMapping("select") public RS select() { //查询列表 List<Essay> list = essayService.selectAll(); list = essayService.selectByCondition(Wrapper.where(gt(Essay$.id, 10)).and(lt(Essay$.id, 20))); //查询一条 Essay essay = essayService.selectById(1L); essay = essayService.selectOneByCondition(Wrapper.where(eq(Essay$.id, 333))); //复杂查询 Select select = new Select(); select.column(Essay$.id).column(Essay$.content); select.where().gt("id", 1).and().eq("content", "222"); select.orderBy("id", SqlSort.DESC); list = essayService.select(select); //用于查询Map Map<String, Object> map = essayService.selectMap(select); List<Map<String, Object>> mapList = essayService.selectMapList(select); return super.successHint("获取成功", list); } //分页 @GetMapping("getList") public Map getList(HttpServletRequest request) { // 查询对象 Select select = new Select(); ReqPageHelper<Essay> pageHelper = new ReqPageHelper<>(request); pageHelper.paging(select, essayService); return pageHelper.toResult("获取列表成功"); } //更新 @PostMapping("update") public RS update(Essay essay) { //根据bean内部id更新 long i = essayService.updateByBeanId(essay); if (i > 0) { return super.successHint("更新成功"); } return super.othersHint("更新失败"); } //删除 @PostMapping("deleteById") public RS deleteById(Integer[] id) { //根据id删除 long i = essayService.deleteById(id); //根据条件删除 //i = essayService.deleteByCondition(Wrapper.where(gt(Essay$.id, 1)).and(eq(Essay$.content, "222"))); if (i > 0) { return super.successHint("删除成功"); } return super.othersHint("删除失败"); } //插入 @PostMapping("add") public RS add() { List<Essay> essayList = new ArrayList<>(); for (int i = 0; i < 100; i++) { Essay essay = new Essay(i, "name" + i); essayList.add(essay); } essayService.insert(essayList); return successHint("成功"); } } 本次更新内容 1:修复逻辑删除时,字段类型为Integer; 2:修复映射时父类字段的问题; 3:修复连表时父类字段生成问题; 4:修复实体类父类字段没有正确将驼峰转下划线的问题; 5:增加is null, is not null条件;

优秀的个人博客,低调大师

oozie自定义action,以操作mysql为例(工作回忆录)

2 --> 目录 创建java项目 添加依赖 自定义action 定义schema 项目打包 oozie-site.xml添加配置 job.properties workflow.xml 测试 本文以oozie-5.2.0.tar.gz为例。 创建java项目 使用IDEA开发工具创建一个java项目,目录结构如图: 添加依赖 jdom-1.1.jar oozie-client-5.2.0.jar oozie-core-5.2.0.jar 这三个包在oozie安装目录的lib目录下。 自定义action 代码如下: package com.leboop.www; import org.apache.oozie.action.ActionExecutor; import org.apache.oozie.action.ActionExecutorException; import org.apache.oozie.client.WorkflowAction; import org.apache.oozie.util.XmlUtils; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.Namespace; import java.io.PrintWriter; import java.sql.*; import java.util.HashSet; import java.util.Set; /** * Created by leboop on 2020/6/21. */ public class SyncMysqlActionExecutor extends ActionExecutor { // 自定义节点类型 private static final String ACTION_TYPE = "sync-mysql"; // 自定义节点命名空间 private static final String NAMESPACE = "uri:oozie:sync-mysql-action:0.1"; // 自定义节点的元素 private static final String JDBC_URL = "jdbc-url"; private static final String SQL = "sql"; private static final String SQL_OUTPUT_FILE_PATH = "sql-output-file-path"; // mysql驱动 private static final String DRIVER = "com.mysql.jdbc.Driver"; private static Set<String> COMPLETED_STATUS = new HashSet<String>(); // 无参构造 public SyncMysqlActionExecutor() { super(ACTION_TYPE); } // 静态块 static { COMPLETED_STATUS.add("SUCCEEDED"); COMPLETED_STATUS.add("KILLED"); COMPLETED_STATUS.add("FAILED"); COMPLETED_STATUS.add("FAILED_KILLED"); } @Override public void initActionType() { super.initActionType(); } public void start(Context context, WorkflowAction workflowAction) throws ActionExecutorException { Element actionXml = null; try { actionXml = XmlUtils.parseXml(workflowAction.getConf()); Namespace ns = Namespace.getNamespace(NAMESPACE); String jdbcUrl = actionXml.getChildTextTrim(JDBC_URL, ns); String sql = actionXml.getChildTextTrim(SQL, ns); String sqlOutputFilePath = actionXml.getChildTextTrim(SQL_OUTPUT_FILE_PATH, ns); runMysql(jdbcUrl, sql, sqlOutputFilePath); context.setExecutionData("OK", null); } catch (JDOMException e) { e.printStackTrace(); } } public void end(Context context, WorkflowAction workflowAction) throws ActionExecutorException { if (workflowAction.getExternalStatus().equals("OK")) { context.setEndData(WorkflowAction.Status.OK, WorkflowAction.Status.OK.toString()); } else { context.setEndData(WorkflowAction.Status.ERROR, WorkflowAction.Status.ERROR.toString()); } } public void check(Context context, WorkflowAction workflowAction) throws ActionExecutorException { throw new UnsupportedOperationException(); } public void kill(Context context, WorkflowAction workflowAction) throws ActionExecutorException { context.setEndData(WorkflowAction.Status.KILLED, "ERROR"); } public boolean isCompleted(String s) { return COMPLETED_STATUS.contains(s); } private void runMysql(String jdbcUrl, String sql, String sqlOutputFilePath) throws ActionExecutorException { Connection connect = null; Statement statement = null; ResultSet resultSet = null; try { Class.forName(DRIVER); connect = DriverManager.getConnection(jdbcUrl); statement = connect.createStatement(); resultSet = statement.executeQuery(sql); writeResultSet(resultSet, sqlOutputFilePath); } catch (Exception e) { throw convertException(e); } finally { try { if (resultSet != null) resultSet.close(); if (statement != null) statement.close(); if (connect != null) connect.close(); } catch (Exception e) { throw convertException(e); } } } private void writeResultSet(ResultSet resultSet, String sqlOutPutFilePath) throws Exception { PrintWriter out; if (sqlOutPutFilePath != null && sqlOutPutFilePath.length() > 0) { out = new PrintWriter(sqlOutPutFilePath); } else { out = new PrintWriter(System.out); } ResultSetMetaData metaData = resultSet.getMetaData(); while (resultSet.next()) { for (int i = 1; i <= metaData.getColumnCount(); i++) { out.println(metaData.getColumnName(i) + "=" + resultSet.getString(i)); } } out.close(); } } 定义schema sync_mysql-0.1.xsd如下: <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sync-mysql="uri:oozie:sync-mysql-action:0.1" elementFormDefault="qualified" targetNamespace="uri:oozie:sync-mysql-action:0.1"> <xs:element name="sync-mysql" type="sync-mysql:sync_mysql_type"/> <xs:complexType name="sync_mysql_type"> <xs:sequence> <xs:element name="jdbc-url" type="xs:string" minOccurs="1" maxOccurs="1"/> <xs:element name="sql" type="xs:string" minOccurs="1" maxOccurs="1"/> <xs:element name="sql-output-file-path" type="xs:string" minOccurs="0" maxOccurs="1"/> </xs:sequence> </xs:complexType> </xs:schema> 项目打包 打瘦包即可,如图: 将包拷贝到oozie安装目录lib下。 oozie-site.xml添加配置 内容如下: <property> <name>oozie.service.ActionService.executor.ext.classes</name> <value>com.leboop.www.SyncMysqlActionExecutor</value> </property> <property> <name>oozie.service.SchemaService.wf.ext.schemas</name> <value>sync_mysql-0.1.xsd</value> </property> 重启oozie server。 job.properties nameNode=hdfs://single:9000 jobTracker=single:8032 queueName=default examplesRoot=jobs oozie.use.system.libpath=true oozie.wf.application.path=${nameNode}/user/root/${examplesRoot}/sync-mysql jdbcURL=jdbc:mysql://192.168.128.1:3306/oozie?user=root&password=root sql=select * from oozie_sys; SQL_OUTPUT_PATH=/out/result.txt 需要在Linux上创建/out/result.txt文件。 workflow.xml <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <workflow-app xmlns="uri:oozie:workflow:0.5" name="sync-mysql-wf"> <start to="sync-mysql-node"/> <action name="sync-mysql-node"> <sync-mysql xmlns="uri:oozie:sync-mysql-action:0.1"> <jdbc-url>${jdbcURL}</jdbc-url> <sql>${sql}</sql> <sql-output-file-path>${SQL_OUTPUT_PATH}</sql-output-file-path> </sync-mysql> <ok to="end"/> <error to="fail"/> </action> <kill name="fail"> <message>syncMysql failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <end name="end"/> </workflow-app> 需要将workflow.xml拷贝到job.properties配置的oozie.wf.application.path路径下。 测试 oozie job -config job.properties -run 如图: 查看日志: oozie job -info 0000004-200621162902099-oozie-root-W 如图: 最后会将查询oozie数据库中oozie_sys表的内容: 输出到/out/result.txt文件中,内容如下: name=db.version data=4 name=oozie.version data=5.2.0

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码