springboot比ssm框架的配置更加简单
新建项目是一定要选择web项目,否则项目不能正常启动
这篇博客总结新学到的内容的
启动类
实体类
@Data //set/get/toString @Accessors(chain = true) //链式加载 @NoArgsConstructor //无参构造 @AllArgsConstructor //有参构造 @TableName("user") //对象与数据表完成映射 public class User implements Serializable{ @TableId(type=IdType.AUTO) //主键自动 private Integer id; private String name; private Integer age; private String sex; }
yml文件
mybatis用的是mybatis-plus
1 server: 2 port: 8090 3 servlet: 4 context-path: / 5 #--------------------- 6 7 #引入数据源配置和配置mvc界面 8 spring: 9 datasource: 10 #引入druid数据源 11 type: com.alibaba.druid.pool.DruidDataSource 12 driver-class-name: com.mysql.cj.jdbc.Driver 13 url: jdbc:mysql://localhost:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true 14 username: root 15 password: root 16 17 mvc: 18 view: 19 prefix: /WEB-INF/ 20 suffix: .jsp 21 22 23 #mybatis-plus配置 24 mybatis-plus: 25 type-aliases-package: com.ywq.testboot.pojo 26 mapper-locations: classpath:mapper/*.xml 27 configuration: 28 map-underscore-to-camel-case: true 29 30 #添加日志输出 31 logging: 32 level: 33 com.demo.mapper: debug
pom.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.1.3.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.ywq</groupId> 12 <artifactId>test-boot</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>test-boot</name> 15 <description>Demo project for Spring Boot</description> 16 17 <properties> 18 <java.version>1.8</java.version> 19 </properties> 20 21 <dependencies> 22 <dependency> 23 <groupId>org.springframework.boot</groupId> 24 <artifactId>spring-boot-starter-web</artifactId> 25 </dependency> 26 27 <dependency> 28 <groupId>org.projectlombok</groupId> 29 <artifactId>lombok</artifactId> 30 <optional>true</optional> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-starter-test</artifactId> 35 <scope>test</scope> 36 <exclusions> 37 <exclusion> 38 <groupId>org.junit.vintage</groupId> 39 <artifactId>junit-vintage-engine</artifactId> 40 </exclusion> 41 </exclusions> 42 </dependency> 43 44 <!--热部署--> 45 <dependency> 46 <groupId>org.springframework</groupId> 47 <artifactId>springloaded</artifactId> 48 <version>1.2.8.RELEASE</version> 49 </dependency> 50 51 <!--引入数据库驱动--> 52 <dependency> 53 <groupId>mysql</groupId> 54 <artifactId>mysql-connector-java</artifactId> 55 <scope>5.1.6</scope> 56 </dependency> 57 58 <!--引入数据源--> 59 <dependency> 60 <groupId>com.alibaba</groupId> 61 <artifactId>druid</artifactId> 62 <version>1.1.21</version> 63 </dependency> 64 65 <!--整合mybatis-plus--> 66 <dependency> 67 <groupId>com.baomidou</groupId> 68 <artifactId>mybatis-plus-boot-starter</artifactId> 69 <version>3.0.6</version> 70 </dependency> 71 72 <!--spring整合JSP添加依赖,jstl那些--> 73 <!--servlet--> 74 <dependency> 75 <groupId>javax.servlet</groupId> 76 <artifactId>javax.servlet-api</artifactId> 77 </dependency> 78 79 <dependency> 80 <groupId>javax.servlet</groupId> 81 <artifactId>jstl</artifactId> 82 </dependency> 83 84 <!--使js页面生效--> 85 <dependency> 86 <groupId>org.apache.tomcat.embed</groupId> 87 <artifactId>tomcat-embed-jasper</artifactId> 88 </dependency> 89 <dependency> 90 <groupId>org.springframework</groupId> 91 <artifactId>spring-web</artifactId> 92 </dependency> 93 94 95 96 </dependencies> 97 98 <build> 99 <plugins> 100 <plugin> 101 <groupId>org.springframework.boot</groupId> 102 <artifactId>spring-boot-maven-plugin</artifactId> 103 </plugin> 104 </plugins> 105 </build> 106 107 </project>