.Spring web demo case

So, here is a simple case.
First of all, we need to create a Spring WEB MVCproject. We might as well find out how to start from the official website. First, find the official documents.
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
You can see Springthe environmental requirements for creating applications, JDK1.8& Maven 3.2+. Then, find the manual creation introduction:
Insert picture description here
Then, follow the steps above to import it into ideaand ideaconfigure it in the middle maven:
specify the mavenfile that you installed and configured , and the file location mavenis the conf/settings.xmlfile in the installation directory , such as Alibaba Cloud Image address:

<!-- 阿里云仓库 -->
<mirrors>
	<mirror>
	  <id>nexus-aliyun</id>
	  <mirrorOf>central</mirrorOf>
	  <name>Nexus aliyun</name>
	  <url>http://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>
</mirrors>
 
  <profiles>
         <profile>
              <id>jdk-1.8</id>
              <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
              </activation>
              <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
              </properties>
         </profile>
  </profiles>

Finally, the downloaded sample project was imported and synchronized maven, but an error occurred: the
Insert picture description here
Internet says that you need to specify springframework.bootthe version, such as:

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<version>2.4.4</version>
			</plugin>
		</plugins>
	</build>

Sure enough, the problem of redemption was solved.

Then, according to the document, create the following two files:
Insert picture description here
Then, Applicationstart in:
Insert picture description here
Insert picture description here
Follow the prompts, the address is: http://localhost:8080/
Then, test according controllerto the address in the configuration http://localhost:8080/greeting?name=User:
Insert picture description here
Insert picture description here


Official case address: https://spring.io/guides/gs/rest-service/
Official document address: https://docs.spring.io/spring-framework/docs/current/reference/html/

Guess you like

Origin blog.csdn.net/qq_26460841/article/details/115028915