一、登录功能

1.1登录所涉及的功能主要包括拦截器,过滤器,用户在未登录的时候,访问页面会阻止访问的,如图所示:

实现这个功能的主要代码如下所示

 1 //拦截器
2 public class LoginHandlerInterceptor implements HandlerInterceptor {
3 //执行之前
4 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
5 Object username = request.getSession().getAttribute("username");
6 if(username ==null){
7 //未登录,返回登录页面
8 request.setAttribute("msg","没有权限,请先登录");
9 request.getRequestDispatcher("/index.html").forward(request,response);
10 return false;
11 }
12 return true;
13 }

解释:首先你登录的时候可以将用户名之类的信息封装在session对象里面,在重启项目后,session的生命周期结束,则Object username = request.getSession().getAttribute("username");

获取的username为空将执行为空操作,实现对用户的拦截。 request.getRequestDispatcher("/index.html").forward(request,response);就是重定向到indext页面。

二、国际化(实现中英文切换)

实现这个功能需要我们在resources下面建立国际化包,如下

解释:login指默认时的,login_en_US.properties指英文,login_zh_CN指中文,在配置文件中,对需要进行转化的进行书写,如下

除此之外还需要在application.properties里面配置

1 #国际化
2 spring.messages.basename=i18n.login

配置完之后将可以实现浏览器端的语言切换(大家应该不明白什么是浏览器端吧)接着向下看

我们在浏览器上可以设置英文还是中文,上面的操作就可以实现中英文切换,但这种方法并不是我们想要的,我们想要的是在登录页面下,点击按钮设置相应的语言,(别着急,向下看) 1

/国际化
2 public class MyLocaleResolver implements LocaleResolver {
3 //解析信息
4 @Override
5 public Locale resolveLocale(HttpServletRequest request) {
6 String l = request.getParameter("l");
7 //默认问英文
8 Locale locale=Locale.getDefault();
9 if(!StringUtils.isEmpty(l)){
10 //根据分割线进行分割
11 String[] split = l.split("_");
12 locale = new Locale(split[0], split[1]);
13 }
14 return locale;
15 }
16
17 @Override
18 public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
19
20 }
21 }

这个是我们中英文切换按钮

1 <a class="btn btn-sm" th:href="@{/index.html(l='zh_cn')}">中文</a>
2 <a class="btn btn-sm"th:href="@{/index.html(l='en_US')}">English</a>

大体解释一下,我们在点击的时候会携带参数的跳转,英文en_US,中文zh_CN,在MyLocaleResolver方法中我们首先获取到是en_US还是zh_CN,然后通过spit方法进行分割,英文分割成en US 中文 zh CN

它们是以key value的形式存储,在springBoot底层可以自动辨别它是什么语言,在springBoot底层默认如下:

1  private static Locale initDefault() {
2 String language, region, script, country, variant;
3 language = AccessController.doPrivileged(
4 new GetPropertyAction("user.language", "en"));//表示英文
5 // for compatibility, check for old user.region property
6 region = AccessController.doPrivileged(
7 new GetPropertyAction("user.region"));

三、mybatis-plus实现CRUD

配置过程很简单详情请看mybatis-plus官网:https://mp.baomidou.com/guide/

在这里想说的就是我在这个里面遇见的一些问题,因为是第一次使用mybatis-plus,所有对于这些并不是太明白,在自己捣鼓了半天,自己差不多明白了,其实参考内容可以访问

https://blog.csdn.net/weixin_45616483/article/details/106011637

四、RestFul风格提交

GET请求

后端:

1 public User selectUserById(@PathVariable("id") Integer id){
2 return userService.getUserById(id);
3 }

前端:localhost:8989/xxx/id

post请求

后端:

1 public User insert(User user){
2 userService.insert(user);
3 return user;
4 }

前端:

1 <form action="http://localhost:8989/XXX" method="post">
2 <input type="text" name="username" value="zhansan"/>
3 <input type="text" name="password" value="123"/>
4 <input type="submit" value="提交"/>
5
6 </form>

PUT请求:

后端

1 public User update(XXX xxxr){
3 return xxxService.update(xxx);
4 }

前端

1 <form action="http://localhost:8989/xxx" method="post">
2 <input type="hidden" name="_method" value="PUT"/>
3 <input type="text" name="username" value="zhangsan"/>
4 <input type="text" name="password" value="123"/>
5 <input type="submit" value="提交"/>
6
7 </form>

DELETE请求

后端:

1    public String delete(@PathVariable("id") Integer id){
2 xxxService.delete(id);
3
4 }

前端:

<form action="http://localhost:8989/xxx/x" method="post">
<input type="text "name="_method" value="DELETE"/>
<input type="submit" value="提交"/> >

一个简单的springboot+mybatis-plus+thymeleaf的学生管理系统的更多相关文章

  1. 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程

    工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...

  2. 一个简单的SpringBoot入门程序

    1. 使用IDEA构建Maven项目 <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  3. Thymeleaf+SpringBoot+Mybatis实现的家庭财务管理系统

    项目简介 项目来源于:https://gitee.com/darlingzhangsh/graduation_project 本系统是基于Thymeleaf+SpringBoot+Mybatis.是非 ...

  4. 7 — 简单了解springboot中的thymeleaf

    1.官网学习地址 https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html 2.什么是thymeleaf? 一张图看明白: 解读: ...

  5. idea从零搭建简单的springboot+Mybatis

    需用到的sql /* Navicat MySQL Data Transfer Source Server : localhost root Source Server Version : 80012 ...

  6. IntelliJ IDEA搭建一个简单的springboot项目

    一.IDEA 安装包 百度网盘链接:https://pan.baidu.com/s/1MYgZaBVWXgy64KxnoeJSyg 提取码:7dh2 IDEA注册码获取:http://idea.lan ...

  7. springboot+mybatis+springSecurity+thymeleaf

    配置步骤: .pom <dependencies> <dependency> <groupId>org.springframework.security</g ...

  8. 最简单的 springboot 发送邮件,使用thymeleaf模板

    1,导入需要的包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...

  9. idea搭建一个简单的springboot项目

    1.file->new->project 2.选中Spring  Initializr 3.填写项目信息: 4.选中Web -> Spring Web

随机推荐

  1. 第8.15节 Python重写自定义类的__repr__方法

    一. 引言 前面两节分别介绍了Python类中的__str__和__repr__方法的作用和语法,所有新式类都支持这两个方法,因为object类实现了这两个方法,但实际上各位开发者在自定义类的过程中, ...

  2. SQL Server 批量插入数据方案 SqlBulkCopy 的简单封装,让批量插入更方便

    一.Sql Server插入方案介绍 关于 SqlServer 批量插入的方式,有三种比较常用的插入方式,Insert.BatchInsert.SqlBulkCopy,下面我们对比以下三种方案的速度 ...

  3. [Java复习]架构部署 超时重试 幂等防重

    画一下你们系统的整体架构图,说说各个服务在生产环境怎么部署的? 核心:服务框架.注册中心.网关 即使你没有用很多微服务架构里的东西,只要有上述三个东西,配合上写一些文档,接口文档,分布式系统架构,其实 ...

  4. justify-content属性详解

    justify-content 定义了flexbox flexbox内的元素在主轴的方向上的对齐方式. 它可以设置以下几种对齐方式: 靠近一方 justify-content:center: /*fl ...

  5. 谈谈 javascript的 call 和 apply用法

    定义: ECMAScript规范为所有函数都包含两个方法(这两个方法非继承而来),call和apply,这两个函数都是在特定的作用域中调用函数,能改变函数的作用域,实际上是改变函数体内 this 的值 ...

  6. SNOI2020 部分题解

    D1T1 画图可以发现,多了一条边过后的图是串并联图.(暂时不确定) 然后我们考虑把问题变成,若生成树包含一条边\(e\),则使生成树权值乘上\(a_e\),否则乘上\(b_e\),求最终的生成树权值 ...

  7. 把java编译成exe和安装包

    由于某些项目甲方迟迟不结算尾款,这就很烦,只能想一些办法 我们知道java,python之类的代码是没有隐私可言的,那么怎么办,总要发给甲方验收,这就要做一些操作来确保自己的利益. 通过在源代码里加上 ...

  8. 终于不再对transition和animation,傻傻分不清楚了 --vue中使用transition和animation

    以前写页面注重在功能上,对于transition和animation是只闻其声,不见其人,对于页面动画效果心理一直痒痒的.最近做活动页面,要求页面比较酷炫,终于有机会认真了解了. transition ...

  9. 【Jmeter Linux环境下运行方法】

    Jmeter 运行 1.cd  jmeter/apache-jmeter-4.0/bin 2.执行 ./jmeter -n -t jmx脚本文件 -l 测结果.jtl文件 -e -o html文件路径 ...

  10. SPI机制剖析——基于DriverManager+ServiceLoader的源码分析

    我的上一篇博客类加载器与双亲委派中提到,SPI机制是一种上级类加载器调用下级类加载器的情形,因此会打破类加载的双亲委派模型.为了深入理解其中的细节,本博客详细剖析一下SPI机制,并以JDBC为例,基于 ...