Mybatis 执行后 参数 未拼接到 SQL语句中

/ 默认分类 / 没有评论 / 173浏览

每次生产有问题,看日志拿到sql,如果参数太多,把参数拼接到sql中费很长时间,于是写了一个小工具!

-----------------来自小马哥的故事

直接上代码


package com.mantis.hc.sale.service.pay.util;


import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.*;

public class sqlTools extends JFrame implements ActionListener {




    private JPanel jp=new JPanel();

    private JLabel[] jlArray={new JLabel("SQL"),

            new JLabel("字段值"),new JLabel("结果"),new JLabel("") };

    private JButton[] jbArray={new JButton("执行"),

            new JButton("清空")};

    private JTextField jtxtSql =new JTextField();

    private JTextField JTextValue= new JTextField();


    private JTextArea resultSQL= new JTextArea();

    public sqlTools(){
        jp.setLayout(null);

        for(int i=0;i<2;i++){

            jlArray[i].setBounds(30, 20+i*50, 80, 26);

            jbArray[i].setBounds(120+i*110, 660, 80,26);

            jp.add(jlArray[i]);

            jp.add(jbArray[i]);

            jbArray[i].addActionListener(this);

        }


        for(int i=2;i<3;i++){

            jlArray[i].setBounds(30, 20+i*50, 80, 26);

            jp.add(jlArray[i]);
        }
        jtxtSql.setBounds(80,20,500,30);
        jp.add(jtxtSql);
        jtxtSql.addActionListener(this);
        JTextValue.setBounds(80,70,500,30);
        jp.add(JTextValue);
        JTextValue.addActionListener(this);
        resultSQL.setBounds(80,120,500,500);
        resultSQL.setLineWrap(true);
        jp.add(resultSQL);
        jlArray[3].setBounds(10, 250, 700, 30);
        jp.add(jlArray[3]);
        this.add(jp);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("小马哥工具");
        this.setResizable(false);
        this.setBounds(100, 230, 700, 800);
        this.setVisible(true);

    }


    public void actionPerformed(ActionEvent e){



        if(jtxtSql.getText().equals("")&&String.valueOf(JTextValue.getText()).equals("")){

            resultSQL.setText("参数不能为空!,请重新参数!");

        }else{

            try{
                String resultStr =  getResultSQL(jtxtSql.getText(),JTextValue.getText());
                resultSQL.setText(resultStr);
            }catch (Exception a){
                System.out.println(a.getMessage());
                resultSQL.setText("参数错误,请检查参数!");
            }

        }

    }

    //主函数入口
    public static void main(String[] args) {

        new sqlTools();

    }








    public static  String getResultSQL(String  text,String  str) {

        Pattern pattern = Pattern.compile("\\?");
        StringBuffer buffer = new StringBuffer();

        //参数转换成数组
        String[] words = ClearBracket(str).split(",");
        for (int i = 0; i < words.length; i++) {

            Matcher matcher = pattern.matcher(text);
            while (matcher.find()) {
                //?号 替换成数据中对应的数据
                matcher.appendReplacement(buffer, "'"+words[i++].trim()+"'");
            }
            matcher.appendTail(buffer);
        }

        return buffer.toString();


    }




    //删除括号及括号中的数据
    private static String ClearBracket(String context) {
        String pattern = "\\([^)]*\\)";
        context = context.replaceAll(pattern, "");
        return context;
    }









}

生成class 文件

javac ResSql.java

打包成jar

jar cvf sqlTools.jar ResSql.class

修改 MANIFEST.MF 文件


Manifest-Version: 1.0
Created-By: 1.8.0_131 (Oracle Corporation)
Main-Class: ResSql

打包压缩 ZIP 修改后缀 JAR

编写Bat文件


@echo off

SET javaw="%JAVA_HOME%\bin\javaw"

start javaw -jar "sqlTools.jar" 

exit