layui ajax 上传文件_layui的一个登录和权限示例

搭建项目

项目架构是springboot+thymeleaf+layui,结构如下图,文件有点多,分成两张图

7c7eb3b10dc9828e2b1d2b66f63adb7c.png
3570cc78a948b553b13993233a0368bc.png

其中resources资源文件里的layui文件夹下就是layui的所有文件,内容需要到官网下载,解压后全部复制即可

pom.xml

<?xml version="1.0" encoding="UTF-8"?>4.0.0org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASEcom.haijunyin layuidemo-permission 0.0.1-SNAPSHOTlayuidemo-permissionDemo project for Spring Bootwar1.8org.springframework.boot spring-boot-starter-web  org.springframework.boot spring-boot-starter-tomcat javax.servlet javax.servlet-api 4.0.0providedorg.thymeleaf thymeleaf 3.0.11.RELEASEorg.thymeleaf thymeleaf-spring4 3.0.11.RELEASEorg.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-test testorg.springframework.boot spring-boot-maven-plugin 

application.properties

#thymelea模板配置xspring.thymeleaf.prefi=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8#热部署文件,页面不产生缓存,及时更新spring.thymeleaf.cache=falsespring.resources.chain.strategy.content.enabled=truespring.resources.chain.strategy.content.paths=/**

LayuidemoPermissionApplication.java

package com.haijunyin.layuidemo.permission;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;import org.springframework.context.annotation.ComponentScan;import org.springframework.scheduling.annotation.EnableAsync;/** * 继承SpringBootServletInitializer,因为继承SpringBootServletInitializer是继承WebApplicationInitializer的,而servlet容器启动的时候 * 会将WebApplicationInitializer相关的所有子类实例化(这也是servlet3.0以上的版本提供支持),所以我们还需要在pom.xml * 文件中导入servlet3.0及以上的版本 */@ComponentScan(value = "com.haijunyin.layuidemo.permission")@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})@EnableAsyncpublic class LayuidemoPermissionApplication extends SpringBootServletInitializer{ @Override public SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(LayuidemoPermissionApplication.class); } public static void main(String[] args) { SpringApplication.run(LayuidemoPermissionApplication.class, args); }}

admin_user_list.html

 layui在线调试
  • 演示说明
  • 日期
  • 分页
  • 上传
  • 滑块

点击上传,或将文件拖拽到此处

admin_user_list.html

 layui在线调试
  • 演示说明
  • 日期
  • 分页
  • 上传
  • 滑块

点击上传,或将文件拖拽到此处

layui {{ layui.v }} 提供强力驱动

DefineAdapter.java,拦截器配置

package com.haijunyin.layuidemo.permission.config;import com.haijunyin.layuidemo.permission.interceptor.LoginInterceptor;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.ArrayList;import java.util.List;@Configurationpublic class DefineAdapter implements WebMvcConfigurer { @Autowired private LoginInterceptor loginInterceptor; //登录拦截器 @Override public void addInterceptors(InterceptorRegistry registry) { //排除不被拦截的资源 List excludePaths = new ArrayList<>(); //layui的静态文件 excludePaths.add("/layui/**"); //静态页面 excludePaths.add("/**/*.html"); //登录 excludePaths.add("/"); excludePaths.add("/login");// excludePaths.add("/error"); registry.addInterceptor(loginInterceptor). addPathPatterns("/**").excludePathPatterns(excludePaths); }}

AdminController.java

package com.haijunyin.layuidemo.permission.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping(value = "admin")public class AdminController { @RequestMapping(value = "list
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值