1. 程式人生 > 實用技巧 >nasm and golink create a DLL x86

nasm and golink create a DLL x86

1.進行專案需求分析,建立資料庫模型並建立資料表,在此不做詳細描述;

2.建立基於Maven的Web專案,專案基本結構如下:

3.pom.xml所需的依賴如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>mybatis</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding
>UTF-8</project.build.sourceEncoding> <junit.version>4.13</junit.version> <spring.version>5.2.8.RELEASE</spring.version> <mybatis.version>3.5.5</mybatis.version> <mybatis.spring.version>2.0.5</mybatis.spring.version> <
commons-dbcp.version>1.4</commons-dbcp.version> <jstl.version>1.2</jstl.version> <log4j.version>1.2.17</log4j.version> <fastjson.version>1.2.73</fastjson.version> <slf4j.version>1.7.30</slf4j.version> <jackson.version>1.9.13</jackson.version> <commons-fileupload.version>1.4</commons-fileupload.version> <commons-io.version>2.7</commons-io.version> <commons-codec.version>1.15</commons-codec.version> <aspectjweaver.version>1.9.6</aspectjweaver.version> <druid.version>1.1.23</druid.version> </properties> <dependencies> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> </dependency> <!-- Junit測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- spring包 core、web、oxm、tx、jdbc、webmvc、aop、context、test --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- mybatis核心包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- mybatis/spring包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <!-- 匯入Mysql資料庫連結jar包 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.20</version> </dependency> <!-- 匯入dbcp/druid的jar包,用來在applicationContext.xml中配置資料庫 --> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>${commons-dbcp.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- JSTL標籤庫 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <!-- 日誌檔案管理包 --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.13.3</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.13.3</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.13.3</version> </dependency> <!-- 格式化物件,方便輸出日誌 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- json和bean之間相互轉換 --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency> <!-- 上傳元件包 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> </dependency> <!-- 面向切面程式設計 --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectjweaver.version}</version> </dependency> <!-- Servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
pom.xml

4.日誌輸出檔案配置

### set log levels ###
log4j.rootLogger = DEBUG,Console,File

###  輸出到控制檯  ###
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%d{yy/MM/dd HH:mm:ss:SSS}]-[%t]-%p --- [%100.100l] --- %m%n

### 輸出到日誌檔案 ###
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.File=${project}src\\main\\resources\\out\\app.log
log4j.appender.File.MaxFileSize=10MB
log4j.appender.File.Threshold=ALL
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=[%d{yy/MM/dd HH:mm:ss:SSS}] - [%t] - %p --- [%100.100l] --- %m%n
log4j.properties

5.建立資料庫連線的基本配置檔案,建議使用外部配置,便於修改(此處所給的是阿里巴巴的德魯伊資料來源相關的jdbc配置):

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/hrm_db?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true
#使用者名稱不可鍵不可為username 否則 會報錯 Access denied for user 'KeLuo'@'localhost' (using password: YES)
name=sahara
password=12345
initialSize=100
maxActive=100
maxWait=3000
minIdle=5
druid.properties

6.Mybatis框架的基本配置(因與Spring整合,其內的環境配置均捨棄不寫,相關配置如資料來源等在Spring的基本配置檔案中配置)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- mybats的主配置檔案 -->
<configuration>
    <!--配置延遲載入策略-->
    <settings>
        <!-- 全域性對映器啟用或禁用快取
        <setting name="cacheEnable" value="true"/> -->
        <!-- 允許JDBC支援生成的鍵,需要適當的驅動。 -->
        <setting name="useGeneratedKeys" value="true"/>
        <!-- 配置預設的執行器 -->
        <setting name="defaultExecutorType" value="REUSE"/>
        <!--開啟延遲載入開關-->
        <setting name="lazyLoadingEnabled" value="true"/>
        <!--將積極載入改為訊息載入,即按需載入-->
        <setting name="aggressiveLazyLoading" value="false"/>
        <!-- 設定超時時間,決定驅動等待一個數據庫響應的時間 -->
        <setting name="defaultStatementTimeout" value="25000"/>
    </settings>
    <!--配置別名-->
    <typeAliases>
        <!--<typeAlias type="com.sahara.entity.Role" alias="Role" />-->
        <package name="com.sahara.domain"/>
    </typeAliases>
    <!--指定對映配置檔案(每個Dao獨立的配置檔案)的位置-->
    <mappers>
        <!--<mapper resource="com/sahara/mappers/IRoleDao.xml"></mapper>-->
        <package name="com.sahara.dao"/>
    </mappers>
</configuration>
mybatisConfig.xml

7.Spring的基本配置檔案:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://mybatis.org/schema/mybatis-spring
       http://mybatis.org/schema/mybatis-spring/mybatis-spring.xsd">

    <!-- 掃描base-package包下的java檔案,有Spring相關注解的類,則把這些類註冊為Spring的bean -->
    <context:component-scan base-package="com.sahara"/>

    <!-- 使用PropertyOverrideConfigurer後處理器載入資料來源引數 -->
    <context:property-placeholder location="classpath:druid.properties"/>

    <!-- 配置druid資料來源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${driverClassName}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${name}"/>
        <property name="password" value="${password}"/>
        <property name="initialSize" value="${initialSize}"/>
        <!-- 連線池最大數量 -->
        <property name="maxActive" value="${maxActive}"/>
        <!-- 獲取連線最大等待時間 -->
        <property name="maxWait" value="${maxWait}"/>
        <!-- 連線池最小空閒 -->
        <property name="minIdle" value="${minIdle}"/>
    </bean>

    <!-- 配置SqlSessionFactory,org.mybatis.spring.SqlSessionFactory是Mybatis社群開發用於整合Spring的bean -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
          p:dataSource-ref="dataSource"
          p:configLocation="classpath:mybatisConfig.xml"/>

    <!-- 配置SqlSessionTemplate
    <bean class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg ref="sqlSessionFactory"/>
    </bean> -->

    <!--  -->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"
          p:basePackage="com.sahara.dao"
          p:annotationClass="org.springframework.stereotype.Repository"
          p:sqlSessionFactoryBeanName="sqlSessionFactory"
    />

    <!-- JDBC事務管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
          p:dataSource-ref="dataSource"/>

    <!-- 啟用annotation註解方式事務管理 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
applicationContext.xml

8.Spring MVC的基本配置檔案

<?xml version="1.0" encoding="utf-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">



    <!-- 自動掃描base-package包下用了@Controller註解的類並將其註冊為Spring的Controller -->
    <context:component-scan base-package="com.sahara.controller"/>

    <!-- 設定預設配置方案 -->
    <mvc:annotation-driven/>

    <!-- 檢視解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 字首 -->
        <property name="prefix">
            <value>/WEB-INF/content</value>
        </property>
        <!-- 字尾 -->
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>
springmvc-config.xml

9.web配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <listener>
        <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>
    <filter>
        <filter-name>log4jServletFilter</filter-name>
        <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>log4jServletFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <!-- end -->
    <!-- 配置Spring核心監聽器,預設會以/WEB-INF/applicationContext.xml作為配置檔案 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- contextConfigLocation引數用來指定Spring的配置檔案 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- 定義Spring MVC的前端控制器 -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- 讓Spring MVC的前端控制器攔截所有請求 -->
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- 編碼過濾器 --><filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
web.xml




10.根據資料庫建立相應的實體類(可使用Lombok外掛以生成Getter與Setter方法)

11.使用Mybatis技術建立資料訪問層(包括介面及XML檔案)

12.建立測試類對資料訪問層進行測試,測試類應引入相關配置,(若無@Run With 與 ContextConfiguration註解,則其內部使用註解會報Null PointException)

package com.sahara.dao;

import com.sahara.dao.UserDao;
import com.sahara.domain.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:applicationContext.xml"})
@Transactional
public class UserTest {

    @Autowired
    public UserDao userDao;

    @Test
    public void testselectById() {
        User user = userDao.selectById(1);
        System.err.println(user);
    }
}

有關SSM與junit整合的配置請訪問:

https://www.cnblogs.com/gkaigk1987/articles/5367569.html

https://blog.csdn.net/CarryBest/article/details/71123493

https://blog.csdn.net/qq_32786873/article/details/56480880

暫時到這裡,更多學習之後會更新。