您的位置:首页 > 编程语言 > Java开发

1.1 使用IntelliJ IDEA搭建Spring-Boot的"Hello World"项目

2017-10-27 11:07 639 查看
Development Software : IntelliJ IDEA 2017Development environment : JAVA 1.8Step 1 : Create a conventional Maven project.Step 2 : Setting configuration file ( 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>springboot</groupId>
<artifactId>springboot</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>      
		<relativePath/> <!-- lookup parent from repository -->    
	</parent> 
   
	<properties>        
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>        
		<java.version>1.8</java.version>    
	</properties>    
	<dependencies>        
		<dependency>            
	<groupId>org.springframework.boot</groupId>            
			<artifactId>spring-boot-starter-web</artifactId>       
		 </dependency>        
		<dependency>          
	<groupId>org.springframework.boot</groupId>            
			<artifactId>spring-boot-starter-thymeleaf</artifactId>   4000    
		</dependency>        
		<dependency>            
	<groupId>org.springframework.boot</groupId>            
			<artifactId>spring-boot-starter-data-mongodb</artifactId>        
		</dependency>    
	</dependencies>    
	<build>        
		<plugins>            
			<plugin>                
		<groupId>org.springframework.boot</groupId>                
				<artifactId>spring-boot-maven-plugin</artifactId>            
			</plugin>        
		</plugins>    
</build> 
 </project>
Step 3 : Import configuration file("pom.xml") required JAR packets1 : Right-click project.2 : Select "Maven" option.3 : Click "Reimport" button.Post Scriptum : you should execute this operation after changing the configuration file.Step 4 : Creaet start-up file(Class file)Post Scriptum : 1、Class fileshould cite (org.springframework.boot.SpringApplication、org.springframework.stereotype.Controller、org.springframework.boot.autoconfigure.SpringBootApplication)2、Class file should add annotation(@Controller  、@SpringBootApplication)Step 5 : Edit function code@RequestMapping(value = "index")@ResponseBodyString index(){return "hello world";}
Post Scriptum : 1、@RequestMapping(value = "index") isfunction access path(accessthis function local path is http://localhost:8080/index).2、@ResponseBody isuse to get request data.Step 6 : Run project1 : Right-click class file.2 : click "Run xxxxxxxx(class name)" button.If there is no error in the project , console will display☟access local path--------------------------------------------------------------------------------------------------If there have any errors(both of English and Code) . please comment me , i'm glad to correct those.
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息