前言:

除了mybatis 不是零配置,有些还是有xml的配置文件在里面的。

注解是Spring的一个构建的一个重要手段,减少写配置文件,下面解释一下一些要用到的注解:

@Configuration 作用于类上面,声明当前类是一个配置类(相当于一个Spring的xml文件)
@ComponentScan(“xxx”) 作用于类上面,自动扫描xxx包名下所有使用@Service、@Component、@Repository和@Controller的类,并注册为Bean
@Bean 作用与类和方法上,相当于Spring配置文件bean节点
@EnableWebMvc 作用于类,开启一些默认配置,如一些ViewResolver或者MessageConverter
@RequestMapping 作用于类、方法,配置URL和方法之间的映射
@RequestBody 作用于参数前,允许request的参数在request体中,而不是在直接链接在地址后面
@ResponseBody 作用于返回值、方法上,支持将返回值放在response体中,而不是返回一个页面。
@RequestParam 作用于参数前,将form的对应name值映射到当前参数中。

从一开始。

先搭建一个 Spring + Spring MVC 的web 项目

  创建项目。

 使用IDEA搭建一个 Spring + Spring MVC + Mybatis 的Web项目  ( 零配置文件 )

使用IDEA搭建一个 Spring + Spring MVC + Mybatis 的Web项目  ( 零配置文件 )

使用IDEA搭建一个 Spring + Spring MVC + Mybatis 的Web项目  ( 零配置文件 )

然后 点击 Finish 完成 创建项目。

这里开始配置我们的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.oukele.ssm</groupId>
  <artifactId>MyDemo</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>MyDemo Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>

    <!--spring 的依赖管理 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.1.3.RELEASE</version>
    </dependency>

   <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.1.3.RELEASE</version>
    </dependency>

   <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>5.1.3.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.1.3.RELEASE</version>
    </dependency>

    <!--spring MVC -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.1.3.RELEASE</version>
    </dependency>

      <!-- servlet  -->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>4.0.1</version>
          <scope>provided</scope>
      </dependency>

      <!--jstl-->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>
      

  </dependencies>
  
</project>
View Code

相关文章:

  • 2021-07-05
  • 2021-10-06
  • 2021-09-15
  • 2022-02-27
  • 2022-01-02
  • 2021-11-27
  • 2021-12-30
  • 2021-08-06
猜你喜欢
  • 2021-12-14
  • 2022-12-23
  • 2021-08-25
  • 2021-09-04
  • 2022-02-12
  • 2022-12-23
  • 2021-08-18
相关资源
相似解决方案