赞
踩
目录
本文主要讲解连接sqlserver的配置
- <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.3.4.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.dmdd</groupId>
- <artifactId>yifang</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>yifang</name>
- <description>yifang</description>
- <properties>
- <java.version>8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.5.3</version>
- </dependency>
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-generator</artifactId>
- <version>3.5.3</version>
- </dependency>
- <dependency>
- <groupId>com.microsoft.sqlserver</groupId>
- <artifactId>sqljdbc4</artifactId>
- <scope>system</scope>
- <version>4.0</version>
- <systemPath>${project.basedir}/src/main/java/com/lib/sqljdbc4-4.0.jar</systemPath>
- </dependency>
-
- <!-- <!– https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 –>-->
- <!-- <dependency>-->
- <!-- <groupId>com.microsoft.sqlserver</groupId>-->
- <!-- <artifactId>sqljdbc4</artifactId>-->
- <!-- <version>4.0</version>-->
- <!-- </dependency>-->
-
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
注:引用sqlserver比mysql多了如下依赖,并且跟mybatis plus的版本一致
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.5.3</version> </dependency>
注:SqlServer连接所需依赖需要以jar包的形式引入
<dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <scope>system</scope> <version>4.0</version> <systemPath>${project.basedir}/src/main/java/com/lib/sqljdbc4-4.0.jar</systemPath> </dependency>
- server:
- port: 8099
- # 配置数据源
- spring:
- datasource:
- driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
- url: jdbc:sqlserver://localhost:1433;databaseName=HLDB_Dev_012
- username: sa
- password: jly720609
- # 开启驼峰命名的实体类
- mybatis-plus:
- configuration:
- map-underscore-to-camel-case: true
-
- log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-
- mapper-locations: classpath:mapper/*.xml
- type-aliases-package: com/hl/hlkj/entity
- spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
- spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=HLDB_Dev_012
- spring.datasource.username=sa
- spring.datasource.password=jly720609
- package com.dmdd.yifang.config;
-
- import com.baomidou.mybatisplus.annotation.DbType;
- import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
- import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
- import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
-
- @Configuration
- //@MapperScan("scan.your.mapper.package")
- public class MybatisPlusConfig {
-
- /**
- * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
- */
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor() {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQL_SERVER2005));
- return interceptor;
- }
-
-
- }
注:需要改为对应数据库的名称,默认的是mysql使用的,sqlserver用不了
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQL_SERVER2005));
win+r打开
输入services.msc
开启代理
右键属性,选择连接,然后开启远程连接
alt+s开启搜索,搜索sqlserver配置管理器
如果有两个MSSQLSEVER协议代表sqlserver重复安装,需要卸载一个
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。