其他
同学,其实用免费版的IDEA来创建SpringBoot项目挺方便的...
GitHub地址:https://github.com/TisFreedom/springbootdome.git
码云地址:https://gitee.com/TisFreedom/springbootdome.git
4.配置自己的maven(如果你没有用默认的也行),完事Next
如果右下角出现这个东西,麻烦你点一下Import Changes。
6.新建java目录和resource目录
7.配置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>
#修改端口
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
@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);
}
}
@Controller
public class TestController {
@RequestMapping("/")
public String index(Model model, HttpServletResponse response) {
return "index";
}
}
11.启动访问
如果你也向我一样配置了端口,和控制器默认路径。name自接用 localhost 就能访问。
老师,免费版的IDEA为啥不能使用Tomcat?
同时,分享一份Java面试资料给大家,覆盖了算法题目、常见面试题、JVM、锁、高并发、反射、Spring原理、微服务、Zookeeper、数据库、数据结构等等。
获取方式:点“在看”,关注公众号并回复 面试 领取。