IDEA通过Maven WebApp archetype 创建Spring boot项目骨架
springboot项目资源:
GitHub地址:https://github.com/TisFreedom/springbootdome.git
码云地址:https://gitee.com/TisFreedom/springbootdome.git
1.环境配置(jdk、maven、idea社区版)这里我就不再详细讲解。
2.新建maven项目。File>New>Project>Maven>Create from archetype>Maven-archetype-webapp>Next
3.填写GroupId和ArticleId 然后Next
4.配置自己的maven(如果你没有用默认的也行),完事Next
5.确认项目存放目录,然后Finish
如果右下角出现这个东西,麻烦你点一下Import Changes。
会生成标准的web项目目录,当然会少java目录和resource目录
5.新建java目录和resource目录
这样就建好了,当然idea是无法识别这些文件夹是干嘛。所以需要手动设置。
选中文件夹>左键>Mark Directory as
java文件夹选 Sources Root
resources文件夹选 Resources Root
6.配置pom.xml
<!-- 定义公共资源版本 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> <relativePath /> </parent> <dependencies> <!-- 包含 mvc,aop 等jar资源 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 映入tomcat --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <!-- jsp的整合依赖 --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <!-- 整合ssm --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 日志依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <!-- jstl标签架包 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <!-- 热部署 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- 没有该配置,devtools 不生效 --> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build>
7.配置application.properties文件,如果配置访问前缀后缀要建立相应的目录和视图
#修改端口 server.port=80 #数据源相关配置 spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=123 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #访问前缀和后缀 spring.mvc.view.prefix=WEB-INF/jsp/ spring.mvc.view.suffix=.jsp mybatis.mapperLocations=classpath:com/springboot/mapper/xml/**/*.xml
8. 新建启动类
@SpringBootApplication //扫描控制器类 @ComponentScan(basePackages="com.springboot") //扫描dao @MapperScan(basePackages="com.springboot.mapper") public class SpringBootStart { public static void main(String [] args){ SpringApplication.run(SpringBootStart.class,args); } }
9.新建控制器
@Controller public class TestController { @RequestMapping("/") public String index(Model model, HttpServletResponse response) { return "index"; } }
你的目录应该是这样子的
10.启动访问
如果你也向我一样配置了端口,和控制器默认路径。name自接用 localhost 就能访问。
作者:TisFreedom
来源:CSDN
原文:https://blog.csdn.net/tisfreedom/article/details/81180660