本次尝试创建一个简单的spring mvc restful项目,尝试简单的接口实现。
工具使用:intellij IDEA
Spring:当前最新版本5.0.5RELEASE
Spring就是各大杂烩,啥东西都可以被加进去,比如data-bind,rabbitmq,mybatis, swagger等等,几乎各种流行的库都被它搞了一把,和spring集成到一起,用起来比较方便,但配置和学习起来比较麻烦,个人并不怎么喜欢,所以一直也没有去实践一把。这次闲来无事就玩玩。
1. intellij IDEA创建一个maven web app
创建项目没什么好说的,非常简单。主要是需要各种配置,这就是spring不好玩的地方,简直乱糟糟。
1.1 POM添加依赖
依赖包含3部分:spring相关库,spring mvc相关库,以及数据绑定相关的库。
<?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>example</groupId>
<artifactId>example1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>example1 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>
<spring.version>5.0.5.RELEASE</spring.version>
<jackson.version>2.9.5</jackson.version>
</properties>
<dependencies>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId&