1. 程式人生 > 資訊 >SKSE 作者透露,《上古卷軸 5:天際週年紀念版》將不相容現有大量 Mod

SKSE 作者透露,《上古卷軸 5:天際週年紀念版》將不相容現有大量 Mod

SMBMS

資料庫:

專案如何搭建?

考慮使用不使用Maven? 使用的話要依賴,不使用要導jar包

專案搭建準備工作

  1. 搭建一個maven web專案

  2. 配置tomcat

  3. 測試專案是否能夠跑起來

  4. 匯入專案中會遇到的jar包;

    jsp、Servlet、mysql驅動、jstl、stand.......

  5. 建立專案包結構

  6. 編寫實體類;

    ORM對映:表-類對映

  7. 編寫基礎公共類

    1. 資料庫配置檔案

      driver=com.mysql.jdbc.Driver
      url="jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=utf8&useSSL=true"
      username=root
      password=123456
      1. 編寫資料庫的公共類

          //靜態程式碼塊,類載入的時候就初始化了
        static {
        Properties properties = new Properties();
        //通過類載入器讀取對應的資源
        InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
        try {
        properties.load(is);

        } catch (IOException e) {
        e.printStackTrace();
        }

        driver = properties.getProperty("driver");
        url = properties.getProperty("url");
        username = properties.getProperty("username");
        password = properties.getProperty("password");
        }

        //獲取資料庫的連線
        public static Connection getConnection(){
        Connection connection = null;
        try {
        Class.forName(driver);
        connection = DriverManager.getConnection(url, username, password);

        } catch (Exception e) {
        e.printStackTrace();
        }
        return connection;
        }
        //編寫查詢公共類
        public static ResultSet exexute(Connection connection,String sql,Object[] params,ResultSet resultSet,PreparedStatement preparedStatement ) throws SQLException {
        //預編譯的sql,在後面直接執行就可以了
        preparedStatement = connection.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
        //setObject,佔位符從1開始,但是我們的陣列是從0開始!
        preparedStatement.setObject(i + 1, params[i]);
        }
        resultSet = preparedStatement.executeQuery(sql);
        return resultSet;
        }

        //編寫增刪改公共方法
        public static int exexute(Connection connection,String sql,Object[] params,PreparedStatement preparedStatement ) throws SQLException {
        preparedStatement = connection.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
        //setObject,佔位符從1開始,但是我們的陣列是從0開始!
        preparedStatement.setObject(i+1,params[i]);
        }
        int updateRows = preparedStatement.executeUpdate(sql);
        return updateRows;
        }
        //釋放資源
        public static boolean closeResource(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet){

        boolean flag = true;
        if (resultSet != null){
        try {
        resultSet.close();
        //GC回收
        resultSet = null;
        } catch (SQLException throwables) {
        throwables.printStackTrace();
        flag = false;
        }
        }
        if (preparedStatement != null){
        try {
        preparedStatement.close();
        //GC回收
        preparedStatement = null;
        } catch (SQLException throwables) {
        throwables.printStackTrace();
        flag = false;
        }
        }
        if (connection!= null){
        try {
        connection.close();
        //GC回收
        connection = null;
        } catch (SQLException throwables) {
        throwables.printStackTrace();
        flag = false;
        }
        }
        return flag;
        }
        }
        1. 編寫字元編碼過濾器

  8. 匯入靜態資源

登入功能實現

  1. 編寫前端頁面

  2. 設定首頁

    <!--   設定歡迎頁面-->
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>