SpringBoot web开发(2)

springboot web开发(2)

crud-员工列表

RestfulCRUD:满足Rest风格
url:/资源名称/资源标识 HTTP请求方式区对资源的CRUD操作

RestfulCRUDRestfulCRUD
查询getEmpemp-GET
添加addEmpemp–POST
修改updateEmpemp — put
删除deleteEmp?id=1emp/{id}–delete

thymeleaf公共页面抽取

<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0" th:fragment="topbar">
<nav class="col-md-2 d-none d-md-block bg-light sidebar"  id="sidebar">

公共页面引用
th:insert : 将公共片段整个插入到声明引入的元素中
th:replace: 将声明引入的元素替换为公共片段
th:include: 将被引用的片段的内容包含进这个标签中

<div th:replace="~{commons/bar::topbar}"></div>
<div th:replace="~{commons/bar::#sidebar(activeUri='emps')}"></div>

引入片段的时候传入参数

<nav class="col-md-2 d-none d-md-block bg-light sidebar"  id="sidebar">
    <div class="sidebar-sticky">
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link active" th:class="${activeUri=='main'?'nav-link active':'nav-link'}"
                   href="#" th:href="@{/main}">
                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home">
                        <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
                        <polyline points="9 22 9 12 15 12 15 22"></polyline>
                    </svg>
                    Dashboard <span class="sr-only">(current)</span>
                </a>
            </li>
......


<div th:replace="~{commons/bar::#sidebar(activeUri='emps')}"></div>

错误处理机制

1)、有模板引擎的情况下;error/状态码; 【将错误页面命名为 错误状态码.html 放在模板引擎文件夹里面的 error文件夹下】,发生此状态码的错误就会来到 对应的页面;
我们可以使用4xx和5xx作为错误页面的文件名来匹配这种类型的所有错误,精确优先(优先寻找精确的状态码.html);
页面能获取的信息;
timestamp:时间戳
status:状态码
error:错误提示
exception:异常对象
message:异常消息
errors:JSR303数据校验的错误都在这里
2)、没有模板引擎(模板引擎找不到这个错误页面),静态资源文件夹下找;
3)、以上都没有错误页面,就是默认来到SpringBoot默认的错误提示页面;

@Component
public class MyErrorAttribute extends DefaultErrorAttributes {

//    @Override
//    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
//        Map<String,Object> map=super.getErrorAttributes(webRequest,includeStackTrace);
//        map.put("myerror","errormy");
//        return map;
//    }

    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
        Map<String,Object> map=super.getErrorAttributes(webRequest, options);
        map.put("myerror","errormy");
        return map;
    }
}
server.error.include-message=always   获取错误消息

配置嵌入式Servlet容器
替换为其他嵌入式Servlet容器
使用外置的Servlet容器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZSECode

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值