标签:代码 auto idt 设置 ppi demo height repo snapshot
设置Maven相关的参数
创建maven-spring项目
在pom文件中添加相关的依赖
<?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>maven-spring-demo</groupId> <artifactId>maven-spring-demo</artifactId> <version>1.0-SNAPSHOT</version> <name>hi-spring</name> <packaging>jar</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <!-- This plugin will set the properties values using dependency information --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.3</version> <executions> <execution> <goals> <goal>properties</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
下载相关的依赖
在DemoRun中添加如下代码:
1 import org.springframework.boot.SpringApplication; 2 import org.springframework.boot.autoconfigure.SpringBootApplication; 3 4 @SpringBootApplication 5 public class DemoRun { 6 public static void main(String[] args) { 7 SpringApplication.run(DemoRun.class, args); 8 } 9 }
在DemoController中添加如下代码:
import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class DemoController { @RequestMapping("/greeting") public String greeting( @RequestParam(value = "name", required = false, defaultValue = "name") String name, @RequestParam(value = "age", required = false, defaultValue = "age") String age, @RequestParam(value = "sex", required = false, defaultValue = "男") String sex, Model model) { model.addAttribute("name", name); model.addAttribute("age", age); model.addAttribute("sex", sex); return "greeting"; } }
标签:代码 auto idt 设置 ppi demo height repo snapshot
原文地址:https://www.cnblogs.com/zy-stu/p/11209913.html