1.SpringBoot整合web资源
1.1 创建动态web资源
1.2 项目结构
1.3 添加资源/jar包
1).添加资源
2).添加jar包文件
`
javax.servlet
javax.servlet-api
javax.servlet
jstl
org.apache.tomcat.embed
tomcat-embed-jasper
`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
1.4 添加YML配置文件
`server:
port: 8090
servlet:
context-path: / #项目根目录发布
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
mvc: #引入mvn配置
view:
prefix: /WEB-INF/ # /默认代表根目录 src/main/webapp
suffix: .jsp
# Spring整合Mybatis-plus配置
mybatis-plus:
type-aliases-package: com.jt.pojo
mapper-locations: classpath:/mybatis/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true
# 打印Mybatissql语句
logging:
level:
com.jt.mapper: debug`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
1.5 入门案例
1.5.1 业务需求
需求: 用户通过http://localhost:8090/findAll 获取全部userList集合,并且在userList.jsp页面中进行表格数据展现
1.5.2 动态web资源404报错说明
说明:IDEA默认条件下工作目录选择不正确的,需要手动配置一下,注意工作目录编辑
1.5.2 编辑UserController
第三阶段: pojo–>Mapper----->Service------>Controller------->页面及JS 自下而上的开发方式
第四阶段 pojo—>Controller—>Service----->Mapper 自上而下的开发方式
`package com.jt.controller;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/findAll")
public String findAll(Model model){
List userList = userService.findAll();
model.addAttribute("userList", userList);
return "userList";
}
}`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
1.5.3 编辑UserService
`package com.jt.service;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UserMapper userMapper;
@Override
public List findAll() {
return userMapper.selectList(null);
}
}`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
1.5.4 页面效果展现
1.6 异步实现业务调用
1.6.1 Ajax为什么可以异步呢? 工作原理是说明
说明:
1).Ajax中间有ajax引擎的参与.ajax引擎实质就是一种代理的思想
2).由于需要实现异步的操作,所以请求必然是多次请求.多次响应.
1.6.2 导入jQuery.JS
1.6.3 Ajax请求流程
如果需要发起Ajax请求时,一般需要发起2个请求.
1个是用来跳转页面的 http://localhost:8090/toAjax
1个是用来请求数据的 http://localhost:8090/findAjax
1.6.4 编辑页面
`<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
您好Springboot
学生信息
编号
姓名
年龄
性别
`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
* 32
* 33
* 34
* 35
* 36
* 37
* 38
* 39
* 40
* 41
* 42
* 43
* 44
* 45
* 46
* 47
* 48
* 49
* 50
* 51
* 52
* 53
* 54
* 55
* 56
* 57
* 58
* 59
* 60
* 61
* 62
* 63
* 64
* 65
* 66
* 67
* 68
* 69
* 70
* 71
* 72
* 73
* 74
* 75
* 76
* 77
* 78
* 79
* 80
* 81
* 82
* 83
* 84
* 85
* 86
* 87
* 88
* 89
1.6.5 编辑UserController
`/**
* 跳转到ajax.jsp页面中
*/
@RequestMapping("toAjax")
public String toAjax(){
return "ajax";
}
/**
* 接收ajax请求: /findAjax
* 返回值: List
*/
@RequestMapping("/findAjax")
@ResponseBody //1.将返回值结果转化为JSON数据返回 2.代表ajax请求结束
public List findAjax(){
return userService.findAll();
}`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
- 京淘项目环境搭建
============
2.1 分布式说明
2.1.1 传统项目中存在的问题
说明: 单体项目架构将所有的功能模块都写到一起,如果其中出现了问题则直接影响整个程序的允许.
2.1.2 分布式架构(拆)
1).可以按照功能模块可以将项目拆分为若干个子项目
2).如果业务功能足够复杂,则需要更加细粒度的拆分方式.
拆分的意义: 使用分布式架构设计,可以有效的降低架构中的耦合性,提高程序的开发速度及运维速度.
2.1.3 分布式思想存在的问题
问题1: 分布式架构中如何保证jar包文件的统一?
问题2: 分布式架构中如何保证工具API的统一?
3京淘后台项目创建
3.1 创建父级工程
3.1.1 创建目录
3.1.2 修改POM.xml文件
`
4.0.0
com.jt
jt
1.0-SNAPSHOT
pom
org.springframework.boot
spring-boot-starter-parent
2.4.0
1.8
true
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-devtools
org.projectlombok
lombok
mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-jdbc
com.baomidou
mybatis-plus-boot-starter
3.2.0
javax.servlet
javax.servlet-api
javax.servlet
jstl
org.apache.tomcat.embed
tomcat-embed-jasper
`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
* 32
* 33
* 34
* 35
* 36
* 37
* 38
* 39
* 40
* 41
* 42
* 43
* 44
* 45
* 46
* 47
* 48
* 49
* 50
* 51
* 52
* 53
* 54
* 55
* 56
* 57
* 58
* 59
* 60
* 61
* 62
* 63
* 64
* 65
* 66
* 67
* 68
* 69
* 70
* 71
* 72
* 73
* 74
* 75
* 76
* 77
* 78
* 79
* 80
* 81
* 82
* 83
* 84
* 85
* 86
* 87
* 88
* 89
* 90
* 91
* 92
* 93
* 94
* 95
3.2 创建工具API项目
3.2.1 创建自己工程
3.2.2 导入工具API
3.3 创建JT-MANAGE项目
3.3.1 创建项目
3.3.2 添加依赖
`
jt
com.jt
1.0-SNAPSHOT
4.0.0
jt-manage
war
com.jt
jt-common
1.0-SNAPSHOT
org.springframework.boot
spring-boot-maven-plugin
`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
* 32
* 33
* 34
* 35
* 36
* 37
3.3.3 导入静态资源文件
说明:将课前资料中的jt-manage项目的src文件导入. 导入结果,如图所示
3.3.4 修改代码
说明:去除没有必要的代码