」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 使用 Oats~i 建立 Web 應用程式 – 設定

使用 Oats~i 建立 Web 應用程式 – 設定

發佈於2024-08-24
瀏覽:714

In the last article, I wrote an introductory post about Oats~i, the open web framework. I talked about its core features, a bit of how it works, and what to expect. If you didn’t read that piece, give it a quick look.

Over the past couple of days, I’ve created a few tooling around Oats~i to ensure we can quickly get up and running installing the framework, running a starter project, and seamlessly working on tutorials and learning.

This piece is the first of a series called Build a Web App with Oats~i. We’ll start with setting up an Oats~i project using two methods – using the cli or manually.

Using the Oats~i CLI (Recommended)

This is the most recommended method for setting up an Oats~i project. It saves you the time of writing boiler plate code and installing the dependencies needed to get an Oats~i project up and running.

However, you should use this method only when creating a completely new project to avoid potential file conflicts between Oats~i and your current project structure.

The cli comes set up with a starter project with a home and about page. You can navigate between these two pages to see Oats~i already in action, handling routing and fragments.

How to Use the Oats~i CLI

  • Navigate to the folder you want to create an Oats~i project
  • Open the terminal and run
npx oats-i-cli

  • Follow the prompts and wait for the setup to complete
  • Run
npm run dev

  • Navigate to the address shown in the terminal at the start of the build (often is localhost:8080). That will open the starter project on your browser. (You can use the local network address to view it on your other devices connected to the same network)

Manual Installation

If you have an existing project you want to install Oats~i to, or love being hardcore, you can set up Oats~i manually. This process is much longer, and requires more attention to ensure everything works well.

Install Dependencies

Now, start by navigating to your project’s directory and open the terminal.

First, we install the dependencies needed to build and run Oats~i. If you’re starting a new project, start by running.

npm init -y

Then, follow the steps outlined below.

NOTE: Apart from installing Oats~i, you can skip any of the steps after it if you already have the libraries/dependencies installed in your current project.

Install Oats~i (Core)

Install the core Oats~i library.

Run

npm install oats-i

Install Webpack

Install Webpack as a development dependency. Webpack will allow us to have better project structures among other features, with the library handling module bundling and asset management.

Run

npm install --save-dev webpack webpack-cli

Install Webpack Dev Server

Install the webpack dev server as a development dependency. This will allow us to run a development server that will auto-update on new changes while we’re building and testing our Oats~i web app.

Run

npm install --save-dev webpack-dev-server

Install Handlebars-Loader

It’s strongly recommended that you use a templating engine for rendering your views in Oats~i. My preferred choice is handlebars. (Learn more about handlebars)

To work with webpack, we’ll need to install the handlebars-loader as a development dependency. That will allow us to use handlebars templates to generate and render our views in-app.

Run

npm install --save-dev handlebars-loader

Install HTML-Loader

To create server-side views, the base Oats~i configuration uses a combination of html-loader and html-webpack-plugin. Let’s first install the html-loader library as a development dependency.

Run

npm install --save-dev html-loader

Install HTML-Webpack-Plugin

The html-webpack-plugin library allows us to output server-side views for our app using webpack. It works in conjunction with html-loader. Install it as a development dependency.

Run

npm install --save-dev html-webpack-plugin

Install Babel-Loader

Babel-loader will load and transform our JavaScript files using webpack. Install it as a development dependency.

Run

npm install --save-dev babel-loader

Install Style-Loader and CSS-Loader

Style-loader and css-loader will inject our css imports as stylesheets in our html files produced by html-loader and html-webpack-plugin. Install these loaders as development dependencies.

Run

npm install --save-dev style-loader

npm install --save-dev css-loader

Install Webpack-Merge

Webpack-merge will allow us to merge multiple webpack configuration files, allowing us to structure our configuration files in optimal ways for our project setup. Install this library as a development dependency.

Run

npm install --save-dev webpack-merge

Install Express-Handlebars

Express-handlebars will allow us to emulate server-side rendering in development using handlebars view files outputted by our webpack configuration, using html-loader and html-webpack-plugin. Install this library as a development dependency.

Run

npm install --save-dev express-handlebars

Create Webpack Configuration Files

At the root of your project’s directory, create a new folder and call it “webpack-configs”.

Build a Web App with Oats~i – Setting Up

Navigate into this folder and create two new folders inside it named “main” and “oats~i”.

Your folder structure should now look like this:

Build a Web App with Oats~i – Setting Up

Now, navigate into “oats~i” and create two more folders named “default” and “main”.

Your folder structure should now look like this:

Build a Web App with Oats~i – Setting Up

------

The “default” folder will hold the default webpack configuration needed by Oats~i to have it’s webpack-dependent functions work. Currently, that is code splitting and lazy loading for fragments.

The “main” folder will hold the webpack configuration for loaders used and recommended by Oats~i. These are the loaders we installed in the “install dependencies” stage. Feel free to edit this configuration later if you want to change loaders.

------

Navigate to the “default” folder and create a new file called “webpack.config.js”

Build a Web App with Oats~i – Setting Up

Open the file and paste the following code inside it.

//@ts-check
const DefaultOats_iConfig = {

    optimization: {

        splitChunks: {

            minSize: 0, //Minimum size, in bytes, for a chunk to be generated.
            minSizeReduction: 1, //Minimum size reduction to the main chunk (bundle), in bytes, needed for a chunk to be generated.
            minChunks: 2,
            cacheGroups: {

                commons: {

                    chunks: "async", //Allow chunks to be shared between sync and async
                }
            }
        }
    }
}

module.exports = DefaultOats_iConfig;

Now, navigate back to the “oats~i” folder and navigate into “main”.

Create a new file and name it “webpack.config.js”.

Build a Web App with Oats~i – Setting Up

Open the file and paste the following code inside.

//@ts-check
/**
 * Contains loaders
 */
const DefaultOats_iLoadersConfig = {

    module: {

        rules: [

            {
                test: /\.(html|sv.hbs|p.hbs)$/,
                use: [
                        {
                            loader: "html-loader",
                            options: {
                                minimize: false
                            }
                        }
                ]
            },
            {
                test: /\.(hbs)$/,
                exclude: /\.(sv.hbs|p.hbs)/,
                use: [
                    {
                        loader: "handlebars-loader",
                        options: {
                            inlineRequires: "./assets"
                        }
                    }
                ]
            },
            {
                test: /\.(js)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: "babel-loader"
                    }
                ]
            },
            {
                test: /\.(png|svg|jpg|gif)$/,
                type: 'asset/resource',
            },
            {
                test: /\.css$/,
                use: [

                    'style-loader',
                    'css-loader'
                ]
            }
        ]
    }
}

module.exports = DefaultOats_iLoadersConfig;

We’re done setting up the core webpack configuration for Oats~i. Now, we need to merge them in a common configuration file that we’ll use project-wide.

Now, navigate back to the “oats~i” folder then back to the “webpack-configurations” folder. Now navigate into “main”.

Create a new file and name it “webpack.config.js”.

Build a Web App with Oats~i – Setting Up

Open the file and paste the following code inside.

//@ts-check
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const DevServerMiddlewareConfig = require("../../proxy-server/proxy_server");
//The folder we'll have our assets emitted after build
const DIST_PATH_PUBLIC_ASSETS = "../../dist/public";
const { merge } = require("webpack-merge");
const DefaultOats_iConfig = require("../oats~i/default/webpack.config");
const DefaultOats_iLoadersConfig = require("../oats~i/main/webpack.config");

//@ts-expect-error
module.exports = merge(DefaultOats_iConfig, DefaultOats_iLoadersConfig, {

    mode: "development",
    devtool: "eval-source-map",
    output: {

        //Where we'll output public assets
        path: path.resolve(__dirname, `${DIST_PATH_PUBLIC_ASSETS}`),
        publicPath: "/",
        assetModuleFilename: 'assets/[name][ext]',
        filename: "js/[name].dev_bundle.js",
        clean: true
    },
    entry: {

        //The main entry (app)
        index: "./src/app/index/scripts/index.js",
    },
    plugins: [
        new HtmlWebpackPlugin({

            template: "./src/server/home/home.sv.hbs",
            filename: "../views/home.hbs",
            chunks: ["index"],
            minify: false
        })
    ],
    devServer: {

        devMiddleware: {

            writeToDisk: true, //Because of our configured server
        },
        setupMiddlewares: DevServerMiddlewareConfig,
    }
});

Now, we should be done setting up our webpack configurations that’s just fine to run an Oats~i project.

Update package.json

Navigate back to your project’s root folder. Open package.json, look for the “scripts” line, and add the following line after “test” (remember to separate with a comma).

"dev": "webpack-dev-server --config ./webpack-configs/main/webpack.config.js"

Build a Web App with Oats~i – Setting Up

Set Up Dev Server Middlewares

In our final webpack configuration file, we specified a middlewares file for the webpack dev server under

setupMiddlewares: DevServerMiddlewareConfig

Under normal circumstances, you don’t need this setup. You can simply write your server view files in html format, use html-loader and html-webpack-plugin to produce them, and have them directly served by webpack-dev-server during development.

However, as you’ll come to learn later, this is not the best setup for building an Oats~i project that’s already primed for server-side rendering. The server-side files are already in html format, meaning they can’t be easily templated with data before being rendered to the client on the initial request.

To accommodate that, the default Oats~i setup ensures you’re creating template files for your server views that will be easy to render with data from your server every time a client requests for a fresh page.

Our dev server middlewares setup will allow us to mimic such as setup on the actual server, for our development environment.

With its default setup, you don’t need to update it for new fragments that you add to the project, as long as you’re not interested in having them server-side rendered. However, once you get to the point where you want to have server-side rendering and test it in development, setting things up will be much easier and faster, without a change in file formats you’ve already used across the project.

Let’s Set Up this Config

At your project’s root directory, create a new folder and name it “proxy-server”. Inside this new folder, create a file and name it “proxy_server.js”

Build a Web App with Oats~i – Setting Up

Open the file and paste the following code:

//@ts-check
const express = require("express");
const path = require("path");
const hbs = require("express-handlebars");

const DevServerMiddlewareConfig = (middlewares, devServer) => {

    /**
     * @type {import("express").Application}
     */
    const app = devServer.app;

    //Configure the view engine
    app.set("views", path.resolve(__dirname, "../dist/views"));
    app.set("view engine", "hbs");
    app.engine("hbs", hbs.engine({

        extname: "hbs",
        layoutsDir: path.resolve(__dirname, "../dist/views"),
        partialsDir: path.resolve(__dirname, "../dist/views/partials")
    }));

    //for json
    app.use(express.json());
    //I think params and queries
    app.use(express.urlencoded({ extended: false }));
    //static
    app.use(express.static(path.resolve(__dirname, "../dist/public")));

    //My middlewares
    //Capture all
    app.get("/*", (req, res, next) => {

        res.render("home", {
            layout: "home"
        });
    });

    return middlewares;
}

module.exports = DevServerMiddlewareConfig;

This configuration will capture all requests to the dev server and return the home.hbs layout file. You can rename this later to your file’s actual name once you start creating your own Oats~i project and leave it as is as long as you’ll not require server-side rendering for any of your fragments.

Create jsconfig.json

Oats~i is typed using a combination of typescript declaration files and JSDoc. There’s a slight issue where types may not always reflect correctly when using the framework, slightly hurting the developer experience.

Instead of refactoring over 100 files and thousands of lines of code, I’ve found a way to make typescript and intellisense (at least in VSCode) to understand the JSDoc types used in Oats~i.

To do this, navigate to your project’s root folder. Create a file named “jsconfig.json”.

Build a Web App with Oats~i – Setting Up

Open it and paste the code below:

{
    "include": [
        "*/**/*.js",
        "**/*",
        "/**/*",
        "node_modules/oats-i" //to get type definitions for oats-i in your project
    ],
}

NOTE: This bit comes automatically with the cli, so don’t do this for an Oats~i project you’ve set up using the cli.

Create Starter Project Files

Let’s now put everything together and create our starter project files to run an Oats~i app for the first time.

Server-side Base Layout

Navigate to your project’s root folder and create a new folder named “src”. This folder will contain all of our project’s source files.

Inside the “src” folder, create two folders named “app” and “server”.

Build a Web App with Oats~i – Setting Up

Navigate to the “server” folder and create a new folder named “home”. Inside the “home” folder, create a new file and name it “home.sv.hbs”

Build a Web App with Oats~i – Setting Up

Open the file and paste the code below:




    Home - My Oats~i AppHome
        
        

App Files

Now navigate back to “src”. Get into the “app” folder and create two folders name “fragments” and “index”.

Build a Web App with Oats~i – Setting Up

Navigate into the “index” folder and create two folders named “scripts” and “styles”.

Build a Web App with Oats~i – Setting Up

Inside the “scripts” folder, create a new folder called “routing-info”. Inside “routing-info” create two files named “app_main_nav_info.js” and “app_routing_info.js”

Build a Web App with Oats~i – Setting Up

Main Navigation info

Open “app_main_nav_info.js” and paste the following code:

//@ts-check
import MainNavigationInfoBuilder from "oats-i/router/utils/nav-info/main_nav_info_builder";

const AppMainNavInfo = MainNavigationInfoBuilder.buildMainNavigationInfo([
    {
        selector: "home-link",
        defaultRoute: "/",
        baseActiveRoute: "/",
    }
]);

export default AppMainNavInfo;

Main Routing Info

Now open “app_routing_info.js” and paste the following code:

//@ts-check
import RoutingInfoUtils from "oats-i/router/utils/routing-info/routing_info_utils";
import AppMainNavInfo from "./app_main_nav_info";
import homeMainFragmentBuilder from "../../../fragments/home/scripts/home_main_fragment";

const AppRoutingInfo = RoutingInfoUtils.buildMainRoutingInfo([

    {
        route: "/",
        target: homeMainFragmentBuilder,
        nestedChildFragments: null
    }
], AppMainNavInfo);

export default AppRoutingInfo;

Index.css

We’ll create an index.css file for a special reason, which MUST be replicated across all your Oats~i projects if you want consistent behavior.

Navigate back to the “index” folder, and create a new folder named “styles”. Inside the folder, create a new file called “index.css”

Build a Web App with Oats~i – Setting Up

Open the file and paste the following code:

/* Crucial styling to allow specially structured A links to still have clicks intercepted by router. */
/* Carry over to your project */
a *:not([click-override=true]){ 

    pointer-events: none 
}

What this css code does is remove pointer events from elements nested inside an A tag, to ensure the browser doesn’t intercept it before Oats~i does. It also gives you, the developer, the freedom to override this behavior using the attribute click-override=true on any element nested within an A tag.

However, expect Oats~i, at its current state, not to intercept links from an A tag with a child element having that attribute.

This means that you can safely write A tags without any modification or special attributes for Oats~i to automatically intercept them and navigate your app locally. You only add special attributes when you want to stop this behavior and have the browser manually route the website.

Carry over this css directive in all Oats~i projects you create. If you use the cli, you’ll find it already in index.css.

Index.js

Navigate back to “scripts” (inside index) and create a new file named “index.js”.

Build a Web App with Oats~i – Setting Up

Open the file and paste the following code.

//@ts-check
//import styles
import "../styles/index.css";
import AppStateManager from "oats-i/base-history/app_state_manager";
import appRoot from "oats-i/bin/app_root"
import AppRoutingInfo from "./routing-info/app_routing_info";
import MainRouter from "oats-i/router/main_router";
import AppMainNavInfo from "./routing-info/app_main_nav_info";

function initApp(){

    const appStateManager = new AppStateManager(AppRoutingInfo);
    appRoot.initApp(appStateManager, new MainRouter(AppRoutingInfo, appStateManager, (args) => {}, "", async (url) => {

        return {

            canAccess: true,
            fallbackRoute: "/"
        }
    }), { template: null, mainNavInfos: AppMainNavInfo }, "");
}

initApp();

Fragments

Navigate back to the “app” folder. Navigate into “fragments” and create a new folder named “home”.

Inside “home”, create a new folder named “scripts”. Inside “scripts”, create a new file named “home_main_fragment.js”.

Build a Web App with Oats~i – Setting Up

Open the file and paste the code below.

//@ts-check
import AppFragmentBuilder from "oats-i/fragments/builder/AppFragmentBuilder";
import AppMainFragment from "oats-i/fragments/AppMainFragment"

class HomeMainFragment extends AppMainFragment{

    async initializeView(cb){

        //@ts-expect-error cannot find module (for view)
        const uiTemplate = require("../views/home_fragment.hbs")();
        this.onViewInitSuccess(uiTemplate, cb);
    }
}

const homeMainFragmentBuilder = new AppFragmentBuilder(HomeMainFragment, {

    localRoutingInfos: null,
    viewID: "home-main-fragment",
});
export default homeMainFragmentBuilder;

Now navigate back to “home” and create a new folder called “views”. Inside “views”, create a new file and name it “home_fragment.hbs”

Build a Web App with Oats~i – Setting Up

Open file and paste the following code:

Home Fragment

Test the Configuration

Navigate to your project’s root. Open the terminal and run

npm run dev

This will start the webpack-dev-server which will bundle the files and run Oats~i. If you open the browser at the url shown in the terminal (often is localhost:8080) and see a page with “Home Fragment” showing, your project has been successfully set up and Oats~i is working fine.

Configuration Extensibility

Regardless of whether you’ve manually set up an Oats~i project or used the cli, there are configuration flexibilities you can enjoy thanks to Oats~i running on top of Webpack.

Basically, apart from the default Oats~i webpack configuration, you can change anything else to your liking as long as you understand webpack, plugins, and loaders, and how they’ll affect your project.

For instance, you can have a production configuration that will use MiniCssExtractPlugin to extract your css into files that will be added to the final html-webpack-plugin output. You can use advanced babel configurations and even switch handlebars-loader for a loader that suits your favorite templating engine.

However, the default setup provided by Oats~i is good enough for most projects. Later on in the tutorials, we’ll add a new configuration to create the final production build with key features such as minification.

Further Reading

I encourage you to learn about Webpack, why it’s needed, and how you can configure it, to make the most out of Oats~i and other projects you may have using Webpack as a bundler.

Sign Up and Follow for the Next Tutorial

That’s it for setting up Oats~i for your project. If you’re working on a new project, just use the cli. It’s easier, faster, and will directly load you into a beautiful starter project that you can inspect and start getting ideas of how to setup a full project with view, styling, and script files in Oats~I, before we start doing that together.

In the next tutorial, we’ll create our first simple project in Oats~i, where we’ll start learning what routing infos, nav infos, and fragments are in Oats~i.

Leave a like and follow to get notified when the next tutorial drops.

See you then.

Support Oats~i

You can support the development of Oats~i through Patreon or buy me a coffee.

版本聲明 本文轉載於:https://dev.to/oatsi/build-a-web-app-with-oatsi-setting-up-53al?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 在 Go 中使用 WebSocket 進行即時通信
    在 Go 中使用 WebSocket 進行即時通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要一种比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSoc...
    程式設計 發佈於2024-11-17
  • Flexbox、Box 或 Flexbox:您應該使用哪種顯示屬性?
    Flexbox、Box 或 Flexbox:您應該使用哪種顯示屬性?
    靈活盒子模型:顯示:Flex、Box、Flexbox在 CSS3 領域,靈活盒子模型徹底改變了方式我們佈局元素。然而,豐富的顯示屬性值可能會令人困惑。 display: flex、display: box 和 display: flexbox 有什麼差別? Display: BoxFirefox 2...
    程式設計 發佈於2024-11-17
  • 如何在不使用 Python 的情況下使用 C++ 計算複雜的數學表達式?
    如何在不使用 Python 的情況下使用 C++ 計算複雜的數學表達式?
    如何在不整合Python 的情況下評估C 中的自訂數學表達式在沒有外部庫或運行時環境的情況下評估C 中的複雜數學表達式可能具有挑戰性。然而,ExprTk 庫提供了一個優雅且高效的解決方案。 讓我們考慮一個範例表達式:3 sqrt(5) pow(3, 2) log(5)使用ExprTk,我...
    程式設計 發佈於2024-11-17
  • 如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    在 PHP 中組合關聯數組在 PHP 中,將兩個關聯數組組合成一個數組是常見任務。考慮以下請求:問題描述:提供的代碼定義了兩個關聯數組,$array1 和 $array2。目標是建立一個新陣列 $array3,它合併兩個陣列中的所有鍵值對。 此外,提供的陣列具有唯一的 ID,而名稱可能重疊。要求是建...
    程式設計 發佈於2024-11-17
  • Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta:列偏移的刪除和恢復Bootstrap 4 在其Beta 1 版本中引入了重大更改柱子偏移了。然而,隨著 Beta 2 的後續發布,這些變化已經逆轉。 從 offset-md-* 到 ml-auto在 Bootstrap 4 Beta 1 中, offset-md-*...
    程式設計 發佈於2024-11-17
  • API 設計中 HTTP 狀態碼的終極參考
    API 設計中 HTTP 狀態碼的終極參考
    在 Web 开发和 API 设计领域,HTTP 状态代码在客户端和服务器之间传达请求结果方面发挥着至关重要的作用。这些代码提供了一种标准化的方式来指示在处理 HTTP 请求期间发生的特定条件、成功或错误。了解这些状态代码对于开发人员至关重要,因为它有助于调试、错误处理和创建更强大的应用程序。 ...
    程式設計 發佈於2024-11-17
  • gRPC 和 Go:建立高效能 Web 服務
    gRPC 和 Go:建立高效能 Web 服務
    介紹 在微服務和分散式系統的世界中,服務之間的高效通訊至關重要。這就是 Google 開發的高效能 RPC(遠端過程呼叫)框架 gRPC 發揮作用的地方。與 Go(一種專為簡單和高效而設計的靜態類型編譯程式語言)相結合,gRPC 可以幫助您建立強大且可擴展的 Web 服務。 ...
    程式設計 發佈於2024-11-17
  • 如何使用 Spring 在 Hibernate 4 中定義與註解的關係?
    如何使用 Spring 在 Hibernate 4 中定義與註解的關係?
    使用Spring 在Hibernate 4 中使用註解定義關係要在Hibernate 4 中為提供的類別Foo 使用註解實現各種類型的關係和Bar,讓我們深入研究一下具體情況。 一對多單向關係:使用@OneToMany註解和List屬性。保持 Bar 類別不變。這建立了一對多關係,其中 Foo 可以...
    程式設計 發佈於2024-11-17
  • 如何在 Python 中即時串流處理輸出?
    如何在 Python 中即時串流處理輸出?
    在進程執行過程中連續輸出顯示在Python腳本中,我們經常利用子程序來執行外部程序。雖然這是一個強大的功能,但在檢索其輸出之前等待進程完成可能會令人沮喪。為了解決這個問題,讓我們探索一種在進程運行時連續串流傳輸進程輸出的方法。 傳統上,我們使用 subprocess.communicate() 來擷...
    程式設計 發佈於2024-11-17
  • 如何在 PHP 中選擇正確的使用者瀏覽器偵測方法?
    如何在 PHP 中選擇正確的使用者瀏覽器偵測方法?
    使用PHP 進行可靠的用戶瀏覽器檢測確定最佳方法當涉及到PHP 中的用戶瀏覽器檢測時,選擇使用$_SERVER ['HTTP_USER_AGENT'] 和get_browser 函數出現。每種方法都有其優點和缺點。 $_SERVER['HTTP_USER_AGENT'...
    程式設計 發佈於2024-11-17
  • 如何在 PHP 中反序列化 jQuery 序列化表單?
    如何在 PHP 中反序列化 jQuery 序列化表單?
    在PHP 中反序列化jQuery 序列化表單利用jQuery 的$('#form').serialize() 方法提交表單資料時到一個PHP頁面,問題就出現了:我們如何在PHP中反序列化它? PHP jQuery序列化表單的反序列化PHP的parse_str()函數提供了有效的解決方...
    程式設計 發佈於2024-11-17
  • 如何在不使用代理程式的情況下追蹤 JAX-WS 中的 XML 請求和回應?
    如何在不使用代理程式的情況下追蹤 JAX-WS 中的 XML 請求和回應?
    在沒有代理的情況下跟踪JAX-WS 中的XML 請求/響應利用JAX-WS 參考實現,可以訪問原始請求/無需使用代理即可回應Web 服務的XML。這可以透過設定啟用日誌記錄通訊的系統屬性來實現。以下是完成此動作的程式碼:System.setProperty("com.sun.xml.ws....
    程式設計 發佈於2024-11-17
  • 大批
    大批
    方法是可以在物件上呼叫的 fns 數組是對象,因此它們在 JS 中也有方法。 slice(begin):將陣列的一部分提取到新數組中,而不改變原始數組。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index ...
    程式設計 發佈於2024-11-17
  • 正規表示式夠了嗎?驗證電子郵件地址的全面指南
    正規表示式夠了嗎?驗證電子郵件地址的全面指南
    確保電子郵件地址的有效性:綜合指南驗證電子郵件地址的有效性是資料驗證的一個重要面向。 Regex(正規表示式)提供了一個強大的工具,可確保使用者輸入符合特定的電子郵件格式。然而,子網域電子郵件地址的存在經常在驗證過程中帶來挑戰。 基於正規表示式的驗證的局限性雖然正則表達式對於檢查基本資訊很有用電子郵...
    程式設計 發佈於2024-11-17
  • 如何使用 PHP 和 MySQL 查詢結果來擷取父節點下的所有子節點、孫節點和後代節點?
    如何使用 PHP 和 MySQL 查詢結果來擷取父節點下的所有子節點、孫節點和後代節點?
    使用PHP 和MySQL 查詢父級下的所有子節點、孫節點等節點原始問題: 檢索與父節點關聯的所有子節點、孫節點和後續後代節點是使用分層資料結構時的常見任務。這個問題出現在資料庫表採用鄰接表模型進行資料組織的場景。 使用遞迴的方法:為了解決這個問題,遞迴被證明是一種有效的方法。以下是如何使用遞歸來實現...
    程式設計 發佈於2024-11-17

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3