Mapper快速SQL生成
来源:互联网 发布:全国驾校数据 编辑:程序博客网 时间:2024/06/05 03:57
public class SQL { private static final String COLUMS = "id,comId,createTime,createUser,num,relateNum,cardId,price,type,purchased,currency,payStatus,auditStatus,auditUser,auditTime,predictTime,payTime,payUser,remark,costType,fundType,deleted,"; private static final String TABLE_NAME = "pub_finance_pay"; private static final String CONDITION_ID = "xxxx"; public static void main(String[] args) { insert(); delete(); getById(); update(); getList(); getListCondition(); } public static void insert() { String sql = "INSERT INTO " + TABLE_NAME + " ("; String[] es = COLUMS.split(","); for (int i = 0; i < es.length; i++) { if (i < es.length -1) { sql += es[i] + ","; } else { sql += es[i] + ") "; } } sql += "VALUES ("; for (int i = 0; i < es.length; i++) { if (i < es.length -1) { sql += "#{" + es[i] + "},"; } else { sql += "#{" + es[i] + "})"; } } System.out.println(sql); } public static void delete() { System.out.println("UPDATE " + TABLE_NAME + " SET deleted=${@com.sjdf.erp.common.dictionary.bean.WhetherState@YES} WHERE comId=#{comId} AND id=#{id}"); } public static void getById() { System.out.println("SELECT * FROM " + TABLE_NAME + " WHERE comId=#{comId} AND id=#{id} AND deleted=${@com.sjdf.erp.common.dictionary.bean.WhetherState@NO}"); } public static void update() { String sql = "UPDATE " + TABLE_NAME + " SET "; String[] es = COLUMS.split(","); for (int i = 0; i < es.length; i++) { if (i < es.length -1) { sql += es[i] + "=#{" +es[i]+"}, "; } else { sql += es[i] + "=#{" +es[i]+"} "; } } sql += "WHERE id=#{id} AND comId=#{comId}"; System.out.println(sql); } public static void getListCondition() { String[] es = COLUMS.split(","); String sql = "<sql id=\"" + CONDITION_ID + "\">\n"; sql += " <where>\n"; sql += " deleted=${@com.sjdf.erp.common.dictionary.bean.WhetherState@NO}\n"; for (int i = 0; i < es.length; i++) { if (!es.equals("deleted")) { sql += String.format(" <if test=\"%s != null\">and %s = #{%s}</if>\n", es[i], es[i], es[i]); } } sql += " </where>\n"; sql += "</sql>"; System.out.println(sql); }; public static void getList() { System.out.println(String.format("SELECT * FROM %s <include refid=\"%s\"/>", TABLE_NAME, CONDITION_ID)); }}
阅读全文
0 0
- Mapper快速SQL生成
- java代码生成,mapper生成,实体类生成,快速生成java代码
- spring上使用mybatis快速生成插件快速生成xml、model、mapper
- 通用mapper生成sql及mybatis使用过程
- Excle快速生成SQL公式
- mybatis 自动生成 mapper
- Mybatis中使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件
- Mybatis mapper获取sql
- mybatis mapper.xml数据库映射生成java实体,增删改查sql语句
- SQL Server 如何快速生成随机数?
- 一条SQL快速生成大量的测试数据
- 快速生成论坛上贴子插入SQL
- 数据库表生成实体 包括注释 并生成mybatis Mapper映射 加入注释 通用SQL查询映射
- mybatis + maven 自动生成mapper
- mybatis根据数据库生成mapper
- 采用Mybatis-Generator生成mapper
- Mybatis逆向工程,生成Mapper
- SpringBoot自动生成Mapper映射
- 安装pycharm2017.2.1报NSIS error解决办法
- Struts2配置文件详解
- 集合框架(六) 实用类:包装类、String、Math、StringBuffer、Random、时间和日期处理类
- 数据结构实验:连通分量个数
- mysql:sql语句添加行号
- Mapper快速SQL生成
- Linux下使用Python的Tkinter库出现的No module named _tkinter问题
- Linux学习之路3
- 282. Expression Add Operators
- URL的组成
- 「翻译」Unity中的AssetBundle详解(一)
- ubuntu apt-get 出现NO_PUBKEY的解决方案
- 599. Minimum Index Sum of Two Lists
- 如何实现Google搜索(Windows10)