5.6 springboot 笔记
1. maven 项目的目录结构:
src/main/java --- controller ,service, mapper java 源文件写这
src/main/resources --- 配置文件, springmvc.xml, mybatis-config.xml
src/main/resources/static --- 存放 静态资源
src/main/resources/templates--- 存放动态资源
src/test/java --- 单元测试用例
2. springboot
ssm----- web.xml, spring.xml, springmvc.xml, mybatis-config.xml, tomcat
太复杂, 太累, 太繁琐, ----- 如何简化? ------ springboot
springboot --- 一站式开发解决方案, 内置了tomcat, 程序无需打包为war,
一个project(工程或项目) 包含若干个 module(模块) 这种方式的好处就是
再父工程下配置 jar的版本号, 子模块 无需再配置版本号
3. 使用springboot的步骤:
a. 修改 父工程的pom.xml (只修改一次)
b. 修改 子module的pom.xml 增加 spring-boot-starter-web 的依赖
c. 编写 启动类: 不允许 直接写在 src/main/java 下, 一般 会创建 包
main()
d. ssm +tomcat , tomcat 端口, 默认8080,
编写 springboot的配置文件 来设置 端口号
yaml 文件, 扩展名 *.yml 或 *.yaml
4. springboot的注意事项:(自己创建的方式 不是采用 官方推荐的方式)
a. 添加依赖,
b. 编写启动类, 必须创建包, 自动扫描 启动类所在包及子包
c. 编写 端口号, 默认 8080, 推荐修改 -------
d. 运行启动类, 打开浏览器 进行测试
5. 还可以利用 springboot的 初始化器 进行 创建 例如 boot2
6. springboot 启动流程
@SpringBootApplication 放到 启动类的 上面, 标识 当前类 为 一个 springboot 应用
7. 带有 html 页面的工程---boot1
找到 src/main/resources 创建 static 及 templates 目录
创建 控制层 返回 html
ssm+tomcat+ jsp + jstl
springboot + html (thymeleaf 引擎) ---添加依赖, pom.xml,
src/main/resources/static 下 的内容 ,可以通过 http://localhost:端口号/页面.html 可以访问
src/main/resources/templates 下 的内容 ,不可以通过 http://localhost:端口号/页面.html ,404
如果 想 访问, 通过 controller 进行访问
springboot 中 默认值: ---- 因此 不需要配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
练习:
创建 boot_lianxi1,
创建 static 下建立 abc.html, 显示 学号
templates 下建立 abcd.html, 显示你的姓名
端口号 8888
5.6 springboot + mybatis , student表 数据的分页查询
grade(id, gname)
student(id,sname,borndate,sex,phone,gid)
mybatis : mapper, entity
a. 创建 实体层, 包名 entity/pojo
Student.java
b. 创建 数据访问层 mapper, 接口 与 mapper.xml
StudentMapper.java 与 StudentMapper.xml
再 src/main/resources下 创建 mapper 目录
c. 创建业务层service, 接口与实现类
d. 创建 控制层 controller
e. 分页查询, 增加依赖 分页插件 --pagehelper
f. 编写 application.yaml 文件 配置 数据源, mybatis,pagehelper
g. 编写 html 增加 thymeleaf 配置
jstl : c:if c:forEach
thymeleaf th:if
5.7 thymeleaf 语法
要想使用 thymeleaf , 首先 增加 依赖 pom.xml --- spring-boot-starter-thymeleaf
thymeleaf 搭配的是 html,
在 html中 如果想 使用 thymeleaf , 则必须引入 命名空间
在 <html> 里 增加 xmlns:th="http://www.thymeleaf.org"
在当前 html 中 可以 使用th:
th:html属性 , 他就会自动替换对应的值
例如 th:id ---> 替换 id的值
th:text ---> 替换 显示文本 [[]]
th:each ---> 遍历
th:each="变量名:${后台controller中的属性名}"
关于 超链接 thymeleaf 推荐使用 @{} 写法
th:href=@{}
5.8 添加 , 删除 ,修改
添加:
有页面 add.html, 录入数据
mapper, service,controller,
1. 添加
修改 mapper
修改 service
修改 controller--- add.html, form, method, post请求
编写 add.html
post请求: 添加/修改 post 安全性高
get请求: 超链接,地址栏
修改list.html 增加. 跳转到 add.html的内容
修改add.html
a. 实现性别的互斥
type=radio , 要求name 必须一致 , 就能实现互斥
由于Student中sex是 int ,因此需要设置value
b. 如何让控件与 controller中的Student属性对应
为 所有的表单元素 除 按钮外 增加 name属性
且 name ="属性名"
c. 修改add.html, 将 年级编号 改为 下拉框
针对 grade表 进行查询全部
entity, mapper,service,
修改 add.html 增加 select 标签
删除:
点击[删除] 按钮后, 需要提示(询问) , 确定删除, 在执行删除
mapper, service,controller
list.html
如果 在onclick事件 需要解析 内容 ,则使用 | |
5.9 编辑
编辑: 一共包含两个, 数据回显, 数据的更新
回显: 根据 主键 进行查询,
主键 是 唯一的, update.html
更新: 执行 update
对学生进行编辑, mapper,service,controller,
建立 update.html
修改 list.html 为 编辑按钮 增加 onclick 事件
添加与修改区别:
添加 不需要传递 id (主键)
单修改 必须传 id --一般 不可见,因此用 隐藏域 hidden 进行传值
没有合适的资源?快使用搜索试试~ 我知道了~
使用boot+thymeleaf进行增删改查
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共36个文件
java:10个
class:10个
html:8个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
0 下载量 144 浏览量
2024-05-27
15:12:47
上传
评论
收藏 25KB RAR 举报
温馨提示
使用boot+thymeleaf进行增删改查
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
共 36 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/2ea55baaa0e746cb9fb674effd5b022e_ly121862.jpg!1)
射手座的程序媛
- 粉丝: 1889
- 资源: 190
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)