java相关部分配置(java配置常出现的问题)

  本篇文章为你整理了java相关部分配置(java配置常出现的问题)的详细内容,包含有java配置文件有哪些 java配置常出现的问题 java要配置哪些环境变量 java中配置文件的作用 java相关部分配置,希望能帮助你了解 java相关部分配置。

   mybatis逆向工程、mybatis-plus代码生成器、swagger配置类、正则表达式、git.ignore忽略文件、SSM框架脚手架、Springboot数据库配置、web文件格式、build过滤、log4j日志配置

  
① generator.properties

  

jdbc.driverLocation=D:/testDir/Maven/repository_g/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar

 

  jdbc.driver >

  ② generatorConfig.xml

  

 ?xml version="1.0" encoding="UTF-8"? 

 

   !DOCTYPE generatorConfiguration

   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"

   generatorConfiguration

   !--指定mysql数据库驱动--

   !-- classPathEntry location="E://repository-p2p//mysql//mysql-connector-java//5.1.43//mysql-connector-java-5.1.43.jar"/ --

   !--导入属性配置--

   properties resource="generator.properties" /properties

   !--指定特定数据库的jdbc驱动jar包的位置--

   classPathEntry location="${jdbc.driverLocation}"/

   context id="default" targetRuntime="MyBatis3"

   !-- optional,旨在创建class时,对注释进行控制,false生成注释,true无注释 --

   commentGenerator

   property name="suppressDate" value="false"/

   property name="suppressAllComments" value="false"/

   /commentGenerator

   !--jdbc的数据库连接 --

   jdbcConnection

   driver connectionURL="${jdbc.connectionURL}"

   userId="${jdbc.userId}"

   password="${jdbc.password}"

   /jdbcConnection

  
!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类

   targetPackage 指定生成的model生成所在的包名

   targetProject 指定在该项目下所在的路径指定生成到的工程名称

   javaModelGenerator targetPackage="com.bjpowernode.crm.workbench.transaction.model"

   targetProject="D:/testDir/javaee/projects/crm/crm001/src/main/java"

   !-- 是否允许子包,即targetPackage.schemaName.tableName --

   property name="enableSubPackages" value="false"/

   !-- 是否对model添加 构造函数 true添加,false不添加--

   property name="constructorBased" value="false"/

   !-- 是否对类CHAR类型的列的数据进行trim操作 --

   property name="trimStrings" value="true"/

   !-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 --

   property name="immutable" value="false"/

   /javaModelGenerator

   !--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 --

   sqlMapGenerator targetPackage="com.bjpowernode.crm.workbench.transaction.mapper"

   targetProject="D:/testDir/javaee/projects/crm/crm001/src/main/java"

   property name="enableSubPackages" value="false"/

   /sqlMapGenerator

   !-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码

   type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象

   type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象

   type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口

   javaClientGenerator targetPackage="com.bjpowernode.crm.workbench.transaction.mapper"

   targetProject="D:/testDir/javaee/projects/crm/crm001/src/main/java" type="XMLMAPPER"

   property name="enableSubPackages" value="true"/

   /javaClientGenerator

   !-- 生成对应的表,注意会覆盖文件 --

   table tableName="tbl_transaction" domainObjectName="Transaction"

   enableCountByExample="false" enableUpdateByExample="false"

   enableDeleteByExample="false" enableSelectByExample="false"

   selectByExampleQueryId="false"

   /table

   /context

   /generatorConfiguration

  

 

  二、mybatis-plus代码生成器

  

package com.example.demo;

 

  import com.baomidou.mybatisplus.annotation.DbType;

  import com.baomidou.mybatisplus.annotation.IdType;

  import com.baomidou.mybatisplus.generator.AutoGenerator;

  import com.baomidou.mybatisplus.generator.config.DataSourceConfig;

  import com.baomidou.mybatisplus.generator.config.GlobalConfig;

  import com.baomidou.mybatisplus.generator.config.PackageConfig;

  import com.baomidou.mybatisplus.generator.config.StrategyConfig;

  import com.baomidou.mybatisplus.generator.config.rules.DateType;

  import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

  import org.junit.Test;

   * @author

   * @since 2018/12/13

  public class CodeGenerator {

   @Test

   public void run() {

   // 1、创建代码生成器

   AutoGenerator mpg = new AutoGenerator();

   // 2、全局配置

   GlobalConfig gc = new GlobalConfig();

   String projectPath = System.getProperty("user.dir");

   gc.setOutputDir(projectPath + "/src/main/java");

   gc.setAuthor("testjava");

   gc.setOpen(false); //生成后是否打开资源管理器

   gc.setFileOverride(false); //重新生成时文件是否覆盖

   gc.setServiceName("%sService"); //去掉Service接口的首字母I

   gc.setIdType(IdType.ID_WORKER); //主键策略

   gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型

   gc.setSwagger2(true);//开启Swagger2模式

   mpg.setGlobalConfig(gc);

   // 3、数据源配置

   DataSourceConfig dsc = new DataSourceConfig();

   dsc.setUrl("jdbc:mysql://localhost:3306/guli");

   dsc.setDriverName("com.mysql.jdbc.Driver");

   dsc.setUsername("root");

   dsc.setPassword("root");

   dsc.setDbType(DbType.MYSQL);

   mpg.setDataSource(dsc);

   // 4、包配置

   PackageConfig pc = new PackageConfig();

   pc.setModuleName("edu"); //模块名

   pc.setParent("com.example.demo");

   pc.setController("controller");

   pc.setEntity("entity");

   pc.setService("service");

   pc.setMapper("mapper");

   mpg.setPackageInfo(pc);

   // 5、策略配置

   StrategyConfig strategy = new StrategyConfig();

   strategy.setInclude("edu_teacher");

   strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略

   strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀

   strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略

   strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作

   strategy.setRestControllerStyle(true); //restful api风格控制器

   strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符

   mpg.setStrategy(strategy);

  
import com.google.common.base.Predicates;

  import org.springframework.context.annotation.Bean;

  import org.springframework.context.annotation.Configuration;

  import springfox.documentation.builders.ApiInfoBuilder;

  import springfox.documentation.builders.PathSelectors;

  import springfox.documentation.service.ApiInfo;

  import springfox.documentation.service.Contact;

  import springfox.documentation.spi.DocumentationType;

  import springfox.documentation.spring.web.plugins.Docket;

  import springfox.documentation.swagger2.annotations.EnableSwagger2;

  @Configuration

  @EnableSwagger2

  public class SwaggerConfig {

   @Bean

   public Docket webApiConfig(){

   return new Docket(DocumentationType.SWAGGER_2)

   .groupName("webApi")

   .apiInfo(webApiInfo())

   .select()

   .paths(Predicates.not(PathSelectors.regex("/admin/.*")))

   .paths(Predicates.not(PathSelectors.regex("/error.*")))

   .build();

   private ApiInfo webApiInfo(){

   return new ApiInfoBuilder()

   .title("标题")

   .description("测试接口页面")

   .version("1.0")

   .contact(new Contact("jegole", "http://localhost.com:8001", "123@qq.com"))

   .build();

  

 

  四、正则表达式

  

一、校验数字的表达式

 

  1. 数字:^[0-9]*$

  2. n位的数字:^\d{n}$

  3. 至少n位的数字:^\d{n,}$

  4. m-n位的数字:^\d{m,n}$

  5. 零和非零开头的数字:^(0[1-9][0-9]*)$

  6. 非零开头的最多带两位小数的数字:^([1-9][0-9]*)+(.[0-9]{1,2})?$

  7. 带1-2位小数的正数或负数:^(\-)?\d+(\.\d{1,2})?$

  8. 正数、负数、和小数:^(\-\+)?\d+(\.\d+)?$

  9. 有两位小数的正实数:^[0-9]+(.[0-9]{2})?$

  10. 有1~3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$

  11. 非零的正整数:^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$

  12. 非零的负整数:^\-[1-9][]0-9"*$ 或 ^-[1-9]\d*$

  13. 非负整数:^(([1-9]\d*)0)$

  14. 非正整数:^-[1-9]\d*0$ 或 ^((-\d+)(0+))$

  15. 非负浮点数:^\d+(\.\d+)?$ 或 ^[1-9]\d*\.\d*0\.\d*[1-9]\d*0?\.0+0$

  16. 非正浮点数:^((-\d+(\.\d+)?)(0+(\.0+)?))$ 或 ^(-([1-9]\d*\.\d*0\.\d*[1-9]\d*))0?\.0+0$

  17. 正浮点数:^[1-9]\d*\.\d*0\.\d*[1-9]\d*$ 或 ^(([0-9]+\.[0-9]*[1-9][0-9]*)([0-9]*[1-9][0-9]*\.[0-9]+)([0-9]*[1-9][0-9]*))$

  18. 负浮点数:^-([1-9]\d*\.\d*0\.\d*[1-9]\d*)$ 或 ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)([0-9]*[1-9][0-9]*\.[0-9]+)([0-9]*[1-9][0-9]*)))$

  19. 浮点数:^(-?\d+)(\.\d+)?$ 或 ^-?([1-9]\d*\.\d*0\.\d*[1-9]\d*0?\.0+0)$

  
9. 中文、英文、数字包括下划线:^[\u4E00-\u9FA5A-Za-z0-9_]+$

  10. 中文、英文、数字但不包括下划线等符号:^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$

  11. 可以输入含有^% =?$\"等字符:[^% =?$\x22]+ 12 禁止输入含有~的字符:[^~\x22]+

  三、特殊需求表达式

  
5. 电话号码("XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX):^(\(\d{3,4}-)\d{3.4}-)?\d{7,8}$

  6. 国内电话号码(0511-4405222、021-87888822):\d{3}-\d{8}\d{4}-\d{7}

  7. 身份证号(15位、18位数字):^\d{15}\d{18}$

  
8. 短身份证号码(数字、字母x结尾):^([0-9]){7,18}(xX)?$ 或 ^\d{8,18}[0-9x]{8,18}[0-9X]{8,18}?$

  
9. 帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$

  
11. 强密码(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间):^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$

  
16. 1.有四种钱的表示形式我们可以接受:"10000.00" 和 "10,000.00", 和没有 "分" 的 "10000" 和 "10,000":^[1-9][0-9]*$

  17. 2.这表示任意一个不以0开头的数字,但是,这也意味着一个字符"0"不通过,所以我们采用下面的形式:^(0[1-9][0-9]*)$

  18. 3.一个0或者一个不以0开头的数字.我们还可以允许开头有一个负号:^(0-?[1-9][0-9]*)$

  19. 4.这表示一个0或者一个可能为负的开头不为0的数字.让用户以0开头好了.把负号的也去掉,因为钱总不能是负的吧.下面我们要加的是说明可能的小数部分:^[0-9]+(.[0-9]+)?$

  20. 5.必须说明的是,小数点后面至少应该有1位数,所以"10."是不通过的,但是 "10" 和 "10.2" 是通过的:^[0-9]+(.[0-9]{2})?$

  21. 6.这样我们规定小数点后面必须有两位,如果你认为太苛刻了,可以这样:^[0-9]+(.[0-9]{1,2})?$

  22. 7.这样就允许用户只写一位小数.下面我们该考虑数字中的逗号了,我们可以这样:^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$

  23 8.1到3个数字,后面跟着任意个 逗号+3个数字,逗号成为可选,而不是必须:^([0-9]+[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$

  24. 备注:这就是最终结果了,别忘了"+"可以用"*"替代如果你觉得空字符串也可以接受的话(奇怪,为什么?)最后,别忘了在用函数时去掉去掉那个反斜杠,一般的错误都在这里

  25. xml文件:^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[xX][mM][lL]$

  26. 中文字符的正则表达式:[\u4e00-\u9fa5]

  27. 双字节字符:[^\x00-\xff] (包括汉字在内,可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1))

  28. 空白行的正则表达式:\n\s*\r (可以用来删除空白行)

  29. HTML标记的正则表达式: (\S*?)[^ ]* .*? /\1 .*? / (网上流传的版本太糟糕,上面这个也仅仅能部分,对于复杂的嵌套标记依旧无能为力)

  30. 首尾空白字符的正则表达式:^\s*\s*$或(^\s*)(\s*$) (可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式)

  31. 腾讯QQ号:[1-9][0-9]{4,} (腾讯QQ号从10000开始)

  32. 中国邮政编码:[1-9]\d{5}(?!\d) (中国邮政编码为6位数字)

  33. IP地址:\d+\.\d+\.\d+\.\d+ (提取IP地址时有用)

  34. IP地址:((?:(?:25[0-5]2[0-4]\\d[01]?\\d?\\d)\\.){3}(?:25[0-5]2[0-4]\\d[01]?\\d?\\d))

  附:正则表达式语法大全:https://www.runoob.com/regexp/regexp-tutorial.html

  

 

  五、git.ignore忽略文件

  

# Compiled class file

 

  *.class

  # Log file

  *.log

  # BlueJ files

  *.ctxt

  # Mobile Tools for Java (J2ME)

  .mtj.tmp/

  # Package Files #

  *.jar

  *.war

  *.nar

  *.ear

  *.zip

  *.tar.gz

  *.rar

  # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml

  hs_err_pid*

  .classpath

  .project

  .settings

  target

  .idea

  *.iml

  

 

  六、SSM框架

  1.第一套

  ① 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 com.jegole /groupId

   artifactId re-ssm /artifactId

   version 1.0-SNAPSHOT /version

   packaging war /packaging

   dependencies

   !-- junit-- !-- lombok--

   dependency

   groupId junit /groupId

   artifactId junit /artifactId

   version 4.11 /version

   /dependency

   dependency

   groupId org.projectlombok /groupId

   artifactId lombok /artifactId

   version 1.18.22 /version

   /dependency

   !-- 数据库驱动-- !-- 数据库连接池--

   !-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --

   dependency

   groupId mysql /groupId

   artifactId mysql-connector-java /artifactId

   version 5.1.47 /version

   /dependency

   !-- https://mvnrepository.com/artifact/com.mchange/c3p0 --

   dependency

   groupId com.mchange /groupId

   artifactId c3p0 /artifactId

   version 0.9.5.5 /version

   /dependency

   !-- servlet -- !-- jsp-- !-- jstl--

   !-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --

   dependency

   groupId javax.servlet /groupId

   artifactId javax.servlet-api /artifactId

   version 4.0.1 /version

   /dependency

   !-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api --

   dependency

   groupId javax.servlet.jsp /groupId

   artifactId jsp-api /artifactId

   version 2.2 /version

   /dependency

   !-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl --

   dependency

   groupId javax.servlet.jsp.jstl /groupId

   artifactId jstl-api /artifactId

   version 1.2 /version

   /dependency

   dependency

   groupId taglibs /groupId

   artifactId standard /artifactId

   version 1.1.2 /version

   /dependency

   !-- mybatis-- !-- mybatis-spring--

   !-- https://mvnrepository.com/artifact/org.mybatis/mybatis --

   dependency

   groupId org.mybatis /groupId

   artifactId mybatis /artifactId

   version 3.5.10 /version

   /dependency

   !-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring --

   dependency

   groupId org.mybatis /groupId

   artifactId mybatis-spring /artifactId

   version 2.0.7 /version

   /dependency

   !-- spring-webmvc-- !-- spring-jdbc--

   !-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --

   dependency

   groupId org.springframework /groupId

   artifactId spring-webmvc /artifactId

   version 5.3.20 /version

   /dependency

   !-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --

   dependency

   groupId org.springframework /groupId

   artifactId spring-jdbc /artifactId

   version 5.3.10 /version

   /dependency

  


jdbc.driver=com.mysql.jdbc.Driver

 

  jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=false useUnicode=true characterEncoding=utf8

  jdbc.username=root

  jdbc.password=123456

  

 

  ③ mybatis-config.xml

  

 ?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"

   configuration

   typeAliases

   package name="com.jegole.pojo"/

   /typeAliases

   mappers

   mapper resource="com/jegole/dao/BookMapper.xml"/

   /mappers

   /configuration

  

 

  ④ spring-dao.xml

  

 ?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: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/context

   http://www.springframework.org/schema/context/spring-context.xsd"

   context:property-placeholder location="classpath:database.properties"/

   bean id="dataSource"

   property name="driverClass" value="${jdbc.driver}"/

   property name="jdbcUrl" value="${jdbc.url}"/

   property name="user" value="${jdbc.username}"/

   property name="password" value="${jdbc.password}"/

   property name="maxPoolSize" value="30"/

   property name="minPoolSize" value="10"/

   property name="autoCommitOnClose" value="false"/

   property name="checkoutTimeout" value="10000"/

   property name="acquireRetryAttempts" value="2"/

   /bean

   bean id="sqlSessionFactory"

   property name="dataSource" ref="dataSource"/

   property name="configLocation" value="classpath:mybatis-config.xml"/

   /bean

   bean

   property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/

   property name="basePackage" value="com.jegole.dao"/

   /bean

   /beans

  

 

  ⑤ spring-service.xml

  

 ?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: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/context

   http://www.springframework.org/schema/context/spring-context.xsd"

   context:component-scan base-package="com.jegole.service"/

   bean id="BookServiceImpl"

   property name="bookMapper" ref="bookMapper"/

   /bean

   bean id="transactionManger"

   property name="dataSource" ref="dataSource"/

   /bean

   /beans

  

 

  ⑥ spring-mvc.xml

  

 ?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:context="http://www.springframework.org/schema/context"

   xmlns:mvc="http://www.springframework.org/schema/mvc"

   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"

   mvc:annotation-driven/

   mvc:default-servlet-handler/

   bean

   property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/

   property name="prefix" value="/WEB-INF/jsp/"/

   property name="suffix" value=".jsp"/

   /bean

   context:component-scan base-package="com.jegole.controller"/

   /beans

  

 

  ⑦ applicationContext.xml

  

 ?xml version="1.0" encoding="UTF-8"? 

 

   beans xmlns="http://www.springframework.org/schema/beans"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="http://www.springframework.org/schema/beans

   http://www.springframework.org/schema/beans/spring-beans.xsd"

   import resource="spring-dao.xml"/

   import resource="spring-service.xml"/

   import resource="spring-mvc.xml"/

   /beans

  

 

  2.第二套

  ① 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 com.bjpowernode.crm /groupId

   artifactId crm /artifactId

   version 1.0-SNAPSHOT /version

   packaging war /packaging

   name crm Maven Webapp /name

   !-- FIXME change it to the projects website --

   url http://www.example.com /url

   properties

   project.build.sourceEncoding UTF-8 /project.build.sourceEncoding

   maven.compiler.source 1.7 /maven.compiler.source

   maven.compiler.target 1.7 /maven.compiler.target

   /properties

   dependencies

   dependency

   groupId junit /groupId

   artifactId junit /artifactId

   version 4.11 /version

   scope test /scope

   /dependency

   !-- MySQL数据库连接驱动 --

   dependency

   groupId mysql /groupId

   artifactId mysql-connector-java /artifactId

   version 5.1.43 /version

   /dependency

   !-- JDBC数据源连接池 --

   dependency

   groupId com.alibaba /groupId

   artifactId druid /artifactId

   version 1.1.1 /version

   /dependency

   !-- MyBatis框架依赖 --

   dependency

   groupId org.mybatis /groupId

   artifactId mybatis /artifactId

   version 3.4.1 /version

   /dependency

   !-- Spring框架依赖的JAR配置 --

   dependency

   groupId org.springframework /groupId

   artifactId spring-context /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-aop /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-core /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-beans /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-jdbc /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-tx /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-web /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-webmvc /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   dependency

   groupId org.springframework /groupId

   artifactId spring-oxm /artifactId

   version 4.3.9.RELEASE /version

   /dependency

   !-- Spring AOP支持--

   dependency

   groupId org.aspectj /groupId

   artifactId aspectjweaver /artifactId

   version 1.8.9 /version

   /dependency

   !-- MyBatis与Spring整合依赖 --

   dependency

   groupId org.mybatis /groupId

   artifactId mybatis-spring /artifactId

   version 1.3.0 /version

   /dependency

   !-- servlet及jstl标签库依赖的JAR配置 --

   dependency

   groupId javax.servlet /groupId

   artifactId javax.servlet-api /artifactId

   version 3.1.0 /version

   /dependency

   dependency

   groupId javax.servlet.jsp.jstl /groupId

   artifactId jstl-api /artifactId

   version 1.2 /version

   /dependency

   dependency

   groupId org.apache.taglibs /groupId

   artifactId taglibs-standard-spec /artifactId

   version 1.2.1 /version

   /dependency

   dependency

   groupId org.apache.taglibs /groupId

   artifactId taglibs-standard-impl /artifactId

   version 1.2.1 /version

   /dependency

   !-- 加载jackson插件依赖 --

   dependency

   groupId com.fasterxml.jackson.core /groupId

   artifactId jackson-core /artifactId

   version 2.7.3 /version

   /dependency

   dependency

   groupId com.fasterxml.jackson.core /groupId

   artifactId jackson-databind /artifactId

   version 2.7.3 /version

   /dependency

   dependency

   groupId com.fasterxml.jackson.core /groupId

   artifactId jackson-annotations /artifactId

   version 2.7.3 /version

   /dependency

   !--poi依赖--

   dependency

   groupId org.apache.poi /groupId

   artifactId poi /artifactId

   version 3.15 /version

   /dependency

   !-- 文件上传 --

   dependency

   groupId commons-fileupload /groupId

   artifactId commons-fileupload /artifactId

   version 1.3.1 /version

   /dependency

   !-- Log4j2依赖的JAR配置 --

   dependency

   groupId org.apache.logging.log4j /groupId

   artifactId log4j-api /artifactId

   version 2.3 /version

   /dependency

   dependency

   groupId org.apache.logging.log4j /groupId

   artifactId log4j-core /artifactId

   version 2.3 /version

   /dependency

   dependency

   groupId org.apache.logging.log4j /groupId

   artifactId log4j-jcl /artifactId

   version 2.3 /version

   /dependency

   /dependencies

   build

   finalName crm /finalName

   pluginManagement !-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --

   plugins

   plugin

   artifactId maven-clean-plugin /artifactId

   version 3.1.0 /version

   /plugin

   !-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --

   plugin

   artifactId maven-resources-plugin /artifactId

   version 3.0.2 /version

   /plugin

   plugin

   artifactId maven-compiler-plugin /artifactId

   version 3.8.0 /version

   /plugin

   plugin

   artifactId maven-surefire-plugin /artifactId

   version 2.22.1 /version

   /plugin

   plugin

   artifactId maven-war-plugin /artifactId

   version 3.2.2 /version

   /plugin

   plugin

   artifactId maven-install-plugin /artifactId

   version 2.5.2 /version

   /plugin

   plugin

   artifactId maven-deploy-plugin /artifactId

   version 2.8.2 /version

   /plugin

   /plugins

   /pluginManagement

   /build

   /project

  

 

  ② mybatis-config.xml

  

 ?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"

   configuration

   settings

   setting name="logImpl" value="STDOUT_LOGGING"/

   /settings

   typeAliases

   package name="com.bjpowernode.crm.model"/

   /typeAliases

   mappers

   package name="com.bjpowernode.crm.mapper"/

   /mappers

   /configuration

  

 

  ③ applicationContext-datasource.xml

  

 ?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:aop="http://www.springframework.org/schema/aop"

   xmlns:context="http://www.springframework.org/schema/context"

   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-4.3.xsd

   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd

   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"

   !-- 配置数据源 --

   bean id="dataSource"

   property name="driverClassName" value="com.mysql.jdbc.Driver"/

   property name="username" value="root"/

   property name="password" value="123456"/

   property name="url" value="jdbc:mysql://127.0.0.1:3306/crm2008?useSSL=false amp;useUnicode=true amp;characterEncoding=UTF-8"/

   /bean

   !-- 配置SqlSessionFactory --

   bean id="sqlSessionFactory"

   !-- 必须注入属性dataSource --

   property name="dataSource" ref="dataSource"/

   !-- 如果mybatis没有特殊的配置(比如别名等),configLocation可以省去 ;否。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: