1.2 创建jsp页面 1.2.1 修改pom文件打包方式为warorg.apache.tomcat.embed tomcat-embed-jasper9.0.45 javax.servlet jstl1.2
1.2.2 在main中创建webapp目录,在webapp下创建WEB-INFwar
1.2.3 在webapp创建.jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
index..
1.3 将jsp页面放在WEB-INF中访问
出现问题
出现错误: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
分析:webapp目录下缺少WEB-INF/web.xml
当是在servlet 3.0之后,对于web.xml文件本身是可选的
解决:1.在pom.xml文件中定义一个参数配置
1.8 UTF-8 UTF-8 2.4.1 false
2.在webapp目录下创建WEB-INF/web.xml
1.3.1 将jsp文件存放到WEB-INF目录运行
http://localhost:8080/index.jsp
1.3.2 在application.yml文件配置SpringMVC视图解析方法
# 支持 yaml 语法配置
server:
port: 9999
servlet:
context-path: /demo1
spring:
datasource:
url: jdbc:mysql://localhost:3306/maven_demo1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
# 视图解析器的配置
mvc:
view:
prefix: /WEB-INF/
suffix: .jsp
mybatis:
mapper-locations: classpath:mappers/*Mapper.xml
type-aliases-package: com.qfedu.springboot.demo.entity
创建PageController
package com.qfedu.springboot.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class PageController {
@RequestMapping("/index.html")
public String index(){
return "index";
}
}
2. 基于SpringBoot的SSM整合
2.1 创建SpringBoot项目
创建项目时添加依赖
lombok,spring,mysql driver,mybatis framework
进行mybatis所需要的配置配置 aplication.yml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/maven_demo1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
mybatis:
type-aliases-package: com.qfedu.springboot.ssm.beans
mapper-locations: classpath:mappers/*.xml
在启动类配置dao扫描,配置SpringbootSsmApplication,如果多个dao,@MapperScan({"",""})
整合Druid连接池
在
SpringBoot
中整合
MyBatis
的时候,默认集成了
Hikari
连接池,
Hikari
的效率⽐
Druid
要⾼,但是得益于
Druid 提供了⽐较便捷的监控系统在企业开发中。
添加druid的starter
配置druid数据源 在application.yam中配置com.alibaba druid-spring-boot-starter1.1.10
spring:
datasource:
druid:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/maven_demo1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
initial-size: 1
min-idle: 1
max-active: 20
mybatis:
type-aliases-package: com.qfedu.springboot.ssm.beans
mapper-locations: classpath:mappers/*.xml
验证是否配置成功



