zoukankan      html  css  js  c++  java
  • 2020.11.18收获

    DaoFactory.java

    package com.jaovo.msg.Util;
        import com.jaovo.msg.dao.UserDaoImpl;
        public class DaoFactory {
             public static UserDaoImpl getDaoImpl() {
                return new UserDaoImpl();
         }
    }                                
     
    DBUtil.java
    package com.jaovo.msg.Util;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class DBUtil {
     //连接数据库
     public  static  Connection getConnection() {
      try {
       //1 加载驱动
       Class.forName("com.mysql.jdbc.Driver").newInstance();
      } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      String user = "root";
      String password = "root";
      String url = "jdbc:mysql://localhost:3306/t_user?&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
      Connection connection = null;
      try {
       //2 创建链接对象connection
        connection = DriverManager.getConnection(url,user,password);
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      return connection;
     }
     
     //关闭资源的方法
     public static void close(Connection connection ) {
      try {
       if (connection != null) {
        connection.close();
       }
       
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
     }
     public static void close(PreparedStatement preparedStatement ) {
      try {
       if (preparedStatement != null) {
        preparedStatement.close();
       }
       
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
     }
     public static void close(ResultSet resultSet ) {
      try {
       if (resultSet != null) {
        resultSet.close();
       }
       
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
     }
     
    }
     
    UserException.java
     
    package com.jaovo.msg.Util;
    @SuppressWarnings("serial")
    public class UserException extends RuntimeException{
     public UserException() {
      super();
      // TODO Auto-generated constructor stub
     }
     public UserException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
      super(message, cause, enableSuppression, writableStackTrace);
      // TODO Auto-generated constructor stub
     }
     public UserException(String message, Throwable cause) {
      super(message, cause);
      // TODO Auto-generated constructor stub
     }
     public UserException(String message) {
      super(message);
      // TODO Auto-generated constructor stub
     }
     public UserException(Throwable cause) {
      super(cause);
      // TODO Auto-generated constructor stub
     }
     
    }
     
    ValidateUtil.java
     
    package com.jaovo.msg.Util;
    import java.util.HashMap;
    import java.util.Map;
    import javax.servlet.http.HttpServletRequest;
    public class ValidateUtil {
     public static  boolean validateNull(HttpServletRequest request,String[] fileds) {
      boolean validate = true;
      //map对象用来装载不同的错误信息
      Map<String,String> errorMsg = new HashMap<String, String>();
      for(String filed :fileds) {
       String value = request.getParameter(filed);
       if (value == null || "".equals(value.trim())) {
        validate = false;
        errorMsg.put(filed, filed+"不能为空");
       }
       if (!validate) {
        request.setAttribute("errormsg", errorMsg);
       }
       
      }
      
      return validate;
     }
     public static String showError(HttpServletRequest request , String filed) {
      @SuppressWarnings("unchecked")
      Map<String, String> errorMsg = (Map<String,String>)request.getAttribute("errormsg");
      if (errorMsg == null) {
       return "";
      }
      String msg = errorMsg.get(filed);
      if (msg == null) {
       return "";
      }
      return msg;
     }
     
    }
     
     
  • 相关阅读:
    BZOJ 4199: [Noi2015]品酒大会 后缀自动机+逆序更新
    BZOJ 3676: [Apio2014]回文串 回文自动机
    Remember the Word UVALive
    [APIO2012]派遣 可并堆(左偏树)
    BZOJ 2555: SubString 后缀自动机 + LCT
    力扣题目汇总(转换成小写字母,唯一摩尔斯密码,有序数组平方)
    力扣题目汇总(加一,旋转数组,整数反转)
    力扣题目汇总(存在重复,合并两个有序数组,搜索插入位置)
    力扣题目汇总(买卖股票的最佳时机,最大连续1的个数,缺失的数字)
    力扣题目汇总(最长特殊序列,回文数,移动零)
  • 原文地址:https://www.cnblogs.com/ltw222/p/14067672.html
Copyright © 2011-2022 走看看