• 。。。springboot


    1.@bean
    作用:相当于xml的配置 注入bean(给容器添加组件)。
    写一个方法,返回他的对象本身的值。
    方法名==id         返回类型==class          return的值 == 组件在容器的实例

    2.@conditional:(条件装配 底层)
    满足conditional指定的条件,才进行组件注入    @conditiononbean( name="tom") 只有容器中有tom这个bean下面的的类和方法才有效。


    3.ImportResource("classpath:beans.xml") 放在配置类里面,可以将配置文件的bean注入到容器里。

    4.@ConfigurationProperties(prefix = "mycar")  将配置文件的属性的值注入到类的属性里。

    @EnableConfigurationProperties(car.class)
    //1.开启car的属性配置,2.把car这个组件自动注册到容器内      不需要再car实体类上面写@component。

    5.springbootApplication
    (1)springbootconfigration :代表当前是配置类。
    (2)compaentscan:指定扫描哪些。
    (3)EnableAutoConfigration 


    lombok


    9.22
    thymeleaf模板
    思路:处理静态资源
    1.登录功能:
    (1)在controller里面写跳转到登录页面的方法@requestmapping("/"),
             找到登录页面(主页面)写他的controller方法,
            在此方法里面判断登录的账号密码。
    方法:if(!StringUtils.isEmpty(user.getUserName()) && "123456".equals(user.getPassword())
    在方法写一个User对象,用密码和user对象的password对比。
    写一个HttpSession参数,把登录的用户保存起来: session.setAttribute("user",user);
    在前端页面中就可以使用这个session对象。调用“user”值可以传入在浏览器传入的user对象的name。
    登录成功要重定向到main.html。return redirect:/main.html.  避免了表单重复提交。
    。。。。。redirect与forward的区别
    redirect:普通的return的返回的是一个页面的路径,而redirect则发送的是一个requestmapping的请求路径。直接把main.html的页面的请求路径加在redirect后面,
    直接重定向到了他的页面,而普通的return到他的页面的话,在每一次刷新的时候都会重复提交表单。
    forward:可以将request对象的信息带着供服务器使用。而redirect的对象不能共享数据

    在方法中写Model对象可以使用model.addAttribute()方法,在前端页面可以传入值  

    通过session对象将输入的userName和password属性将user对象用setattribute方法保存起来。

    2.实现将main主页的用户信息显示出来
    (1)首先    在前端页面f12找到用户信息的名称,然后在main.index页面找到相应的位置(ctrl+f),将他固定的值换成 [[${session.user.userName}]]
                                        
    thymeleaf的写法:
        链接使用 :th:src=@{链接}
        循环写法: 
                         
            
    抽取模板:
    th:include/repalce/include 
    例:

      抽取了common文件的fragment为leftmenu的。
       抽取了common文件的id为leftmenu的。

    使用
      model.addAttribute("users",users); 将users的值传入到前端


                  Trident
                  Internet
                  [[${user.password}]]
             
           


    拦截器
    1.实现一个HandlerInterceptor接口
    public class LoginInterceptor implements HandlerInterceptor {

    2。重写他的preHandle方法。
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    通过session获得user对象
            HttpSession session = request.getSession();
            Object user = session.getAttribute("user");
    判断是否登录,如果登录则放行
            if (user!=null){
    //          放行
                return true;
            }
    //        拦截住
    提示信息 
    在前端页面为:
            request.setAttribute("msg","请先登录");
            request.getRequestDispatcher("/").forward(request,response);
            return false;

        }

    3.配置拦截器
    编写一个类implements WebMvcConfigurer 加@Configuration注解表示交给spring容器管理。

    4.重写他的addInterceptors方法
    加上拦截的路径 addPathPatterns("/**")拦截所有
    excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**")表示放行的路径。


    @Configuration
    public class AdminWebConfig implements WebMvcConfigurer {
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
    //        /**  静态资源也被拦截
            registry.addInterceptor(new Logininterceptor()).addPathPatterns("/**")
                    .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**");

    9.24 
    1,-----------文件上传

    (1)

    enctype="multipart/form-data">
    form表单的action表示要发送到的地址,将action="@{/upload}在upload里面写文件上传的方法。

    文件上传表单的固定写法:method="post" enctype="multipart/form-data"

    (2)将文件封装在MultipartFile类型中,通过他的transferTo方法,存在起来。
     file.transferTo(new File("D:\\apicture\\"+originalFilename));


    使用servlet
    方法一:在启动类加 @ServletComponentScan(basePackages = "com.lz.springboot04")
    方法二:在servlet类加@WebServlet(urlPatterns = "/my")注册servlet组件,
    没有经过spring的拦截器1
     

  • 相关阅读:
    17.linuxGPIO应用编程
    教你如何使用云服务器搭建我的世界Minecraft服务器(超级简单-10分钟完成)
    测试工作十年,想对还在迷茫的朋友说:一点要做好个人规划...
    java基于springboot+vue学生考勤签到请假管理系统84y43
    QT中,QTableWidget 使用示例详细说明
    DirectX11 With Windows SDK--38 级联阴影贴图(CSM)
    Rocketmq学习2——Rocketmq消息过滤&事务消息&延迟消息原理源码浅析
    linux 网络命令
    软件生命周期过程
    Docker
  • 原文地址:https://blog.csdn.net/weixin_45713331/article/details/127118662