IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> JdbcTemplate的增删改查用法 -> 正文阅读

[JavaScript知识库]JdbcTemplate的增删改查用法

JdbcTemplate的增删改查用法

vue前端调用方法

async init() {
      var that = this;
      //
      that.tableData = [];
      that.page.total = 0;
      //
      var params = {};
      params["pageIndex"] = that.page.currentPage;
      params["pageSize"] = that.page.pageSize;
      //
      var t_url = config.business.url + "/api/calendarCustom/calendarListPage";
      api.ajax(t_url, "post", params, null, false).then((r) => {
        if (r.success) {
          that.tableData = r.data.rows;
          that.page.total = r.data.total;
        } else {
          that.$message(r.msg);
        }
      });
    },
rowDel(row, index) {
      //删除 form值
      var that = this;
      //
      api.confirm(
        "删除【" + row.name_ + "】的记录, 是否继续?",
        function () {
          //
          var params = {};
          params["calendar_id"] = row.id_;
          //
          var t_url = config.business.url + "/api/calendarCustom/delete";
          api.ajax(t_url, "post", params, null, false).then((r) => {
            if (r.success) {
              that.$message(r.msg);
              that.init();
            } else {
              that.$message(r.msg);
            }
          });
        },
        null
      );
    },
//保存功能
    save(callback) {
      var that = this;
      //
      if (!that.form.desc_ || that.form.desc_.length <= 0) {
        that.$message("desc_不能为空");
        return;
      }
      if (!that.form.name_ || that.form.name_.length <= 0) {
        that.$message("name_不能为空");
        return;
      }
      if (!that.form.type_ || that.form.type_.length <= 0) {
        that.$message("type_不能为空");
        return;
      }
      //
      //保存
      if (that.form.id_ <= 0) {
        var t_url = config.business.url + "/api/calendarCustom/insert";
        api.ajax_body(t_url, "post", that.form).then((r) => {
          if (r.success) {
            that.init();
            that.$message(r.data);
            if (callback) {
              callback();
            }
          } else {
            that.$message(r.data);
          }
        });
      } else {
        var t_url = config.business.url + "/api/calendarCustom/update";
        api.ajax_body(t_url, "post", that.form).then((r) => {
          if (r.success) {
            that.init();
            that.$message(r.data);
            if (callback) {
              callback();
            }
          } else {
            that.$message(r.data);
          }
        });
      }
      //
    },

java后端写法

/**
 * 对外提供的访问接口  基础rest api控制器   jdbcTemplate
 * vp:hsg
 * create date:2022-02
 */
@RestController
public class jdbcTemplateController {
    protected final Logger logger = LoggerFactory.getLogger(tasksController.class);

    @Autowired
    protected JdbcTemplate jdbcTemplate;

}
package com.puri.pg.rest.flow;

import com.puri.pg.common.data.dbUtil;
import com.puri.pg.common.data.dbfield;
import com.puri.pg.common.utils.JsonResult;
import com.puri.pg.lib.libBase;
import com.puri.pg.rest.flow.object.*;
import com.puri.pg.rest.jdbcTemplateController;
import com.puri.pg.rest.restController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(value = "calendarCustom", tags = {"工作日配置服务"}, description = "工作日配置服务")
@CrossOrigin
@RestController
@RequestMapping("/api/calendarCustom")
public class calendarCustomController extends jdbcTemplateController {
    @ApiOperation(value = "添加工作日", notes = "添加工作日")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody uflo_calendar obj) {
        JsonResult rbc = new JsonResult();
        try {
            if (obj.name_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("名称不能为空");
                return rbc;
            }
            if (obj.type_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("类型不能为空");
                return rbc;
            }
            if (obj.desc_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("描述不能为空");
                return rbc;
            }
            //
            obj.id_ = libBase.getMax_1(this.jdbcTemplate, "uflo_calendar", "id_");
            //
            int r = libBase.insert(this.jdbcTemplate, "uflo_calendar", obj.getInsertfields());
            if (r >= 0) {
                rbc = libBase.JsonResultOKData((Object) "保存成功");
            }
        } catch (Exception ex) {
            rbc = JsonResult.error(ex.getMessage());
        } finally {
        }
        return rbc;
    }

    @ApiOperation(value = "编辑工作日", notes = "编辑工作日")
    @PostMapping("/update")
    public JsonResult update(@RequestBody uflo_calendar obj) {
        JsonResult rbc = new JsonResult();
        try {
            if (obj.id_ <= 0) {
                rbc = libBase.JsonResultErrorData("编号不能为空");
                return rbc;
            }
            if (obj.name_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("名称不能为空");
                return rbc;
            }
            if (obj.type_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("类型不能为空");
                return rbc;
            }
            if (obj.desc_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("描述不能为空");
                return rbc;
            }
            //
            List<dbfield> fdList = obj.getInsertfields();
            int r = libBase.update(this.jdbcTemplate, "uflo_calendar", fdList, fdList.size() - 1);
            if (r >= 0) {
                rbc = libBase.JsonResultOKData((Object) "保存成功");
            }
        } catch (Exception ex) {
            rbc = JsonResult.error(ex.getMessage());
        } finally {
        }
        return rbc;
    }

    @ApiOperation(value = "删除工作日", notes = "删除工作日")
    @PostMapping("/delete")
    public JsonResult delete(String calendar_id) {
        String sql = "";
        sql = "delete  from uflo_calendar_date where calendar_id_=" + calendar_id;
        libBase.update(this.jdbcTemplate, sql);

        sql = "delete  from uflo_calendar where id_=" + calendar_id;
        libBase.update(this.jdbcTemplate, sql);

        return libBase.JsonResultOKData("删除完毕");
    }

    //======
    @ApiOperation(value = "添加工作日中日期", notes = "添加工作日中日期")
    @PostMapping("/insert_date")
    public JsonResult insert_date(@RequestBody uflo_calendar_date obj) {
        JsonResult rbc = new JsonResult();
        try {
            if (obj.name_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("名称不能为空");
                return rbc;
            }
            if (obj.calendar_id_ <= 0) {
                rbc = libBase.JsonResultErrorData("父编号不能为空");
                return rbc;
            }
            if (obj.calendar_date_ == null) {
                rbc = libBase.JsonResultErrorData("日期设置不能为空");
                return rbc;
            }
            //
            obj.id_ = libBase.getMax_1(this.jdbcTemplate, "uflo_calendar_date", "id_");
            //
            int r = libBase.insert(this.jdbcTemplate, "uflo_calendar_date", obj.getInsertfields());
            if (r >= 0) {
                rbc = libBase.JsonResultOKData((Object) "保存成功");
            }
        } catch (Exception ex) {
            rbc = JsonResult.error(ex.getMessage());
        } finally {
        }
        return rbc;
    }

    @ApiOperation(value = "修改工作日中日期", notes = "修改工作日中日期")
    @PostMapping("/update_date")
    public JsonResult update_date(@RequestBody uflo_calendar_date obj) {
        JsonResult rbc = new JsonResult();
        try {
            if (obj.id_ <= 0) {
                rbc = libBase.JsonResultErrorData("编号不能为空");
                return rbc;
            }
            if (obj.name_.isEmpty()) {
                rbc = libBase.JsonResultErrorData("名称不能为空");
                return rbc;
            }
            if (obj.calendar_id_ <= 0) {
                rbc = libBase.JsonResultErrorData("父编号不能为空");
                return rbc;
            }
            if (obj.calendar_date_ == null) {
                rbc = libBase.JsonResultErrorData("日期设置不能为空");
                return rbc;
            }
            //
            List<dbfield> dbList=obj.getInsertfields();
            int r = libBase.update(this.jdbcTemplate, "uflo_calendar_date", dbList,dbList.size()-1);
            if (r >= 0) {
                rbc = libBase.JsonResultOKData((Object) "保存成功");
            }
        } catch (Exception ex) {
            rbc = JsonResult.error(ex.getMessage());
        } finally {
        }
        return rbc;
    }

    @ApiOperation(value = "删除工作日中日期", notes = "删除工作日中日期")
    @PostMapping("/delete_date")
    public JsonResult delete_date(String date_id) {
        String sql = "";
        sql = "delete  from uflo_calendar_date where id_=" + date_id;
        libBase.update(this.jdbcTemplate, sql);
        //
        return libBase.JsonResultOKData("删除完毕");
    }
    //======
    @ApiOperation(value = "获取所有日程表", notes = "获取所有日程表")
    @PostMapping("/calendarListPage")
    public JsonResult calendarListPage(Integer pageIndex, Integer pageSize) {
        try {
            String sql = "select * from uflo_calendar order by id_ desc";
            return libBase.JsonResultOKData(libBase.getDataTablePage(this.jdbcTemplate, sql, pageIndex, pageSize));
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            return libBase.JsonResultErrorData(ex.getMessage());
        }
    }

    @ApiOperation(value = "获取一个日程表中日期设置列表", notes = "获取一个日程表中日期设置列表")
    @PostMapping("/calendarDateListPage")
    public JsonResult calendarDateListPage(String calendar_id, Integer pageIndex, Integer pageSize) {
        try {
            String sql = "select * from uflo_calendar_date ";
            sql += " where calendar_id_=" + calendar_id + " ";
            sql += " order by id_ desc";
            return libBase.JsonResultOKData(libBase.getDataTablePage(this.jdbcTemplate, sql, pageIndex, pageSize));
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            return libBase.JsonResultErrorData(ex.getMessage());
        }
    }

}

libBase封装库

package com.puri.pg.lib;

import com.puri.pg.common.data.dbUtil;
import com.puri.pg.common.data.dbfield;
import com.puri.pg.common.data.dbfieldtype;
import com.puri.pg.common.utils.DateUtils;
import com.puri.pg.common.utils.JsonResult;
import com.puri.pg.rest.jdbcTemplateController;
import com.puri.pg.rest.zjd.uflow.tasksController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;

//基础库 (基础功能库)
//create date:2022-02
//vp:hsg
public class libBase {
    public static final Logger logger = LoggerFactory.getLogger(libBase.class);
    public static int FastLimitCount = 1000;
    protected static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

    public static JsonResult JsonResultOKData(Object data)
    {
        JsonResult r=JsonResult.isOK(true);
        r.put("data",data);
        r.put("msg","操作成功");
        return r;
    }
    public static JsonResult JsonResultErrorData(Object data)
    {
        JsonResult r=JsonResult.isOK(false);
        r.put("data",data);
        return r;
    }

    public static int save(JdbcTemplate jdbcTemplate,String sql)
    {
        return jdbcTemplate.update(sql);
    }
    public static int update(JdbcTemplate jdbcTemplate,String sql)
    {
        return jdbcTemplate.update(sql);
    }
    public static int update(JdbcTemplate jdbcTemplate,String sql,Object[] args)
    {
        return jdbcTemplate.update(sql,args);
    }
    public static int[] updateBatch(JdbcTemplate jdbcTemplate,String sql, List<Object[]> rowList)
    {
        return jdbcTemplate.batchUpdate(sql,rowList);
    }
    //------
    public static int insert(JdbcTemplate jdbcTemplate,String tableName,List<dbfield> fields)
    {
        StringBuilder sb_fds=new StringBuilder();
        StringBuilder sb_values=new StringBuilder();
        List<Object> objList=new ArrayList();
        dbfield fd=null;
        for(int i=0;i<fields.size();i++)
        {
            fd=fields.get(i);
            if(sb_fds.length()>0)
            {
                sb_fds.append(","+fd.name);
                if (fd.type == dbfieldtype.geometry) {
                    sb_values.append(",st_multi(ST_GeomFromText(?," + fd.defaultValue + "))");
                }
                else {
                    sb_values.append(",?");
                }
            }
            else
            {
                sb_fds.append(fd.name);
                if (fd.type == dbfieldtype.geometry) {
                    sb_values.append("st_multi(ST_GeomFromText(?," + fd.defaultValue + "))");
                }
                else {
                    sb_values.append("?");
                }
            }
            //插入的值列表
            if (fd.type == dbfieldtype.Int) {
                objList.add(toInt(fd.value));
            } else if (fd.type == dbfieldtype.decimal) {
                objList.add(toDouble(fd.value));
            } else if (fd.type == dbfieldtype.date) {
                objList.add(toDate(fd.value));
            } else if (fd.type == dbfieldtype.datetime) {
                objList.add(toTimestamp(fd.value));
            } else if (fd.type == dbfieldtype.time) {
                objList.add(toTime(fd.value));
            } else if (fd.type == dbfieldtype.bool) {
                objList.add(toBoolean(fd.value));
            } else if (fd.type == dbfieldtype.geometry) {
                objList.add(fd.value);
            } else {
                objList.add(fd.value);
            }
            //
        }
        String sql = "insert into "+tableName+"("+sb_fds.toString()+") values("+sb_values.toString()+")";
        return update(jdbcTemplate,sql,objList.toArray());
    }
    //
    public static int update(JdbcTemplate jdbcTemplate,String tableName,List<dbfield> fields,int whereStart)
      throws Exception
    {
        dbfield fd=null;
        if (fields != null && fields.size() > 0) {
            String fdStr = "";
            String VStr = "";
            for (int i = 0; i < whereStart; ++i) {
                fd = (dbfield) fields.get(i);
                if (fdStr.length() <= 0) {
                    fdStr = fd.name + "=?";
                } else {
                    fdStr = fdStr + "," + fd.name + "=?";
                }
            }

            String whereStr = "";
            String t_Str;
            if (whereStart > 0 && whereStart < fields.size()) {
                t_Str = "";

                for (int j = whereStart; j < fields.size(); ++j) {
                    fd = (dbfield) fields.get(j);
                    if (t_Str.length() <= 0) {
                        t_Str = fd.name + "=?";
                    } else {
                        t_Str = t_Str + " and " + fd.name + "=?";
                    }
                }

                whereStr = " where " + t_Str;
            }

            String sql = "update " + tableName + " set " + fdStr + " " + whereStr;

            List<Object> objList=new ArrayList();
            for(int i=0;i<fields.size();i++)
            {
                fd=fields.get(i);

                //插入的值列表
                if (fd.type == dbfieldtype.Int) {
                    objList.add(toInt(fd.value));
                } else if (fd.type == dbfieldtype.decimal) {
                    objList.add(toDouble(fd.value));
                } else if (fd.type == dbfieldtype.date) {
                    objList.add(toDate(fd.value));
                } else if (fd.type == dbfieldtype.datetime) {
                    objList.add(toTimestamp(fd.value));
                } else if (fd.type == dbfieldtype.time) {
                    objList.add(toTime(fd.value));
                } else if (fd.type == dbfieldtype.bool) {
                    objList.add(toBoolean(fd.value));
                } else if (fd.type == dbfieldtype.geometry) {
                    objList.add(fd.value);
                } else {
                    objList.add(fd.value);
                }
                //
            }
            return update(jdbcTemplate,sql,objList.toArray());
        }
        else {
            throw new Exception("参数空异常");
        }
    }
    //------
    //获取sql语句的表数据
    public static List<Map<String, Object>> getDataTable(JdbcTemplate jdbcTemplate,String sql)
    {
        return (List<Map<String, Object>>)jdbcTemplate.queryForList(sql);
    }
    public static pageUtils getDataTablePage(JdbcTemplate jdbcTemplate, String sql, Integer pageIndex, Integer pageSize)
            throws Exception
    {
        long total=libBase.getRowCount(jdbcTemplate,sql);
        String pageSQL=libBase.getPageSQL(sql,pageIndex,pageSize);
        List<Map<String,Object>> mapList=libBase.getDataTable(jdbcTemplate,pageSQL);
        return new pageUtils(mapList,total);
    }

    public static String queryForString(JdbcTemplate jdbcTemplate,String sql)
    {
        return (String)jdbcTemplate.queryForObject(sql,String.class);
    }
    public static Long queryForLong(JdbcTemplate jdbcTemplate,String sql)
    {
        return (Long)jdbcTemplate.queryForObject(sql,Long.class);
    }
    public static Integer queryForInt(JdbcTemplate jdbcTemplate,String sql)
    {
        return (Integer)jdbcTemplate.queryForObject(sql,Integer.class);
    }
    public static Date queryForDate(JdbcTemplate jdbcTemplate,String sql)
    {
        return (Date)jdbcTemplate.queryForObject(sql,Date.class);
    }
    public static Timestamp queryForTimestamp(JdbcTemplate jdbcTemplate,String sql)
    {
        return (Timestamp)jdbcTemplate.queryForObject(sql, Timestamp.class);
    }

    public static Boolean queryForBoolean(JdbcTemplate jdbcTemplate,String sql)
    {
        return (Boolean)jdbcTemplate.queryForObject(sql,Boolean.class);
    }
    public static List<String> queryForList(JdbcTemplate jdbcTemplate,String sql)
    {
        return jdbcTemplate.queryForList(sql,String.class);
    }
    //----
    public static int getMax_1(JdbcTemplate jdbcTemplate,String table,String id)
            throws  Exception
    {
        Integer v=1;
        String sql="select max("+id+")+1 as max_1 from "+table;
        v=libBase.queryForInt(jdbcTemplate,sql);
        if(v==null || v==0)
        {
            v=1;
        }
        return v;
    }
    public static int getMax_1(JdbcTemplate jdbcTemplate,String table,String id,String whereStr)
            throws  Exception
    {
        Integer v=1;
        String sql="select max("+id+")+1 as max_1 from "+table+" "+whereStr;
        v=libBase.queryForInt(jdbcTemplate,sql);
        if(v==null || v==0)
        {
            v=1;
        }
        return v;
    }

    public static Integer getMax_1_dm(JdbcTemplate jdbcTemplate,String tablename,String dmfdmc,String preDM)
            throws Exception
    {
        Integer xh=1;
        try
        {
            lock.writeLock().lock();
            //
            String sql = "select count("+dmfdmc+") row_count  from ";
            sql+=" (select "+dmfdmc+" from "+tablename+" where "+dmfdmc+" like '" + preDM + "%' order by "+dmfdmc+" desc) as t";
            Integer rowCount = libBase.queryForInt(jdbcTemplate,sql);
            if(rowCount>0) {
                sql="select  "+dmfdmc+"  from  ";
                sql+=" ( select  "+dmfdmc+" from "+tablename+" where "+dmfdmc+" like '"+preDM+"%' order by "+dmfdmc+" desc)  as t  limit 1 ";
                String dm_max=libBase.queryForString(jdbcTemplate,sql);
                String t_max_xh=dm_max.replace(preDM,"");
                Integer max_xh=Integer.parseInt(t_max_xh);
                max_xh+=1;    //取最大值加一
                xh=max_xh;
            }
        } finally {
            lock.writeLock().unlock();
        }
        return xh;
    }
    //=======================================
    public static String  getPageSQL(String sql, Integer pageIndex, Integer pageSize)  {
        int offset = (pageIndex - 1) * pageSize;
        return  sql + " limit  " + pageSize + "  OFFSET  " + offset + " ";    //postgresql库
    }
    public static Long  getRowCountRight(JdbcTemplate jdbcTemplate,String sql) throws Exception {
        String t_sql = "select count(*) as cwgis_rowcount from (" + sql + ") as t";
        return libBase.queryForLong(jdbcTemplate,t_sql);
    }
    public static long getRowCountFast(JdbcTemplate jdbcTemplate,String sql) throws Exception {
        long total = 0;
        //"QUERY PLAN"
        List<String> valList = libBase.queryForList(jdbcTemplate," EXPLAIN " + sql);   //只能单例=queryForList
        if (valList.size() > 0) {
            String firstRow = (String)valList.get(0);
            if (firstRow.indexOf("rows=") > 0) {
                total = Long.valueOf(firstRow.substring(firstRow.indexOf("rows=") + 5, firstRow.indexOf("width=")).trim());
            }
        }
        return total;
    }

    public static long getRowCount(JdbcTemplate jdbcTemplate,String sql) throws Exception {
        long total = libBase.getRowCountFast(jdbcTemplate,sql);
        if (total <= libBase.FastLimitCount) {
            total = libBase.getRowCountRight(jdbcTemplate,sql);
        }
        return total;
    }
    //-----
    public static boolean toBoolean(Object v) {
        boolean defaultValue = false;
        if (v != null) {
            try {
                defaultValue = Boolean.parseBoolean(v.toString());
            } catch (Exception var7) {
                ;
            } finally {
                ;
            }

            String var3 = v.toString().toUpperCase();
            byte var4 = -1;
            switch(var3.hashCode()) {
                case 49:
                    if (var3.equals("1")) {
                        var4 = 0;
                    }
                    break;
                case 84:
                    if (var3.equals("T")) {
                        var4 = 3;
                    }
                    break;
                case 89:
                    if (var3.equals("Y")) {
                        var4 = 1;
                    }
                    break;
                case 87751:
                    if (var3.equals("YES")) {
                        var4 = 2;
                    }
                    break;
                case 2583950:
                    if (var3.equals("TRUE")) {
                        var4 = 4;
                    }
            }

            switch(var4) {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                    defaultValue = true;
                    break;
                default:
                    defaultValue = false;
            }
        }

        return defaultValue;
    }

    public static Double toDouble(Object v) {
        Double defaultValue = 0.0D;
        if (v != null) {
            try {
                defaultValue = Double.parseDouble(v.toString());
            } catch (Exception var7) {
                ;
            } finally {
                ;
            }
        }

        return defaultValue;
    }

    public static Integer toInt(Object v) {
        Integer defaultValue = 0;
        if (v != null) {
            try {
                defaultValue = Integer.parseInt(v.toString());
            } catch (Exception var7) {
                ;
            } finally {
                ;
            }
        }

        return defaultValue;
    }

    public static Float toFloat(Object v) {
        float defaultValue = 0.0F;
        if (v != null) {
            try {
                defaultValue = Float.parseFloat(v.toString());
            } catch (Exception var7) {
                ;
            } finally {
                ;
            }
        }

        return defaultValue;
    }

    public static Date toDate(Object v) {
        Date t_date = null;

        try {
            if (v != null) {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                java.util.Date mydate2 = df.parse(v.toString());
                t_date = new Date(mydate2.getTime());
            }
        } catch (Exception var5) {
            t_date = null;
        }

        return t_date;
    }

    public static Date toDateTime(Object v) {
        Date t_date = null;

        try {
            if (v != null) {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                java.util.Date mydate2 = df.parse(v.toString());
                t_date = new Date(mydate2.getTime());
            }
        } catch (Exception var5) {
            t_date = null;
        }

        return t_date;
    }

    public static Timestamp toTimestamp(Object v) {
        Timestamp t_Timestamp = null;

        try {
            if (v != null) {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                java.util.Date mydate2 = df.parse(v.toString());
                t_Timestamp = new Timestamp(mydate2.getTime());
            }
        } catch (Exception var5) {
            t_Timestamp = null;
        }

        return t_Timestamp;
    }

    public static Time toTime(Object v) {
        Time t_Time = null;

        try {
            if (v != null) {
                DateFormat df = new SimpleDateFormat("HH:mm:ss");
                java.util.Date mydate2 = df.parse(v.toString());
                t_Time = new Time(mydate2.getTime());
            }
        } catch (Exception var5) {
            t_Time = null;
        }

        return t_Time;
    }
    //=======================================
    //
    public static String getNewGuid()
    {
        return  com.puri.pg.common.utils.UUIDUtil.getUUIDExcludeLine();
    }
    //公共函数2
    public static String getParam(String key, Map params)
    {
        Object tObj=params.get(key);
        if(tObj!=null) {
            return tObj.toString();
        }
        return "";
    }
    public static boolean getParamBool(String key,Map params)
    {
        String tStr=getParam(key,params);
        if(tStr=="") tStr="false";
        return Boolean.parseBoolean(tStr);
    }
    public static int getParamInt(String key,Map params){
        String tStr=getParam(key,params);
        if(tStr=="") tStr="0";
        return Integer.parseInt(tStr);
    }
    public static Long getParamLong(String key,Map params){
        String tStr=getParam(key,params);
        if(tStr=="") tStr="0";
        return Long.parseLong(tStr);
    }
    public static double getParamDouble(String key,Map params)
    {
        String tStr=getParam(key,params);
        if(tStr=="") tStr="0";
        return Double.parseDouble(tStr);
    }
    public static java.util.Date getParamDate(String key,Map params)
    {
        String tStr=getParam(key,params);
        if(tStr=="") return getNowDate();
        return DateUtils.dateTime("yyyy-MM-dd",tStr);
    }
    public static java.util.Date getParamDatetime(String key,Map params)
    {
        String tStr=getParam(key,params);
        if(tStr=="") return getNowDate();
        return DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",tStr);
    }
    public static java.util.Date getParamDatetimeNull(String key,Map params)
    {
        String tStr=getParam(key,params);
        if(tStr=="") return null;
        return DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",tStr);
    }
    public static java.sql.Date getNowDate()
    {
        long L=System.currentTimeMillis();
        Date pub_date=new Date(L);
        return pub_date;
    }
    public static String getNowDateFormat(String format)
    {   //"yyyy-MM-dd"
        if(format.equals("")==true)
        {
            format="yyyy-MM-dd";
        }
        long L=System.currentTimeMillis();
        java.sql.Date pub_date=new Date(L);
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(pub_date);
    }
    public static java.sql.Timestamp getNowTimeStamp()
    {
        String currentDateTime= DateUtils.getCurrentTime();
        //
        return java.sql.Timestamp.valueOf(currentDateTime);
    }
    public static BigDecimal getBigDecimalZero()
    {
        return new BigDecimal("0");
    }
    public static BigDecimal getBigDecimalValueDouble(double value)
    {
        return new BigDecimal(value);
    }
    public static int compareValueBigDecimal(BigDecimal value,double compareValue)
    {      //-1,0,1
        //-1 less than
        //0  eq
        //l larger than
        return value.compareTo(new BigDecimal(compareValue));

    }

}

pageUtils 分页结果类

package com.puri.pg.lib;

import java.io.Serializable;
import java.util.List;

public class pageUtils implements Serializable {
    private static final long serialVersionUID = 1L;
    private long total;
    private List<?> rows;

    public pageUtils(List<?> list, long total) {
        this.rows = list;
        this.total = total;
    }

    public long getTotal() {
        return this.total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<?> getRows() {
        return this.rows;
    }

    public void setRows(List<?> rows) {
        this.rows = rows;
    }
}

  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2022-03-03 16:03:16  更:2022-03-03 16:07:39 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 9:02:34-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码