Spring boot+mvc架构搭建

直接来干货,第一步咱们得先配置springboot关联的java包,我这边把包稍微整理下,这里可能会有别人代码的痕迹,没错我也进行了参照。

<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>cn.qlq</groupId>
   <artifactId>springboot-ssm</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.1.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>

   <dependencies>
      <!-- 模板引擎 -->
      <dependency>
         <groupId>org.apache.velocity</groupId>
         <artifactId>velocity-engine-core</artifactId>
         <version>2.0</version>
      </dependency>


      <!-- 热部署 -->
      <!--        <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>-->
      <!-- 构建Restful Api文档 -->
      <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger2</artifactId>
         <version>2.9.2</version>
      </dependency>
      <!--引入swagger-ui包-->
      <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger-ui</artifactId>
         <version>2.9.2</version>
      </dependency>

      <!--引入swagger-bootstrap-ui包-->
      <dependency>
         <groupId>com.github.xiaoymin</groupId>
         <artifactId>swagger-bootstrap-ui</artifactId>
         <version>1.8.4</version>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      
      <!-- 设置Tomcat打包的时候不打包下面配置 -->
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-tomcat</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-devtools</artifactId>
      </dependency>
      <!-- spring-boot整合mybatis -->
      <!-- <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> 
         <version>1.1.1</version> </dependency> -->
      <!-- mysql驱动 -->

      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.6</version>
      </dependency>

      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-tx</artifactId>
         <version>4.3.7.RELEASE</version>
      </dependency>
      <!--导入加密包-->
      <dependency>
         <groupId>com.auth0</groupId>
         <artifactId>java-jwt</artifactId>
         <version>3.3.0</version>
      </dependency>
      <dependency>
         <groupId>io.dropwizard.metrics</groupId>
         <artifactId>metrics-healthchecks</artifactId>
         <version>3.1.2</version>
      </dependency>
        <dependency>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-core</artifactId>
            <version>3.1.2</version>
        </dependency>
      <!--上传至腾讯云服务器-->
      <dependency>
         <groupId>com.qcloud</groupId>
         <artifactId>cos_api</artifactId>
         <version>5.4.10</version>
      </dependency>
      <!--json配置-->
      <dependency>
         <groupId>com.alibaba</groupId>
         <artifactId>fastjson</artifactId>
         <version>1.2.47</version>
      </dependency>
      <!-- 基本配置 -->
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.9</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
         <version>2.5</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>jsp-api</artifactId>
         <version>2.0</version>
         <scope>provided</scope>
      </dependency>
<!--情感分析接口-->
      <dependency>
         <groupId>com.mashape.unirest</groupId>
         <artifactId>unirest-java</artifactId>
         <version>1.3.18</version>
      </dependency>
      <!-- Mybatis -->
      <dependency>
         <groupId>org.mybatis</groupId>
         <artifactId>mybatis</artifactId>
         <version>3.2.7</version>
      </dependency>
      <!-- Mybatis整合Spring -->
      <dependency>
         <groupId>org.mybatis</groupId>
         <artifactId>mybatis-spring</artifactId>
         <version>1.2.2</version>
      </dependency>
      <!-- 连接池 -->
      <dependency>
         <groupId>com.jolbox</groupId>
         <artifactId>bonecp-spring</artifactId>
         <version>0.8.0.RELEASE</version>
      </dependency>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-jdbc</artifactId>
      </dependency>
      <dependency>
         <groupId>com.github.pagehelper</groupId>
         <artifactId>pagehelper</artifactId>
         <version>5.1.2</version>
      </dependency>
      <dependency>
         <groupId>org.projectlombok</groupId>
         <artifactId>lombok</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.google.code.gson</groupId>
         <artifactId>gson</artifactId>
         <version>2.8.5</version>
      </dependency>
   </dependencies>
   <build>
      <!-- 配置了很多插件 -->
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
               <source>8</source>
               <target>8</target>
               <encoding>UTF-8</encoding>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
</project>

 

这上面呢也有许多包咱们用不上,这个你看着你所需要啥包就留下啥包就行了

接着咱们的配置mybatis的xml,这个咱因为也是个菜鸟所以只能给你看一下我参照别人的配置的

我尽量写得仔细些这样不会出现由于not found 出错 这个下图里面useMapper的配置

<?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="cacheEnabled" value="true" /> </settings> -->
   <!-- 只需要定义个别名,这个应该有 -->
   <settings>
      <setting name="callSettersOnNulls" value="true"/>
   </settings>
   
   <!-- springboot集成pageHelper(Java配置未注入的时候可以用下面配置) -->
<!--   <plugins>
      com.github.pagehelper为PageHelper类所在包名
      <plugin interceptor="com.github.pagehelper.PageInterceptor">
         使用下面的方式配置参数,后面会有所有的参数介绍
         <property name="helperDialect" value="mysql" />
      </plugin>
   </plugins> -->
</configuration>

到这里我们还剩mybatis的sqlxml没有配置了,接下来咱们继续配置 这是下图里SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.qlq.smartj.mapper.UserMapper">
   <select id="findAll" resultType="cn.qlq.smartj.mapper.UserMapper">
      select * from user
   </select>
   <select id="findByUsername" resultType="cn.qlq.smartj.bean.User">
      SELECT * FROM user
      where
      username=#{username}
    </select>
   <select id="findUserById" resultType="cn.qlq.smartj.bean.User">
        SELECT * FROM user
      where
      id=#{Id}
    </select>
</mapper>

这个是我项目里放置的位置  我想如果你喜欢就用在相似的位置如果不喜欢 就换位置

到这里mybatis的xml配置完了

第二步咱的链接上数据库

这个 暂时先不写 如有人想知道 在下面评论 我单发给你吧 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值