fragment

thymeleaf利用fragment解决html页面间获取context-path问题

时间秒杀一切 提交于 2020-02-06 18:32:24
问题说明 我使用spring boot+thymeleaf做了个项目,那前台页面都是html,里面有各种api调用和路径跳转。 大家都知道这些路径不能写死,为保证任何情况下路径的正确性,一般都是这种格式: 项目路径 +接口路径,例如:localhost:8080/system/api/user/1 现在已知thymeleaf页面中js要获取项目路径时这样的: <script type="text/javascript" th:inline="javascript"> /*<![CDATA[*/ var ctx = /*[[@{/}]]*/ ''; /*]]>*/ </script> ctx=/system/ 那我又不想每个页面都写这么一段,所以利用thymeleaf的片段引用特性可以把它抽成公共脚本供各html页面用。 解决方法 1.创建fragment.html <script type="text/javascript" th:inline="javascript" th:fragment="ctx"> /*<![CDATA[*/ var ctx = /*[[@{/}]]*/ ''; /*]]>*/ </script> 2.页面引用 <!--ctx--> <script th:replace="~{fragment::ctx}"/> 3.调整接口和路径格式 $.get(ctx+

[android]com.android.support:appcompat-v7:XXX 包导入无法Build

房东的猫 提交于 2020-02-04 15:14:28
在学习《Android编程权威指南》时,按书中要求添加com.android.support:appcompat的依赖,然后编译不通过,提示如下问题: 大概意思是,Android Pie之前支持这个库,我们建议迁移到AndroidX libraries…… 然后搜索了一下,原来2018年google开发者大会以后,相关库已经整合到AndroidX库中,这里放一个链接:(别人的说明) 1. AndroidX变化 1)常用依赖库对比: Old build artifact AndroidX build artifact com.android.support:appcompat-v7:28.0.2 androidx.appcompat:appcompat:1.0.0 com.android.support:design:28.0.2 com.google.android.material:material:1.0.0 com.android.support:support-v4:28.0.2 androidx.legacy:legacy-support-v4:1.0.0 com.android.support:recyclerview-v7:28.0.2 androidx.recyclerview:recyclerview:1.0.0 com.android.support

HTML5幻灯片库reveal.js使用

不问归期 提交于 2020-02-04 11:36:32
介绍 reveal.js 是一个用于实现幻灯片效果的库。使用该库。 github地址: github 提供了页面编辑功能: slides.com 官方demo: demo 我自己做的PPT地址: ppt (建议使用Chrome查看) 特点 reveal.js 有一下几个特点: 支持标签来区分每一页幻灯片 可以使用markdown来写内容 支持pdf的导出 支持演说注释 提供JavaScript API来控制页面 提供了多个默认主题和切换方式 自适应移动端和PC端 安装 从 reveal.js 上下载压缩包,并解压 进入 reveal.js 文件夹,直接修改 index.html 文件就可以 编辑后好,用浏览器打开html页面就可以看到PPT的内容。 必需的文件只有这几个: 使用方法 整体布局 幻灯片的内容需要包含在 <div class="reveal"> <div class="slides"> 的标签中。 一个 section 是一页幻灯片。当 section 包含在 section 中时,是一个纵向的幻灯片。 怎么理解呢? 可以这样理解:横向的幻灯片代表一章,纵向的幻灯片代表一章中的一节。那么横向的幻灯片在播放时是左右切换的,而纵向的幻灯片是上下切换的。For example: <div class="reveal"> <div class="slides">

同源策略以及绕过此限制的方法

孤街浪徒 提交于 2020-02-04 06:36:00
同源策略 源:由协议【https、http】+域名【a.com】+端口【80、443】组成,(ie中略有不同),同源策略是浏览器的核心安全策略,目的是将来自不同源的资源进行隔离,并控制不同源资源间的通信,从而减少安全威胁,增强安全性。 跨域中的一些限制以及不限制内容如下: 不限制内容: 脚本文件 js 图片资源 样式资源css iframe展示其他的的资源 a链接访问其他资源 多媒体等资源 form表单提交 限制内容: 跨域的方法【get、post可以】 跨域请求头不可以添加自定义头部 本地文件系统读写 iframe可以访问iframe整体,不能访问内容 cookie的限制,使用CORS需要withCredentials=true才可以带上cookie ======================================================== 一、同源策略 1、何为同源? 所谓"同源"指的两个网页url的三个部分是相同的: http://www.example.com:80/dir/page.html 协议相同 域名相同 端口相同 2、同源策略 同源策略是Web应用程序安全模型中的一个重要概念,它由 Netscape 公司在1995年引入浏览器。该策略最初是为保护DOM的访问而设计的,Web浏览器允许第一个Web页面中包含的脚本访问第二个Web页面中的数据

How to avoid fragment recreation when tap back button using navigation architecture actions?

女生的网名这么多〃 提交于 2020-02-03 10:45:27
问题 I am using android studio navigation component to create some fragments and switch between them using the actions. Problem is that each time I tap Back button to go back from a Fragment2 to Fragment1, Fragment one is recreated. I want to avoid that. I found solutions when one don't use navigation component and simply can replace ".replace" with ".add", but can't find any information on how to do the same with navigation component. 回答1: I think it's a normal thing that your fragment 1 is

How to pre-load a fragment before showing?

不想你离开。 提交于 2020-02-03 10:37:05
问题 In my activity I have several fullscreen fragments, each of them downloads some data from web (using an async task) and shows them to the user. The fragments are showed one at a time. To be more specific, each of the fragment readings some urls from a sqlite database, and fetch the content before showing them in a list, if that matters. The data loading tasks can be done in the OnCreate() function. I would like to preload all the fragment (at least starting the downloading), when I show a

Android模块开发-----用户信息模块(Fragment和Activity之间数据的传递)

天大地大妈咪最大 提交于 2020-02-03 00:04:52
在上一章节的 《Android模块开发------SQLite数据库的使用(登录模块)》 中,介绍了基本的登录模块,本节介绍一下用户模块的设计思路。 在登录成功,进入主界面后,通过ViewPager+Fragment的形式将Fragment添加到MainActivity,在用户UserFragment中,主要负责处理的就是显示当前用户的用户名,还有退出登录等简单的操作,后续有功能添加会在此更新。 (1)Activity和Activity之间数据的传递。 这种数据的传递方式,是开发过程中最常见的,通常会使用Intent、Bundle来进行数据的携带,然后跳转Activity。 Intent intent = new Intent ( ) ; //携带用户名信息到UserFragment显示 intent . putExtra ( "username" , username ) ; intent . setClass ( LoginActivity . this , MainActivity . class ) ; startActivity ( intent ) ; 使用Intent携带数据信息到MainActivity,在MainActivity中,通过下面的方式,可以得到传递的用户名信息。 String username = getIntent ( ) .

Android开发过程3——Activity向Fragment中传递数据

孤街浪徒 提交于 2020-02-02 02:40:23
一,Activity1向Activity2中传递数据的方法如下: Activity1传递数据: Intent i=new Intent(Login.this,menu.class); i.putExtra("data",userName);//userName为传递的数据 startActivity(i); Activity2 接收这个传递过来的参数: String Name=i.getStringExtra("data"); 二,Activity1和Activity2,其中宿主Activity2中有三个Fragment,现在要将Activity1中的数据传递到Activity2中的某一个碎片Fragment中,具体处理方法如下: 1、先通过Activity之间数据的传递将Activity1中的参数传递到宿主Activity2中,宿主Activity2中我们在写碎片布局的时候已经处理好了FragmentManaget和FragmentTransaction。接着在宿主Activity2中接收数据,接着将数据发送到Fragment中。 此代码为宿主中部分代码Activity2 . 3、在Fragment中接收数据: 来源: CSDN 作者: Mr 白白 链接: https://blog.csdn.net/weixin_40438421/article/details

ViewPager inside Fragment with margins and page transformer not rendering correctly

一个人想着一个人 提交于 2020-02-01 03:17:27
问题 I have a viewpager with fragments inside it. I use the code similar to e.g. ViewPager margin in PageTransformer transformations and padding so you can see the faded out edge of fragments on either side of the fragment you are currently viewing. But the problem is when the viewpager is first started, the fragments on either side are not faded and zoomed out. I.e. the transformPage method of my ZoomOutPageTransformer doesn't get called until you start swiping, so the initial off-page right /

java.lang.NullPointerException on setOnClickListener in Fragment

余生长醉 提交于 2020-01-30 11:36:51
问题 I'm pretty new to Android and I'm trying to create an application that will score matches of the Vex Robotics Competition. I have a ViewPager with fragments for each team and i have a lot of buttons that increase and decrease numbers in EditTexts . I created an OnClickListener for each one. This code was working before I introduced SharedPreferences to carry values to the activity that calculates the score. Fragment Code (sorry, there's a lot of it): package com.bearsandthings