• Java(SpringBoot05)


    Java(SpringBoot05)

    参考视频:22. 员工管理系统:国际化(狂神)

    13. 页面国际化

    • 有的时候,我们的网站会去涉及中英文甚至多语言的切换,这时候我们就需要学习国际化了!

    13.1 准备工作

    • 先在IDEA中统一设置properties的编码问题!
      在这里插入图片描述
    • 编写国际化配置文件,抽取页面需要显示的国际化页面消息。我们可以去登录页面查看一下,哪些内容我们需要编写国际化的配置!

    13.2 配置文件编写

    1. 我们在resources资源文件下新建一个i18n目录,存放国际化配置文件

    2. 建立一个login.properties文件,还有一个login_zh_CN.properties;发现IDEA自动识别了我们要做国际化操作;文件夹变了!
      在这里插入图片描述

    3. 我们可以在这上面去新建一个文件;
      在这里插入图片描述

    • 弹出如下页面:我们再添加一个英文的;
      在这里插入图片描述
    • 这样就快捷多了!
      在这里插入图片描述
    1. 接下来,我们就来编写配置,我们可以看到idea下面有另外一个视图;
      在这里插入图片描述
    • 这个视图我们点击 + 号就可以直接添加属性了;我们新建一个login.tip,可以看到边上有三个文件框可以输入
      在这里插入图片描述

    • 我们添加一下首页的内容!
      在这里插入图片描述

    • 然后依次添加其他页面内容即可!
      在这里插入图片描述

    • 然后去查看我们的配置文件;

    • login.properties :默认

    login.btn=登录
    login.password=密码
    login.remember=记住我
    login.tip=请登录
    login.username=用户名
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 英文:
    login.btn=Sign in
    login.password=Password
    login.remember=Remember me
    login.tip=Please sign in
    login.username=Username
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 中文:
    login.btn=登录
    login.password=密码
    login.remember=记住我
    login.tip=请登录
    login.username=用户名
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • OK,配置文件步骤搞定!

    13.3 配置文件生效探究

    • 我们去看一下SpringBoot对国际化的自动配置!这里又涉及到一个类:MessageSourceAutoConfiguration
    • 里面有一个方法,这里发现SpringBoot已经自动配置好了管理我们国际化资源文件的组件 ResourceBundleMessageSource;
    // 获取 properties 传递过来的值进行判断
    @Bean
    public MessageSource messageSource(MessageSourceProperties properties) {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        if (StringUtils.hasText(properties.getBasename())) {
            // 设置国际化文件的基础名(去掉语言国家代码的)
            messageSource.setBasenames(
                StringUtils.commaDelimitedListToStringArray(
                                           StringUtils.trimAllWhitespace(properties.getBasename())));
        }
        if (properties.getEncoding() != null) {
            messageSource.setDefaultEncoding(properties.getEncoding().name());
        }
        messageSource.setFallbackToSystemLocale(properties.isFallbackToSystemLocale());
        Duration cacheDuration = properties.getCacheDuration();
        if (cacheDuration != null) {
            messageSource.setCacheMillis(cacheDuration.toMillis());
        }
        messageSource.setAlwaysUseMessageFormat(properties.isAlwaysUseMessageFormat());
        messageSource.setUseCodeAsDefaultMessage(properties.isUseCodeAsDefaultMessage());
        return messageSource;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 我们真实 的情况是放在了i18n目录下,所以我们要去配置这个messages的路径;
    spring.messages.basename=i18n.login
    
    • 1

    13.4 配置页面国际化值

    • 去页面获取国际化的值,查看Thymeleaf的文档,找到message取值操作为:#{…}。我们去页面测试下:
    • IDEA还有提示,非常智能的!
      在这里插入图片描述
    • 我们可以去启动项目,访问一下,发现已经自动识别为中文的了!
      在这里插入图片描述
    • 但是我们想要更好!可以根据按钮自动切换中文英文!

    13.5 配置国际化解析

    • 在Spring中有一个国际化的Locale (区域信息对象);里面有一个叫做LocaleResolver (获取区域信息对象)的解析器!
    • 我们去我们webmvc自动配置文件,寻找一下!看到SpringBoot默认配置:
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "spring.mvc", name = "locale")
    public LocaleResolver localeResolver() {
        // 容器中没有就自己配,有的话就用用户配置的
        if (this.mvcProperties.getLocaleResolver() == WebMvcProperties.LocaleResolver.FIXED) {
            return new FixedLocaleResolver(this.mvcProperties.getLocale());
        }
        // 接收头国际化分解
        AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
        localeResolver.setDefaultLocale(this.mvcProperties.getLocale());
        return localeResolver;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • AcceptHeaderLocaleResolver 这个类中有一个方法
    public Locale resolveLocale(HttpServletRequest request) {
        Locale defaultLocale = this.getDefaultLocale();
        // 默认的就是根据请求头带来的区域信息获取Locale进行国际化
        if (defaultLocale != null && request.getHeader("Accept-Language") == null) {
            return defaultLocale;
        } else {
            Locale requestLocale = request.getLocale();
            List<Locale> supportedLocales = this.getSupportedLocales();
            if (!supportedLocales.isEmpty() && !supportedLocales.contains(requestLocale)) {
                Locale supportedLocale = this.findSupportedLocale(request, supportedLocales);
                if (supportedLocale != null) {
                    return supportedLocale;
                } else {
                    return defaultLocale != null ? defaultLocale : requestLocale;
                }
            } else {
                return requestLocale;
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 那假如我们现在想点击链接让我们的国际化资源生效,就需要让我们自己的Locale生效!
    • 我们去自己写一个自己的LocaleResolver,可以在链接上携带区域信息!
    • 修改一下前端页面的跳转连接:
    <!-- 这里传入参数不需要使用 ?使用 (key=value)-->
    <a class="btn btn-sm" th:href="@{/index.html(l='zh_CN')}">中文</a>
    <a class="btn btn-sm" th:href="@{/index.html(l='en_US')}">English</a>
    
    • 1
    • 2
    • 3
    • 我们去写一个处理的组件类!
    package com.kuang.component;
    
    import org.springframework.util.StringUtils;
    import org.springframework.web.servlet.LocaleResolver;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.util.Locale;
    
    //可以在链接上携带区域信息
    public class MyLocaleResolver implements LocaleResolver {
    
        //解析请求
        @Override
        public Locale resolveLocale(HttpServletRequest request) {
    
            String language = request.getParameter("l");
            Locale locale = Locale.getDefault(); // 如果没有获取到就使用系统默认的
            //如果请求链接不为空
            if (!StringUtils.isEmpty(language)){
                //分割请求参数
                String[] split = language.split("_");
                //国家,地区
                locale = new Locale(split[0],split[1]);
            }
            return locale;
        }
    
        @Override
        public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
    
        }
    }
    
    • 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
    • 为了让我们的区域化信息能够生效,我们需要再配置一下这个组件!在我们自己的MvcConofig下添加bean;
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 我们重启项目,来访问一下,发现点击按钮可以实现成功切换!搞定收工!

    14. 网站图标

    • 具体效果 清理缓存后重启浏览器 显示的才准确。

    • 图标存放目录
      在这里插入图片描述

    • 需要修改或添加的地方:

    1. MyMvcConfig
    • 添加addResourceHandlers
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
            registry.addResourceHandler("/templates/**" ).addResourceLocations("classpath:/templates/");
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 添加excludePathPatterns ,"/static/favicon.ico"
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoginHandlerInterceptor())
                    .addPathPatterns("/**")
                    .excludePathPatterns("/index.html"
                            ,"/","/user/login","/css/*"
                            ,"/js/**","/img/**"
                            ,"/static/favicon.ico");
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    1. 在index页面的head标签中添加以下link(其他页面也一样)
        
        <link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
    
    • 1
    • 2
    • 完成。
      在这里插入图片描述

    15. 员工列表展示

    • 部分代码:
    • EmployeeController
    package com.zach.controller;
    
    import com.zach.dao.EmployeeDao;
    import com.zach.pojo.Employee;
    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 java.util.Collection;
    
    @Controller
    public class EmployeeController {
    
        @Autowired
        EmployeeDao employeeDao;
    
        @RequestMapping("/emps")
        public String list(Model model){
            Collection<Employee> employees = employeeDao.getAll();
            model.addAttribute("emps", employees);
            return "emp/list";
        }
    
    }
    
    • 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
    • list.html(部分)
    
    <div th:insert="~{commons/commons::topbar}">div>
    
    <div class="container-fluid">
        <div class="row">
            
            <div th:insert="~{commons/commons::sidebar(active='list.html')}">div>
    
            <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                <h2>Section titleh2>
                <div class="table-responsive">
                    <table class="table table-striped table-sm">
                        <thead>
                            <tr>
                                <th>idth>
                                <th>lastNameth>
                                <th>emailth>
                                <th>genderth>
                                <th>departmentth>
                                <th>birthth>
                                <th>操作th>
                            tr>
                        thead>
                        <tbody>
                            
                            <tr th:each="emp:${emps}">
                                
                                <td th:text="${emp.getId()}">td>
                                <td>[[ ${emp.getLastName()} ]]td>
                                <td>[[ ${emp.getEmail()} ]]td>
                                <td>[[ ${emp.getGender()}==0 ? '女' : '男']]td>
                                <td>[[ ${emp.department.getDepartmentName()} ]]td>
                                
                                <td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}">td>
                                <td>
                                    <button class="btn btn-sm btn-primary"> 编辑 button>
                                    | <button class="btn btn-sm btn-danger"> 删除 button>
                                td>
                            tr>
                        tbody>
                    table>
                div>
            main>
        div>
    div>
    
    • 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

    16. 员工操作实现等

    • application.properties
    # 关闭默认图标(目前已经没用了)
    # spring.mvc.favicon.enabled=false
    
    # 关闭模板引擎的缓存
    spring.thymeleaf.cache=false
    
    # 添加路径上下文
    server.servlet.context-path=/zach
    
    # 我们的配置文件的真实位置
    spring.messages.basename=i18n.login
    
    # 时间日期格式化
    spring.mvc.format.date=yyyy-MM-dd HH:mm:ss
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • index.html
    DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>SignIn Template for Bootstraptitle>
        
        <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
        
        <link th:href="@{/css/signin.css}" rel="stylesheet">
    
        
        <link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
    head>
    
    <body class="text-center">
    <form class="form-signin" th:action="@{/user/login}">
        <img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72">
        <h1 class="h3 mb-3 font-weight-normal" th:text="#{login.tip}">Please sign inh1>
    
        
        
        <p style="color: palevioletred" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}">p>
    
        <label>
            <input type="text" name="username" class="form-control" th:placeholder="#{login.username}" required="" autofocus="">
        label>
        <label>
            <input type="password" name="password" class="form-control" th:placeholder="#{login.password}" required="">
        label>
        <div class="checkbox mb-3">
            <label>
                <input type="checkbox" value="remember-me"> [[#{login.remember}]]
            label>
        div>
        <button class="btn btn-lg btn-primary btn-block" type="submit" th:text="#{login.btn}">Sign inbutton>
        <p class="mt-5 mb-3 text-muted">© 2017-2018p>
        <a class="btn btn-sm" th:href="@{/index.html(l='zh_CN')}">中文a>
        <a class="btn btn-sm" th:href="@{/index.html(l='en_US')}">Englisha>
    form>
    
    body>
    
    html>
    
    • 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
    • dashboard.html
    DOCTYPE html>
    
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
    
        <title>Dashboard Template for Bootstraptitle>
        
        <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    
        
        <link th:href="@{/css/dashboard.css}" rel="stylesheet">
        <link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
        <style type="text/css">
            /* Chart.js */
    
            @-webkit-keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            @keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            .chartjs-render-monitor {
                -webkit-animation: chartjs-render-animation 0.001s;
                animation: chartjs-render-animation 0.001s;
            }
        style>
    head>
    
    <body>
    
    <div th:replace="~{commons/commons::topbar}">div>
    
    <div class="container-fluid">
        <div class="row">
            
            
            <div th:replace="~{commons/commons::sidebar(active='main.html')}">div>
    
            <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                <div class="chartjs-size-monitor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;">
                    <div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
                        <div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0">div>
                    div>
                    <div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
                        <div style="position:absolute;width:200%;height:200%;left:0; top:0">div>
                    div>
                div>
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
                    <h1 class="h2">Dashboardh1>
                    <div class="btn-toolbar mb-2 mb-md-0">
                        <div class="btn-group mr-2">
                            <button class="btn btn-sm btn-outline-secondary">Sharebutton>
                            <button class="btn btn-sm btn-outline-secondary">Exportbutton>
                        div>
                        <button class="btn btn-sm btn-outline-secondary dropdown-toggle">
                            <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-calendar"><rect x="3" y="4" width="18" height="18" rx="2" ry="2">rect><line x1="16" y1="2" x2="16" y2="6">line><line x1="8" y1="2" x2="8" y2="6">line><line x1="3" y1="10" x2="21" y2="10">line>svg>
                            This week
                        button>
                    div>
                div>
    
                <canvas class="my-4 chartjs-render-monitor" id="myChart" width="1076" height="454" style="display: block; width: 1076px; height: 454px;">canvas>
    
    
            main>
        div>
    div>
    
    
    
    <script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js" >script>
    <script type="text/javascript" src="asserts/js/popper.min.js" >script>
    <script type="text/javascript" src="asserts/js/bootstrap.min.js" >script>
    
    
    <script type="text/javascript" src="asserts/js/feather.min.js" >script>
    <script>
        feather.replace()
    script>
    
    
    <script type="text/javascript" src="asserts/js/Chart.min.js" >script>
    <script>
        var ctx = document.getElementById("myChart");
        var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
                datasets: [{
                    data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                    lineTension: 0,
                    backgroundColor: 'transparent',
                    borderColor: '#007bff',
                    borderWidth: 4,
                    pointBackgroundColor: '#007bff'
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: false
                        }
                    }]
                },
                legend: {
                    display: false,
                }
            }
        });
    script>
    
    body>
    
    html>
    
    • 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
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • list.html
    DOCTYPE html>
    
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
    
        <title>Dashboard Template for Bootstraptitle>
        
        <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    
        
        <link th:href="@{/css/dashboard.css}" rel="stylesheet">
        <link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
        <style type="text/css">
            /* Chart.js */
    
            @-webkit-keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            @keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            .chartjs-render-monitor {
                -webkit-animation: chartjs-render-animation 0.001s;
                animation: chartjs-render-animation 0.001s;
            }
        style>
    head>
    
    <body>
    
    <div th:insert="~{commons/commons::topbar}">div>
    
    <div class="container-fluid">
        <div class="row">
            
            <div th:insert="~{commons/commons::sidebar(active='list.html')}">div>
    
            <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                <h2><a class="btn btn-sm btn-success" th:href="@{/emp}">添加员工a>h2>
                <div class="table-responsive">
                    <table class="table table-striped table-sm">
                        <thead>
                            <tr>
                                <th>idth>
                                <th>lastNameth>
                                <th>emailth>
                                <th>genderth>
                                <th>departmentth>
                                <th>birthth>
                                <th>操作th>
                            tr>
                        thead>
                        <tbody>
                            
                            <tr th:each="emp:${emps}">
                                
                                <td th:text="${emp.getId()}">td>
                                <td>[[ ${emp.getLastName()} ]]td>
                                <td>[[ ${emp.getEmail()} ]]td>
                                <td>[[ ${emp.getGender()}==0 ? '女' : '男']]td>
                                <td>[[ ${emp.department.getDepartmentName()} ]]td>
                                
                                <td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}">td>
                                <td>
                                    
                                    <a class="btn btn-sm btn-primary" th:href="@{'/emp/'+${emp.getId()}}"> 编辑 a>
                                    | <a class="btn btn-sm btn-danger" th:href="@{/delemp/} + ${emp.getId()}"> 删除 a>
                                td>
                            tr>
                        tbody>
                    table>
                div>
            main>
        div>
    div>
    
    
    
    <script type="text/javascript" src="/static/js/jquery-3.2.1.slim.min.js">script>
    <script type="text/javascript" src="/static/js/popper.min.js">script>
    <script type="text/javascript" src="/static/js/bootstrap.min.js">script>
    
    
    <script type="text/javascript" src="/static/js/feather.min.js">script>
    <script>
        feather.replace()
    script>
    
    
    <script type="text/javascript" src="/static/js/Chart.min.js">script>
    <script>
        var ctx = document.getElementById("myChart");
        var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
                datasets: [{
                    data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                    lineTension: 0,
                    backgroundColor: 'transparent',
                    borderColor: '#007bff',
                    borderWidth: 4,
                    pointBackgroundColor: '#007bff'
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: false
                        }
                    }]
                },
                legend: {
                    display: false,
                }
            }
        });
    script>
    
    body>
    
    html>
    
    • 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
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • add.html
    DOCTYPE html>
    
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
    
        <title>Dashboard Template for Bootstraptitle>
        
        <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    
        
        <link th:href="@{/css/dashboard.css}" rel="stylesheet">
        <link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
        <style type="text/css">
            /* Chart.js */
    
            @-webkit-keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            @keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            .chartjs-render-monitor {
                -webkit-animation: chartjs-render-animation 0.001s;
                animation: chartjs-render-animation 0.001s;
            }
        style>
    head>
    
    <body>
    
    <div th:insert="~{commons/commons::topbar}">div>
    
    <div class="container-fluid">
        <div class="row">
            
            <div th:insert="~{commons/commons::sidebar(active='list.html')}">div>
    
            <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                <form th:action="@{/emp}" method="post">
                    <div class="form-group">
                        <label>LastName label>
                        <label>
                            <input type="text" name="lastName" class="form-control" placeholder="zach">
                        label>
                    div>
                    <div class="form-group">
                        <label>Email label>
                        <label>
                            <input type="email" name="email" class="form-control" placeholder="525266345@qq.com">
                        label>
                    div>
                    <div class="form-group">
                        <label>Gender label><br/>
                        <div class="form-check form-check-inline">
                            <label>
                                <input class="form-check-inline" type="radio" name="gender" value="1">
                            label>
                            <label class="form-check-label">label>
                        div>
                        <div class="form-check form-check-inline">
                            <label>
                                <input class="form-check-inline" type="radio" name="gender" value="0">
                            label>
                            <label class="form-check-label">label>
                        div>
                    div>
                    <div class="form-group">
                        <label>department label>
                        <label>
                            
                            <select class="form-control" name="department.id">
                                
                                
                                
                                <option th:each="dept:${departments}"
                                        th:text="${dept.getDepartmentName()}"
                                        th:value="${dept.getId()}">option>
                            select>
                        label>
                    div>
                    <div class="form-group">
                        <label>Birth label>
                        <label>
                            <input type="text" name="birth" class="form-control"
                                   placeholder="2022-08-05 11:11:11">
                        label>
                    div>
                    <button type="submit" class="btn btn-primary">添加button>
                form>
            main>
        div>
    div>
    
    
    
    <script type="text/javascript" src="/static/js/jquery-3.2.1.slim.min.js">script>
    <script type="text/javascript" src="/static/js/popper.min.js">script>
    <script type="text/javascript" src="/static/js/bootstrap.min.js">script>
    
    
    <script type="text/javascript" src="/static/js/feather.min.js">script>
    <script>
        feather.replace()
    script>
    
    
    <script type="text/javascript" src="/static/js/Chart.min.js">script>
    <script>
        var ctx = document.getElementById("myChart");
        var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
                datasets: [{
                    data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                    lineTension: 0,
                    backgroundColor: 'transparent',
                    borderColor: '#007bff',
                    borderWidth: 4,
                    pointBackgroundColor: '#007bff'
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: false
                        }
                    }]
                },
                legend: {
                    display: false,
                }
            }
        });
    script>
    
    body>
    
    html>
    
    • 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
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • update.html
    DOCTYPE html>
    
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
    
        <title>Dashboard Template for Bootstraptitle>
        
        <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    
        
        <link th:href="@{/css/dashboard.css}" rel="stylesheet">
        <link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
        <style type="text/css">
            /* Chart.js */
    
            @-webkit-keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            @keyframes chartjs-render-animation {
                from {
                    opacity: 0.99
                }
                to {
                    opacity: 1
                }
            }
    
            .chartjs-render-monitor {
                -webkit-animation: chartjs-render-animation 0.001s;
                animation: chartjs-render-animation 0.001s;
            }
        style>
    head>
    
    <body>
    
    <div th:insert="~{commons/commons::topbar}">div>
    
    <div class="container-fluid">
        <div class="row">
            
            <div th:insert="~{commons/commons::sidebar(active='list.html')}">div>
    
            <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                <form th:action="@{/emp}" method="post">
                    
                    <input type="hidden" name="id" th:value="${emp.getId()}">
                    <div class="form-group">
                        <label>LastName label>
                        <label>
                            
                            <input th:value="${emp.getLastName()}" type="text" name="lastName" class="form-control" placeholder="zach">
                        label>
                    div>
                    <div class="form-group">
                        <label>Email label>
                        <label>
                            
                            <input th:value="${emp.getEmail()}" type="email" name="email" class="form-control" placeholder="525266345@qq.com">
                        label>
                    div>
                    <div class="form-group">
                        <label>Gender label><br/>
                        <div class="form-check form-check-inline">
                            <label>
                                
                                <input th:checked="${emp.getGender()==1}" class="form-check-inline" type="radio" name="gender" value="1">
                            label>
                            <label class="form-check-label">label>
                        div>
                        <div class="form-check form-check-inline">
                            <label>
                                
                                <input th:checked="${emp.getGender()==0}" class="form-check-inline" type="radio" name="gender" value="0">
                            label>
                            <label class="form-check-label">label>
                        div>
                    div>
                    <div class="form-group">
                        <label>department label>
                        <label>
                            
                            <select class="form-control" name="department.id">
                                
                                
                                
                                
                                <option th:selected="${dept.getId==emp.getDepartment().getId()}"
                                        th:each="dept:${departments}"
                                        th:text="${dept.getDepartmentName()}"
                                        th:value="${dept.getId()}">
                                option>
                            select>
                        label>
                    div>
                    <div class="form-group">
                        <label>Birth label>
                        <label>
                            
                            <input th:value="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}"
                                   type="text" name="birth" class="form-control"
                                   placeholder="2022-08-05 11:11:11">
                        label>
                    div>
                    <button type="submit" class="btn btn-primary">确认修改button>
                form>
            main>
        div>
    div>
    
    
    
    <script type="text/javascript" src="/static/js/jquery-3.2.1.slim.min.js">script>
    <script type="text/javascript" src="/static/js/popper.min.js">script>
    <script type="text/javascript" src="/static/js/bootstrap.min.js">script>
    
    
    <script type="text/javascript" src="/static/js/feather.min.js">script>
    <script>
        feather.replace()
    script>
    
    
    <script type="text/javascript" src="/static/js/Chart.min.js">script>
    <script>
        var ctx = document.getElementById("myChart");
        var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
                datasets: [{
                    data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                    lineTension: 0,
                    backgroundColor: 'transparent',
                    borderColor: '#007bff',
                    borderWidth: 4,
                    pointBackgroundColor: '#007bff'
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: false
                        }
                    }]
                },
                legend: {
                    display: false,
                }
            }
        });
    script>
    
    body>
    
    html>
    
    • 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
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 404.html
    DOCTYPE html>
    
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    		<meta name="description" content="">
    		<meta name="author" content="">
    
    		<title>Dashboard Template for Bootstraptitle>
    		
    		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    		
    		<link th:href="@{/css/dashboard.css}" rel="stylesheet">
    		<link th:href="@{/static/favicon.ico}" rel="shortcut icon"/>
    		<style type="text/css">
    			/* Chart.js */
    			
    			@-webkit-keyframes chartjs-render-animation {
    				from {
    					opacity: 0.99
    				}
    				to {
    					opacity: 1
    				}
    			}
    			
    			@keyframes chartjs-render-animation {
    				from {
    					opacity: 0.99
    				}
    				to {
    					opacity: 1
    				}
    			}
    			
    			.chartjs-render-monitor {
    				-webkit-animation: chartjs-render-animation 0.001s;
    				animation: chartjs-render-animation 0.001s;
    			}
    		style>
    	head>
    
    	<body>
    		<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
    			<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">Company namea>
    			<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
    			<ul class="navbar-nav px-3">
    				<li class="nav-item text-nowrap">
    					<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">Sign outa>
    				li>
    			ul>
    		nav>
    
    		<div class="container-fluid">
    			<div class="row">
    				<nav class="col-md-2 d-none d-md-block bg-light sidebar">
    					<div class="sidebar-sticky">
    						<ul class="nav flex-column">
    							<li class="nav-item">
    								<a class="nav-link active" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-file">
    										<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z">path>
    										<polyline points="13 2 13 9 20 9">polyline>
    									svg>
    									Orders
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-shopping-cart">
    										<circle cx="9" cy="21" r="1">circle>
    										<circle cx="20" cy="21" r="1">circle>
    										<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6">path>
    									svg>
    									Products
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-users">
    										<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2">path>
    										<circle cx="9" cy="7" r="4">circle>
    										<path d="M23 21v-2a4 4 0 0 0-3-3.87">path>
    										<path d="M16 3.13a4 4 0 0 1 0 7.75">path>
    									svg>
    									Customers
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-bar-chart-2">
    										<line x1="18" y1="20" x2="18" y2="10">line>
    										<line x1="12" y1="20" x2="12" y2="4">line>
    										<line x1="6" y1="20" x2="6" y2="14">line>
    									svg>
    									Reports
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-layers">
    										<polygon points="12 2 2 7 12 12 22 7 12 2">polygon>
    										<polyline points="2 17 12 22 22 17">polyline>
    										<polyline points="2 12 12 17 22 12">polyline>
    									svg>
    									Integrations
    								a>
    							li>
    						ul>
    
    						<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
                  <span>Saved reportsspan>
                  <a class="d-flex align-items-center text-muted" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                    <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-plus-circle"><circle cx="12" cy="12" r="10">circle><line x1="12" y1="8" x2="12" y2="16">line><line x1="8" y1="12" x2="16" y2="12">line>svg>
                  a>
                h6>
    						<ul class="nav flex-column mb-2">
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-file-text">
    										<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
    										<polyline points="14 2 14 8 20 8">polyline>
    										<line x1="16" y1="13" x2="8" y2="13">line>
    										<line x1="16" y1="17" x2="8" y2="17">line>
    										<polyline points="10 9 9 9 8 9">polyline>
    									svg>
    									Current month
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-file-text">
    										<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
    										<polyline points="14 2 14 8 20 8">polyline>
    										<line x1="16" y1="13" x2="8" y2="13">line>
    										<line x1="16" y1="17" x2="8" y2="17">line>
    										<polyline points="10 9 9 9 8 9">polyline>
    									svg>
    									Last quarter
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-file-text">
    										<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
    										<polyline points="14 2 14 8 20 8">polyline>
    										<line x1="16" y1="13" x2="8" y2="13">line>
    										<line x1="16" y1="17" x2="8" y2="17">line>
    										<polyline points="10 9 9 9 8 9">polyline>
    									svg>
    									Social engagement
    								a>
    							li>
    							<li class="nav-item">
    								<a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
    									<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-file-text">
    										<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
    										<polyline points="14 2 14 8 20 8">polyline>
    										<line x1="16" y1="13" x2="8" y2="13">line>
    										<line x1="16" y1="17" x2="8" y2="17">line>
    										<polyline points="10 9 9 9 8 9">polyline>
    									svg>
    									Year-end sale
    								a>
    							li>
    						ul>
    					div>
    				nav>
    
    				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
    					<h1>404h1>
    				main>
    			div>
    		div>
    
    		
    		
    		<script type="text/javascript" src="/static/js/jquery-3.2.1.slim.min.js" >script>
    		<script type="text/javascript" src="/static/js/popper.min.js" >script>
    		<script type="text/javascript" src="/static/js/bootstrap.min.js" >script>
    
    		
    		<script type="text/javascript" src="/static/js/feather.min.js" >script>
    		<script>
    			feather.replace()
    		script>
    
    		
    		<script type="text/javascript" src="/static/js/Chart.min.js" >script>
    		<script>
    			var ctx = document.getElementById("myChart");
    			var myChart = new Chart(ctx, {
    				type: 'line',
    				data: {
    					labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
    					datasets: [{
    						data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
    						lineTension: 0,
    						backgroundColor: 'transparent',
    						borderColor: '#007bff',
    						borderWidth: 4,
    						pointBackgroundColor: '#007bff'
    					}]
    				},
    				options: {
    					scales: {
    						yAxes: [{
    							ticks: {
    								beginAtZero: false
    							}
    						}]
    					},
    					legend: {
    						display: false,
    					}
    				}
    			});
    		script>
    
    	body>
    
    html>
    
    • 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
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • commons.html
    DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    
    
    <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0" th:fragment="topbar">
        <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#"> [[${session.loginUser}]] a>
        <input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
        <ul class="navbar-nav px-3">
            <li class="nav-item text-nowrap">
                <a class="nav-link" th:href="@{/user/logout}">注销a>
            li>
        ul>
    nav>
    
    
    
    
    <nav class="col-md-2 d-none d-md-block bg-light sidebar" th:fragment="sidebar">
        <div class="sidebar-sticky">
            <ul class="nav flex-column">
                <li class="nav-item">
                    <a th:class="${active=='main.html' ? 'nav-link active' : 'nav-link'}" th:href="@{/index.html}">
                        <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>
                        首页 <span class="sr-only">(current)span>
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-file">
                            <path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z">path>
                            <polyline points="13 2 13 9 20 9">polyline>
                        svg>
                        Orders
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-shopping-cart">
                            <circle cx="9" cy="21" r="1">circle>
                            <circle cx="20" cy="21" r="1">circle>
                            <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6">path>
                        svg>
                        Products
                    a>
                li>
                <li class="nav-item">
                    <a th:class="${active=='list.html' ? 'nav-link active' : 'nav-link'}" th:href="@{/emps}">
                        <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-users">
                            <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2">path>
                            <circle cx="9" cy="7" r="4">circle>
                            <path d="M23 21v-2a4 4 0 0 0-3-3.87">path>
                            <path d="M16 3.13a4 4 0 0 1 0 7.75">path>
                        svg>
                        员工管理
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-bar-chart-2">
                            <line x1="18" y1="20" x2="18" y2="10">line>
                            <line x1="12" y1="20" x2="12" y2="4">line>
                            <line x1="6" y1="20" x2="6" y2="14">line>
                        svg>
                        Reports
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-layers">
                            <polygon points="12 2 2 7 12 12 22 7 12 2">polygon>
                            <polyline points="2 17 12 22 22 17">polyline>
                            <polyline points="2 12 12 17 22 12">polyline>
                        svg>
                        Integrations
                    a>
                li>
            ul>
    
            <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
                <span>Saved reportsspan>
                <a class="d-flex align-items-center text-muted" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                    <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-plus-circle"><circle cx="12" cy="12" r="10">circle><line x1="12" y1="8" x2="12" y2="16">line><line x1="8" y1="12" x2="16" y2="12">line>svg>
                a>
            h6>
            <ul class="nav flex-column mb-2">
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-file-text">
                            <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
                            <polyline points="14 2 14 8 20 8">polyline>
                            <line x1="16" y1="13" x2="8" y2="13">line>
                            <line x1="16" y1="17" x2="8" y2="17">line>
                            <polyline points="10 9 9 9 8 9">polyline>
                        svg>
                        Current month
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-file-text">
                            <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
                            <polyline points="14 2 14 8 20 8">polyline>
                            <line x1="16" y1="13" x2="8" y2="13">line>
                            <line x1="16" y1="17" x2="8" y2="17">line>
                            <polyline points="10 9 9 9 8 9">polyline>
                        svg>
                        Last quarter
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-file-text">
                            <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
                            <polyline points="14 2 14 8 20 8">polyline>
                            <line x1="16" y1="13" x2="8" y2="13">line>
                            <line x1="16" y1="17" x2="8" y2="17">line>
                            <polyline points="10 9 9 9 8 9">polyline>
                        svg>
                        Social engagement
                    a>
                li>
                <li class="nav-item">
                    <a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">
                        <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-file-text">
                            <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z">path>
                            <polyline points="14 2 14 8 20 8">polyline>
                            <line x1="16" y1="13" x2="8" y2="13">line>
                            <line x1="16" y1="17" x2="8" y2="17">line>
                            <polyline points="10 9 9 9 8 9">polyline>
                        svg>
                        Year-end sale
                    a>
                li>
            ul>
        div>
    nav>
    
    
    
    html>
    
    • 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
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • Java类
    • Department
    package com.zach.pojo;
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    /**
     * @author : Zach
     * @date : 2022-07-28 11:17
     * @description : TODO
     * @modified by : Zach
     */
    
    //部门表
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Department {
    
        private Integer id;
        private String departmentName;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • Employee
    package com.zach.pojo;
    
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    import java.util.Date;
    
    /**
     * @author : Zach
     * @date : 2022-07-28 11:19
     * @description : TODO
     * @modified by : Zach
     */
    
    //员工表
    @Data
    @NoArgsConstructor
    public class Employee {
    
        private Integer id;
        private String lastName;
        private String email;
        private Integer gender; //男1 女0
    
        private Department department;
        private Date birth;
    
        public Employee(Integer id, String lastName, String email, Integer gender, Department department) {
            this.id = id;
            this.lastName = lastName;
            this.email = email;
            this.gender = gender;
            this.department = department;
            //默认的创建日期
            this.birth = new Date();
        }
    }
    
    
    • 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
    • DepartmentDao
    package com.zach.dao;
    
    import com.zach.pojo.Department;
    import org.springframework.stereotype.Repository;
    
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * @author : Zach
     * @date : 2022-07-28 11:29
     * @description : TODO
     * @modified by : Zach
     */
    
    //部门dao
    @Repository
    public class DepartmentDao {
        //模拟数据库中的数据
        private static Map<Integer, Department> departments = null;
    
        static {
            departments = new HashMap<Integer,Department>();//创建一个部门表
    
            departments.put(101,new Department(101,"教学部"));
            departments.put(102,new Department(102,"市场部"));
            departments.put(103,new Department(103,"教研部"));
            departments.put(104,new Department(104,"运营部"));
            departments.put(105,new Department(105,"后勤部"));
    
        }
    
        //获得所有的部门信息
        public Collection<Department> getDepartments(){
            return departments.values();
        }
    
        //通过id得到部门
        public Department getDepartmentById(Integer id){
            return departments.get(id);
        }
    
    
    
    }
    
    
    • 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
    • EmployeeDao
    package com.zach.dao;
    
    import com.zach.pojo.Department;
    import com.zach.pojo.Employee;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;
    
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * @author : Zach
     * @date : 2022-07-28 11:53
     * @description : TODO
     * @modified by : Zach
     */
    
    //员工Dao
    @Repository
    public class EmployeeDao {
        //模拟数据库中的数据
        private static Map<Integer, Employee> employees = null;
        //员工有所属的部门
        @Autowired
        private DepartmentDao departmentDao;
    
        static {
            employees = new HashMap<Integer, Employee>();//创建一个  表
    
            employees.put(1001,new Employee(1001,"张天道","525266345@qq.com",1,new Department(101,"教学部")));
            employees.put(1002,new Employee(1002,"张天道z","z525266345@qq.com",0,new Department(102,"市场部")));
            employees.put(1003,new Employee(1003,"张天道t","t525266345@qq.com",1,new Department(103,"教研部")));
            employees.put(1004,new Employee(1004,"张天道d","d525266345@qq.com",0,new Department(104,"运营部")));
            employees.put(1005,new Employee(1005,"张天道?","?525266345@qq.com",1,new Department(105,"后勤部")));
    
        }
    
        //主键自增!
        private static Integer initId = 1006;
        //增加一个员工
        public void save(Employee employee){
            if (employee.getId()==null){
                employee.setId(initId++);
            }
    
            employee.setDepartment(departmentDao.getDepartmentById(employee.getDepartment().getId()));
            employees.put(employee.getId(),employee);
    
        }
    
        //查询全部员工信息
        public Collection<Employee> getAll(){
            return employees.values();
        }
    
        //通过id查询员工
        public Employee getEmployeeById(Integer id){
            return employees.get(id);
        }
    
        //通过id删除员工
        public void delete(Integer id){
            employees.remove(id);
        }
    
    
    
    }
    
    
    • 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
    • LoginHandlerInterceptor
    package com.zach.config;
    
    import org.springframework.web.servlet.HandlerInterceptor;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * @author : Zach
     * @date : 2022-07-29 12:29
     * @description : TODO
     * @modified by : Zach
     */
    
    public class LoginHandlerInterceptor implements HandlerInterceptor {
    
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    
            //登陆成功之后,应该有用户的session
            Object loginUser = request.getSession().getAttribute("loginUser");
    
            if (loginUser==null){//没有登录
                request.setAttribute("msg","没有权限,请先登录");
                request.getRequestDispatcher("/index.html").forward(request,response);
                return false;
            }else {
                return true;
            }
    
        }
    
    }
    
    
    • 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
    • MyLocaleResolver
    package com.zach.config;
    
    import org.springframework.web.servlet.LocaleResolver;
    import org.thymeleaf.util.StringUtils;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.util.Locale;
    
    /**
     * @author : Zach
     * @date : 2022-07-29 11:06
     * @description : TODO
     * @modified by : Zach
     */
    
    public class MyLocaleResolver implements LocaleResolver {
    
        //解析请求
        @Override
        public Locale resolveLocale(HttpServletRequest request) {
            //获取请求中的语言参数
            String language = request.getParameter("l");
    
            Locale locale = Locale.getDefault();//如果没有就使用默认的
    
            //如果请求的链接携带了国际化的参数
            if(!StringUtils.isEmpty(language)){
                //zh_CN
                String[] split = language.split("_");
                //split:国家,地区
                locale = new Locale(split[0], split[1]);
            }
    
            return locale;
        }
    
        @Override
        public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    
        }
    }
    
    
    • 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
    • MyMvcConfig
    package com.zach.config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.servlet.LocaleResolver;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    /**
     * @author : Zach
     * @date : 2022-07-28 11:11
     * @description : TODO
     * @modified by : Zach
     */
    
    @Controller
    public class MyMvcConfig implements WebMvcConfigurer {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("index");
            registry.addViewController("/index.html").setViewName("index");
            registry.addViewController("/main.html").setViewName("dashboard");
        }
    
        //自定义的国际化组件就生效了!
        @Bean
        public LocaleResolver localeResolver(){
            return new MyLocaleResolver();
        }
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
            registry.addResourceHandler("/templates/**" ).addResourceLocations("classpath:/templates/");
        }
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoginHandlerInterceptor())
                    .addPathPatterns("/**")
                    .excludePathPatterns("/index.html"
                            ,"/","/user/login","/css/*"
                            ,"/js/**","/img/**"
                            ,"/static/favicon.ico");
        }
    }
    
    
    • 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
    • EmployeeController
    package com.zach.controller;
    
    import com.zach.dao.DepartmentDao;
    import com.zach.dao.EmployeeDao;
    import com.zach.pojo.Department;
    import com.zach.pojo.Employee;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    import java.util.Collection;
    
    /**
     * @author : Zach
     * @date : 2022-07-29 13:21
     * @description : TODO
     * @modified by : Zach
     */
    
    @Controller
    public class EmployeeController {
    
        @Autowired
        EmployeeDao employeeDao;
        @Autowired
        DepartmentDao departmentDao;
    
        @RequestMapping("/emps")
        public String list(Model model){
            Collection<Employee> employees = employeeDao.getAll();
            model.addAttribute("emps", employees);
            return "emp/list";
        }
    
        @GetMapping("/emp")
        public String toAddPage(Model model){
            //查出所有部门的信息
            Collection<Department> departments = departmentDao.getDepartments();
            model.addAttribute("departments", departments);
            return "emp/add";
        }
    
        @PostMapping("/emp")
        public String addEmp(Employee employee){
            System.out.println("save=>"+employee);
            employeeDao.save(employee);//调用底层业务方法保存员工信息
            //添加的操作 forward
            return "redirect:/emps";
        }
    
        //跳转到员工信息修改页面
        @GetMapping("/emp/{id}")
        public String toUpdateEmp(@PathVariable("id") Integer id, Model model){
            //查出原来的数据
            Employee employee = employeeDao.getEmployeeById(id);
            model.addAttribute("emp",employee);
            //查出所有部门的信息
            Collection<Department> departments = departmentDao.getDepartments();
            model.addAttribute("departments", departments);
            return "emp/update";
        }
    
        @PostMapping("/updateEmp")
        public String updateEmp(Employee employee){
            employeeDao.save(employee);
            return "redirect:/emps";
        }
    
        //删除员工
        @GetMapping("/delemp/{id}")
        public String updateEmp(@PathVariable("id") int id){
            employeeDao.delete(id);
            return "redirect:/emps";
        }
    }
    
    
    • 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
    • LoginController
    package com.zach.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.thymeleaf.util.StringUtils;
    
    import javax.servlet.http.HttpSession;
    
    /**
     * @author : Zach
     * @date : 2022-07-29 11:58
     * @description : TODO
     * @modified by : Zach
     */
    
    @Controller
    public class LoginController {
    
        @RequestMapping("/user/login")
        public String login(
                @RequestParam("username") String username,
                @RequestParam("password") String password,
                Model model, HttpSession session){
            //具体的业务:
            if (!StringUtils.isEmpty(username)
                    && "123456".equals(password)){
                session.setAttribute("loginUser",username);
                return "redirect:/main.html";
            }
            else {
                //告诉用户,你登录失败了!
                model.addAttribute("msg","用户名或者密码错误!");
                return "index";
            }
    
        }
    
        @RequestMapping("/user/logout")
        public String logout(HttpSession session){
            session.invalidate();
            return "redirect:/index.html";
        }
    
    }
    
    
    • 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
    • pom.xml
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>2.7.2version>
            <relativePath/> 
        parent>
    
        <groupId>com.zachgroupId>
        <artifactId>springboot-03-webartifactId>
        <version>0.0.1-SNAPSHOTversion>
        <name>springboot-03-webname>
        <description>springboot-03-webdescription>
    
        <properties>
            <java.version>1.8java.version>
        properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
    
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-testartifactId>
                <scope>testscope>
            dependency>
    
            <dependency>
                <groupId>org.webjarsgroupId>
                <artifactId>jqueryartifactId>
                <version>3.4.1version>
            dependency>
    
            
            
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-thymeleafartifactId>
            dependency>
    
            
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
            dependency>
        dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-maven-pluginartifactId>
                plugin>
            plugins>
        build>
    
    project>
    
    
    • 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
    • 项目结构
      在这里插入图片描述
      在这里插入图片描述

     
     

    —————— THE END ——————
     
  • 相关阅读:
    【使用python绘制统计图表】
    云原生网关可观测性综合实践
    C Primer Plus(6) 中文版 第14章 结构和其他数据形式 14.5 嵌套结构
    【附源码】计算机毕业设计JAVA智能社区管理系统
    【PHPWrod】使用PHPWord导出word文档
    redmine安装插件提示Tasks: TOP => redmine:plugins:migrate => environment
    [RK3568][Android11]内核Oops日志分析
    K线形态识别_镊子线
    C++模板
    Elasticsearch:从零开始创建一个 ingest pipeline 处理器
  • 原文地址:https://blog.csdn.net/Zachsj/article/details/126049529