SpringMVC+Spring+mybatis 项目实践

SpringMVC+Spring+mybatis 项目实践

 

1.生成项目

尝试了两种方法,一、利用https://start.spring.io/生成项目解压在,再用IDEA打开

 

二、是基于maven

 

注意配置maven的相关信息,前提需要自己安装maven

 

 

遇到的问题:项目生成后,IDEA自动下载库失败;

修改了maven 配置的镜像:

 

 

 

镜像代码:

 

<!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
      <mirror>
          <id>alimaven</id>
          <mirrorOf>central</mirrorOf>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
      </mirror>
      <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
      <mirror>
          <id>central</id>
          <name>Maven Repository Switchboard</name>
          <url>http://repo1.maven.org/maven2/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
      <mirror>
          <id>repo2</id>
          <mirrorOf>central</mirrorOf>
          <name>Human Readable Name for this Mirror.</name>
          <url>http://repo2.maven.org/maven2/</url>
      </mirror>
      <mirror>
          <id>ibiblio</id>
          <mirrorOf>central</mirrorOf>
          <name>Human Readable Name for this Mirror.</name>
          <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
      </mirror>
      <mirror>
          <id>jboss-public-repository-group</id>
          <mirrorOf>central</mirrorOf>
          <name>JBoss Public Repository Group</name>
          <url>http://repository.jboss.org/nexus/content/groups/public</url>
      </mirror>
      <mirror>
          <id>google-maven-central</id>
          <name>Google Maven Central</name>
          <url>
              https://maven-central.storage.googleapis.com
          </url>
          <mirrorOf>central</mirrorOf>
      </mirror>
      <!-- 中央仓库在中国的镜像 -->
      <mirror>
          <id>maven.net.cn</id>
          <name>oneof the central mirrors in china</name>
          <url>http://maven.net.cn/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
  </mirrors>
View Code

 

然后就可以直接下载了。

 

2.导入相关依赖

 

 

3.导入前一个项目的资源

 

导入后注意修改各类包的引用路径,

4.创建mapper,修改数据库语句,并往所有servlet上添加 @Controller 的注解,转变为Spring MVC

尝试使用mybatis

 

(使用mybatis mapper配置失误,数据库连接有问题,最后还是采取以前项目数据库连接)

实现效果:

 

 

 

 

码云地址:https://gitee.com/pinaomansgitee/SpringMVC.git

 

posted @ 2020-06-24 16:16  pianoman  阅读(332)  评论(0编辑  收藏  举报