&n">
Home Database Mysql Tutorial 开发自己的Data Access Application Block[上篇]

开发自己的Data Access Application Block[上篇]

Jun 07, 2016 pm 03:48 PM
access application data develop my own

经常在网上看到对ORM的讨论沸沸扬扬,我也来凑个热闹,谈谈我写的一个ORM。最近在做一项工作,把我们经常用到的一些业务逻辑抽象出来,写成一个个的Application Block,使之可以运用到不同的Application中,比如Data Access,Messaging,Auditing,Data bind

经常在网上看到对ORM的讨论沸沸扬扬,我也来凑个热闹,谈谈我写的一个ORM。最近在做一项工作,把我们经常用到的一些业务逻辑抽象出来,写成一个个的Application Block,使之可以运用到不同的Application中,比如Data Access,Messaging,Auditing,Data binding等等。现在先做一个Data access application block。由于时间仓促,没有进行什么优化和较多的测试,大家不必深究我所提供的Code ,我只希望为大家的ORM提供另一种想法。

这个application block应达到的目的:

  • 封装所有的Data Access操作。

  • 适合主流的DBMS:SQL Server(2000和2005),Oracle(9i和10g),DB2。

  • 尽量简化Developer的操作和提供最大的灵活性,在Data Retrieval方面,只要指定SQL或者Stored Procedure和相应的参数;在Data Update方面,既可以直接调用SQL和Stored Procedure,还可以把包含多个相互关联Data Table的Dataset通过一次调用实现数据的更新。此外,可以自由地选择使用SQL还是Stored procedure;可以使用Commander builder生成Command或者使用基于Mapped stored procedure生成的Command进行数据更新。

  • 实现泛型编程,使使用该AppBlock的代码能够适合所有的数据库。

  • 实现Transaction。

  • 提供可配置性,包括不同数据库的配置,不同Data Mapping的配置等等。

下面是该AppBlock使用到的Entity:
开发自己的Data Access Application Block[上篇]

  • Database:Abstract Class,封装了绝大部分和具体数据库无关的Data Access操作逻辑。通过两个Mapping:IDbParameterNameMapping和IStoredProcedureNameMapping,实现Dataset和Db的一个映射。比如Dataset中Data table name和Stored procedure name的Mapping,Data table中Field和Stored procedure中参数名的Mapping。这两个Mapping是可以配置的,你只需要实现提供的Interface编写适合你的Mapping provider就可以了。

  • SqlDatabase:封装基于SQL Server 的操作。ADO.NET 2.0在1.0的基础上作了很大的改善,主要的增加的大量的基类,为我们进行泛型编程,编写和具体Db无关的代码变得异常容易。所以我们把大多数Data Access的操作可以封装在Abstract Database类中,SqlDatabase中的内容实际上是很少的。

  • OracleDatabase:封装基于Oracle的操作。

  • IDbParameterNameMapping和IStoredProcedureNameMapping:我想大家都是这样的感受,实现ORM的本质就是实现内存中的数据(主要是Dataset)和数据库的一个映射。在Dataset和数据库中的Table相互Mapping方面,我觉得没有必要采用特殊的Mapping,直接和简单易行的就是Table和Dataset中的Data Table完全匹配(table name 和field name完全匹配)。所以重要的是实现Dataset和Stored procedure的Mapping:Table Name如何与进行Insert,Update,Delete的Stored procedure name匹配,不同Version(original & current)的Field如何与Stored procedure的Parameter name 匹配。而这样一个匹配应该是可配置的,因为每个Application在数据库设计时的命名都有各自的要求,所以我在这里采用的Provider的设计模式。用户可以实现这两个Interface编写适合自己的Mapping provider,通过我提供的Configuration block很容易地完成配置。同时,我写了一个默认的,简单的Mapping:SimpleDbParameterNameMapping和SimpleStoredProcedureNameMapping。

      有一点需要补充的是,要实现上面的Mapping,对Stored Procedure的命名有较高的要求,手工编写的方式已经不能适合我们的要求,所以我们需要一个生成Stored procedure的Generator,这个Generator也使用这两个可配置的Mapping接口。

  • DatabaseFactory: 一个静态的类,根据配置的信息创建你需要的具体的Database对象,实现泛型化编程。

  • DataAccessConfigurationCollection,DataAccessConfigurationElement,DataAccessConfigurationdiv 三个Configuration的Class。

为了使大家清楚地看出这个Application block所有的操作,我把所有的操作封装在一个IDatabase的interface中,不过需要注意的是,我采用的是基于Abstract class的编程,而不是基于Interface的编程,相信大家对这两种方式讨论得已经碰倒的太多了,孰优孰劣我就不想对说了。这个IDatabase 接口,只是展示所有Operation之用,并没有在我的代码中用到。

开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]namespace Artech.ApplicationBlock.DataAccess
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]    
public interface IDatabase
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
Fill a System.Data.DataSet with retrieved data.#region Fill a System.Data.DataSet with retrieved data.
开发自己的Data Access Application Block[上篇]        
void FillDataSet(DataSet dataInfo, string commandText, IDictionarystringobject> parameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
void FillDataSet(DataSet dataInfo, string tableName, string commandText, IDictionarystringobject> parameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
void FillDataSet(DataSet dataInfo, string tableName, CommandType commandType, string commandText, IDictionarystringobject> parameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
#endregion

开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
Save the changed data which is stored in a dataset into database.#region Save the changed data which is stored in a dataset into database.
开发自己的Data Access Application Block[上篇]        
void UpdateData(DataSet dataInfo);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
void UpdateData(DataTable table);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
void UpdateData(DataTable table, string insertCommandText, string updateCommandText, string deleteCommandText,
开发自己的Data Access Application Block[上篇]           Dictionary
stringobject> insertParameters, Dictionarystringobject> updateParameters, Dictionarystringobject> deleteParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]                
void UpdateData(DataTable table, CommandType commandType, string insertCommandText, string updateCommandText, string deleteCommandText,
开发自己的Data Access Application Block[上篇]            Dictionary
stringobject> insertParameters, Dictionarystringobject> updateParameters, Dictionarystringobject> deleteParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
void UpdateData(DataTable table, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
#endregion

开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
Execute a command and return the affect row count.#region Execute a command and return the affect row count.
开发自己的Data Access Application Block[上篇]        
int ExecuteNonQuery(CommandType commandType, string commandText, Dictionarystringobject> inputParameters, Dictionarystringobject> outputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
int ExecuteNonQuery(CommandType commandType, string commandText, Dictionarystringobject> inputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
int ExecuteNonQuery( string commandText, Dictionarystringobject> inputParameters, Dictionarystringobject> outputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
int ExecuteNonQuery( string commandText, Dictionarystringobject> inputParameters);
开发自己的Data Access Application Block[上篇]        
#endregion

开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
Execute a command and return the data in the form of data reader.#region Execute a command and return the data in the form of data reader.
开发自己的Data Access Application Block[上篇]        DbDataReader ExecuteReader(CommandType commandType, 
string commandText, Dictionarystringobject> inputParameters, Dictionarystringobject> outputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        DbDataReader ExecuteReader(CommandType commandType, 
string commandText, Dictionarystringobject> inputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        DbDataReader ExecuteReader(
string commandText, Dictionarystringobject> inputParameters, Dictionarystringobject> outputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        DbDataReader ExecuteReader(
string commandText, Dictionarystringobject> inputParameters);
开发自己的Data Access Application Block[上篇]        
#endregion

开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
Execute a command and return a scalar value.#region Execute a command and return a scalar value.
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
object ExecuteScalar(CommandType commandType, string commandText, Dictionarystringobject> inputParameters, Dictionarystringobject> outputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
object ExecuteScalar(CommandType commandType, string commandText, Dictionarystringobject> inputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
object ExecuteScalar(string commandText, Dictionarystringobject> inputParameters, Dictionarystringobject> outputParameters);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]        
object ExecuteScalar(string commandText, Dictionarystringobject> inputParameters);
开发自己的Data Access Application Block[上篇]        
#endregion

开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
Transaction based operation#region Transaction based operation
开发自己的Data Access Application Block[上篇]        
void BeginTransaction();
开发自己的Data Access Application Block[上篇]        
void Commit();
开发自己的Data Access Application Block[上篇]        
void RollBack();
开发自己的Data Access Application Block[上篇]        
#endregion

开发自己的Data Access Application Block[上篇]    }

开发自己的Data Access Application Block[上篇]}

开发自己的Data Access Application Block[上篇]

这个列表和大部分ORM没有什么太大的区别,大家已经司空见惯,实现起来也不会有什么太大的困难。对于大部分操作,我不会做详细的介绍。接下来我们来简要地看看这样一个AppBlock是如何实现的。
1. Data Mapping

我们首先来看看Data Mapping:实现Dataset中Table name和Stored Procedure Name的Mapping,以及Dataset 中的Field 和Stored procedure的参Parameter name的Mapping。

IDbParameterNameMapping

开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]using System;
开发自己的Data Access Application Block[上篇]
using System.Collections.Generic;
开发自己的Data Access Application Block[上篇]
using System.Text;
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]
namespace Artech.ApplicationBlock.DataMapping
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
/**//// 


开发自己的Data Access Application Block[上篇]    
/// IStoredProcedureNameMapping defines the mapping between the data table name and the name of stored procedures to perform insertion, modification and deletion operation.
开发自己的Data Access Application Block[上篇]    
/// 
开发自己的Data Access Application Block[上篇]    public interface IStoredProcedureNameMapping
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
/**//// 
开发自己的Data Access Application Block[上篇]        
/// Get the name of stored procedure to perform seletion operation.
开发自己的Data Access Application Block[上篇]        
/// 
开发自己的Data Access Application Block[上篇]        
/// The name of the database table.
开发自己的Data Access Application Block[上篇]        
/// The name of stored procedure to perform seletion operation

开发自己的Data Access Application Block[上篇]        string GetSelectStoredProcedureName(string tableName);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
/**//// 
开发自己的Data Access Application Block[上篇]        
/// Get the name of stored procedure to perform insert operation.
开发自己的Data Access Application Block[上篇]        
/// 
开发自己的Data Access Application Block[上篇]        
/// The name of the database table.
开发自己的Data Access Application Block[上篇]        
/// The name of stored procedure to perform insertion operation

开发自己的Data Access Application Block[上篇]        string GetInsertStoredProcedureName(string tableName);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
/**//// 
开发自己的Data Access Application Block[上篇]        
/// Get the name of stored procedure to perform modification operation.
开发自己的Data Access Application Block[上篇]        
/// 
开发自己的Data Access Application Block[上篇]        
/// The name of the database table.
开发自己的Data Access Application Block[上篇]        
/// The name of stored procedure to perform modification operation

开发自己的Data Access Application Block[上篇]        string GetModifyStoredProcedureName(string tableName);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
/**//// 
开发自己的Data Access Application Block[上篇]        
/// Get the name of stored procedure to perform deletion operation.
开发自己的Data Access Application Block[上篇]        
/// 
开发自己的Data Access Application Block[上篇]        
/// The name of the database table.
开发自己的Data Access Application Block[上篇]        
/// The name of stored procedure to perform deletion operation

开发自己的Data Access Application Block[上篇]        string GetDeleteStoredProcedureName(string tableName);
开发自己的Data Access Application Block[上篇]    }

开发自己的Data Access Application Block[上篇]}

开发自己的Data Access Application Block[上篇]

IDbParameterNameMapping

开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]using System;
开发自己的Data Access Application Block[上篇]
using System.Collections.Generic;
开发自己的Data Access Application Block[上篇]
using System.Text;
开发自己的Data Access Application Block[上篇]
using System.Data;
开发自己的Data Access Application Block[上篇]
namespace Artech.ApplicationBlock.DataMapping
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
/**//// 


开发自己的Data Access Application Block[上篇]    
/// IDbParameterNameMapping define the defult mapping between the source column name and the parameter name of the corresponding stored procedure.
开发自己的Data Access Application Block[上篇]    
/// 
开发自己的Data Access Application Block[上篇]    public interface IDbParameterNameMapping
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
/**//// 
开发自己的Data Access Application Block[上篇]        
/// Get the source column name based on the parameter name of the related stored procedure.
开发自己的Data Access Application Block[上篇]        
/// 
开发自己的Data Access Application Block[上篇]        
/// The parameter name of the corresponding stored procedure.
开发自己的Data Access Application Block[上篇]        
/// The source column name corresponding to the parameter name.

开发自己的Data Access Application Block[上篇]        string GetSourceCoulmnName(string patameterName);
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]        
/**//// 
开发自己的Data Access Application Block[上篇]        
/// Get the source parameter name based on the source column name.
开发自己的Data Access Application Block[上篇]        
/// 
开发自己的Data Access Application Block[上篇]        
/// The source column name corresponding to the parameter name.
开发自己的Data Access Application Block[上篇]        
/// The data row version of the source solumn conressponding to the parameter.
开发自己的Data Access Application Block[上篇]        
/// The parameter name of the corresponding stored procedure.

开发自己的Data Access Application Block[上篇]        string GetParameterName(string columnName, DataRowVersion rowVersion);
开发自己的Data Access Application Block[上篇]    }

开发自己的Data Access Application Block[上篇]}

开发自己的Data Access Application Block[上篇]

这两个Mapping主要用在通过Dataset跟新数据库的场景,利用IDbParameterNameMapping,我们通过Dataset中各个Table name获得对它进行Insert,Update,Delete操作的Stored procedure的name。利用IDbParameterNameMapping,我们可以为Stored procedure的Parameter指定对应的Source field.  

注:GetParameterName方法实际上是不需要的,我把使用在另一个AppBlock中。

接下来我们来写两个实现了上面连个Interface的默认的mapping:SimpleStoredProcedureNameMapping和SimpleDbParameterNameMapping。他实际上实现了这样的Mapping:比如Table name为T_ABC_DEF(我经常用的命名方式:以T开头代表Table,名称大写并一下划线连接),那么对应的Stored procedure name分别为:sp_abc_def_s(Select), sp_abc_def_i(Insert), sp_abc_def_u(Update), sp_abc_def_d(delete)。如果Field name为ABC_123,那么对于Original version的Parameter name为o_abc_123(o代表Original),Current version的Parameter name为p_abc_123(p代表一般意义的Parameter)。

开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]using System;
开发自己的Data Access Application Block[上篇]
using System.Collections.Generic;
开发自己的Data Access Application Block[上篇]
using System.Text;
开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]
namespace Artech.ApplicationBlock.DataMapping
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
/**//// 


开发自己的Data Access Application Block[上篇]    
/// IStoredProcedureNameMapping defines the mapping between the data table name and the name of stored procedures to perform insertion, modification and deletion operation.
开发自己的Data Access Application Block[上篇]    
/// 
开发自己的Data Access Application Block[上篇]    public class SimpleStoredProcedureNameMapping:IStoredProcedureNameMapping
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]    
开发自己的Data Access Application Block[上篇]{
开发自己的Data Access Application Block[上篇]开发自己的Data Access Application Block[上篇]

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to disable background applications in Windows 11_Windows 11 tutorial to disable background applications How to disable background applications in Windows 11_Windows 11 tutorial to disable background applications May 07, 2024 pm 04:20 PM

1. Open settings in Windows 11. You can use Win+I shortcut or any other method. 2. Go to the Apps section and click Apps & Features. 3. Find the application you want to prevent from running in the background. Click the three-dot button and select Advanced Options. 4. Find the [Background Application Permissions] section and select the desired value. By default, Windows 11 sets power optimization mode. It allows Windows to manage how applications work in the background. For example, once you enable battery saver mode to preserve battery, the system will automatically close all apps. 5. Select [Never] to prevent the application from running in the background. Please note that if you notice that the program is not sending you notifications, failing to update data, etc., you can

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

How to convert deepseek pdf How to convert deepseek pdf Feb 19, 2025 pm 05:24 PM

DeepSeek cannot convert files directly to PDF. Depending on the file type, you can use different methods: Common documents (Word, Excel, PowerPoint): Use Microsoft Office, LibreOffice and other software to export as PDF. Image: Save as PDF using image viewer or image processing software. Web pages: Use the browser's "Print into PDF" function or the dedicated web page to PDF tool. Uncommon formats: Find the right converter and convert it to PDF. It is crucial to choose the right tools and develop a plan based on the actual situation.

Can't allow access to camera and microphone in iPhone Can't allow access to camera and microphone in iPhone Apr 23, 2024 am 11:13 AM

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

What does field mean in java What does field mean in java Apr 25, 2024 pm 10:18 PM

In Java, a "field" is a data member in a class or interface that is used to store data or state. The properties of field include: type (can be any Java data type), access rights, static (belongs to a class rather than an instance), final (immutable) and transient (not serialized). Field is used to store state information of a class or interface, such as storing object data and maintaining object state.

How does the Java reflection mechanism modify the behavior of a class? How does the Java reflection mechanism modify the behavior of a class? May 03, 2024 pm 06:15 PM

The Java reflection mechanism allows programs to dynamically modify the behavior of classes without modifying the source code. By operating the Class object, you can create instances through newInstance(), modify private field values, call private methods, etc. Reflection should be used with caution, however, as it can cause unexpected behavior and security issues, and has a performance overhead.

How to cross-domain iframe in vue How to cross-domain iframe in vue May 02, 2024 pm 10:48 PM

Ways to solve iframe cross-domain issues in Vue: CORS: Enable CORS support in the backend server and use XMLHttpRequest or fetch API to send CORS requests in Vue. JSONP: Dynamically load JSONP scripts in Vue using the JSONP endpoint in the backend server. Proxy server: Set up a proxy server to forward requests, use a third-party library (such as axios) in Vue to send requests and set the proxy server URL.

What does a memory stick look like? What does a memory stick look like? Apr 21, 2024 pm 01:01 PM

What does a computer memory module look like? This is an overview of the graphics card and memory module in the computer. The computer's independent graphics card is inserted into the graphics card slot, with a fan, and the memory module is inside the memory module slot on the computer's motherboard, shaped like a green rectangle. Laptop memory modules are different from desktop memory modules, and they cannot be used interchangeably. Appearance difference 1: Desktop memory, slender, 13-14 cm in length. 2: Notebook memory is shorter, about five centimeters. Memory is the bridge in the computer, responsible for data exchange between the processor and hardware such as hard disk, motherboard, and graphics card. The red circle on the way is the memory stick, next to the CPU fan and plugged into the memory stick. Look, a computer memory stick looks like this. Use a screwdriver to open the cover of the desktop computer. The red circle in the middle is the memory module. What is a memory stick?

See all articles