• 配置文件整合


    以下都是我日常会使用到的配置文件模板

    mybatis

    mybatis-config.xml

    
    DOCTYPE configuration
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "https://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
        
        <properties resource="db.properties">
            <property name="username" value="root"/>
        properties>
        <settings>
            <setting name="logImpl" value="STDOUT_LOGGING"/>
            <setting name="mapUnderscoreToCamelCase" value="true"/>
        settings>
        
        <typeAliases>
            <package name="com.wq.pojo"/>
        typeAliases>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            dataSource>
        environment>
    environments>
    
        <mappers>
            <mapper resource="com/wq/dao/BlogMapper.xml"/>
        mappers>
    configuration>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    随之而来的就会有一个

    db.propertis

    driver=com.mysql.cj.jdbc.Driver
    url=jdbc:mysql://127.0.0.1:3306/mybatis?serverTimezone=GMT&allowPublicKeyRetrieval=true&useSSL=false&characterEncoding=utf8
    username=root
    password=wang12345
    
    • 1
    • 2
    • 3
    • 4

    mapper.xml

    
    DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="com.wq.mapper.UserMapper">
        <select id="queryUser" resultType="user">
            select * from user
        select>
    mapper>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    获取sqlSession的工具类

    MybatisUtil

    package com.wq.utils;
    
    import org.apache.ibatis.io.Resources;
    import org.apache.ibatis.session.SqlSession;
    import org.apache.ibatis.session.SqlSessionFactory;
    import org.apache.ibatis.session.SqlSessionFactoryBuilder;
    
    import java.io.IOException;
    import java.io.InputStream;
    
    public class MybatisUtil {
        static SqlSessionFactory sqlSessionFactory;
        static {
            try {
                //使用mybatis的第一步 获取sqlSessionFactory对象
                String resource = "mybatis-config.xml";
                InputStream inputStream = Resources.getResourceAsStream(resource);
                sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //既然有了 SqlSessionFactory,顾名思义,我们可以从中获得 SqlSession 的实例。
        //SqlSession 提供了在数据库执行 SQL 命令所需的所有方法。
        //你可以通过 SqlSession 实例来直接执行已映射的 SQL 语句。
        public static SqlSession getSqlSession(){
            return sqlSessionFactory.openSession();
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    spring

    applicationContext.xml

    
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    		https://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop
    		https://www.springframework.org/schema/aop/spring-aop.xsd
    		http://www.springframework.org/schema/context
    		https://www.springframework.org/schema/context/spring-context.xsd">
        
        <context:component-scan base-package="com"/>
        <context:annotation-config/>
    
        <bean id="userService" class="com.wq.service.UserServiceImpl"/>
        
        <aop:aspectj-autoproxy/>
    beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    web

    web.xml

    
    
    <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
                          https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
             version="6.0"
             metadata-complete="true">
    
    
      <servlet>
        <servlet-name>helloservlet-name>
        <servlet-class>com.wq.servlet.HelloServletservlet-class>
      servlet>
      <servlet>
        <servlet-name>errorservlet-name>
        <servlet-class>com.wq.servlet.ErrorServletservlet-class>
      servlet>
    
      <servlet-mapping>
        <servlet-name>helloservlet-name>
        <url-pattern>/hellourl-pattern>
      servlet-mapping>
      <servlet-mapping>
        <servlet-name>errorservlet-name>
        <url-pattern>/*url-pattern>
      servlet-mapping>
    
      
    
    
    
    
    web-app>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62

    部分maven依赖

    junit

    <dependency>
    	<groupId>junitgroupId>
    	<artifactId>junitartifactId>
        <version>4.13.2version>
    dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    mysql-jdbc

            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
                <version>8.0.33version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    mybatis

            <dependency>
                <groupId>org.mybatisgroupId>
                <artifactId>mybatisartifactId>
                <version>3.5.13version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    spring-jdbc

            
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jdbcartifactId>
                <version>6.0.11version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    aspectjweaver

            
            
            <dependency>
                <groupId>org.aspectjgroupId>
                <artifactId>aspectjweaverartifactId>
                <version>1.9.19version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    mybatis-spring

            
            <dependency>
                <groupId>org.mybatisgroupId>
                <artifactId>mybatis-springartifactId>
                <version>3.0.2version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    lombok

            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <version>1.18.24version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    资源导出过滤问题

    maven中添加以下配置

        <build>
            <resources>
                <resource>
                    <directory>src/main/resourcesdirectory>
                    <includes>
                        <include>**/*.propertiesinclude>
                        <include>**/*.xmlinclude>
                    includes>
                    <filtering>truefiltering>
                resource>
                <resource>
                    <directory>src/main/javadirectory>
                    <includes>
                        <include>**/*.propertiesinclude>
                        <include>**/*.xmlinclude>
                    includes>
                    <filtering>truefiltering>
                resource>
            resources>
        build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
  • 相关阅读:
    B树及插入操作介绍
    当发布/订阅模式遇上.NET
    GPT-4o多模态大模型的架构设计
    优化理论笔记
    mysql主从同步
    软件设计师_数据库系统_学习笔记
    Redis+SpringBoot企业版集群实战------【华为云版】
    录视频背景杂乱无章怎么办,替换背景一下搞定
    【推荐系统->论文阅读】Wide&Deep模型
    Python: 10大Web框架简介
  • 原文地址:https://blog.csdn.net/m0_63962653/article/details/133110361