首页 文章 精选 留言 我的

精选列表

搜索[响应式微服务],共10028篇文章
优秀的个人博客,低调大师

CentOS7设置SWAP分区,小内存服务器的救世主

前言 Swap分区在系统的物理内存(这里应该是运行内存)不够用的时候,把物理内存中的一部分空间释放出来,以供当前运行的程序使用。那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被释放的空间被临时保存到Swap分区中,等到那些程序要运行时,再从Swap分区中恢复保存的数据到内存中。 设置 1.添加SWAP分区 sh 复制代码 cd / && dd if=/dev/zero of=swapfile bs=1024 count=4194304 chmod 600 /swapfile && mkswap /swapfile swapon /swapfile && swapon -s echo "/swapfile swap swap defaults 0 0" >> /etc/fstab 注: count=4194304中4194304为交换分区大小 4194304=102410244大小为4G 交换区大小设置有个参考依据,物理内存小于4G则SWAP设置为物理内存的两倍、物理内存等于4G则SWAP设置为4G、物理内存大于4G则SWAP设置为物理内存的1/2。 2.重启系统 sh 复制代码 shutdown -r now 3.查看分区结果 sh 复制代码 free -m 4.关闭交换空间 sh 复制代码 cd / && swapoff swapfile && rm -rf swapfile

优秀的个人博客,低调大师

Spring Cloud Spring Boot mybatis分布式微服务云架构(七)开发Web应用(1)

静态资源访问在我们开发Web应用的时候,需要引用大量的js、css、图片等静态资源。 默认配置Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则: /static /public /resources /META-INF/resources 举例:我们可以在src/main/resources/目录下创建static,在该位置放置一个图片文件。启动程序后,尝试访问http://localhost:8080/D.jpg。如能显示图片,配置成功。 渲染Web页面在之前的示例中,我们都是通过@RestController来处理请求,所以返回的内容为json对象。那么如果需要渲染html页面的时候,要如何实现呢? 模板引擎在动态HTML实现上Spring Boot依然可以完美胜任,并且提供了多种模板引擎的默认配置支持,所以在推荐的模板引擎下,我们可以很快的上手开发动态网站。 Spring Boot提供了默认配置的模板引擎主要有以下几种: Thymeleaf FreeMarker Velocity Groovy Mustache Spring Boot建议使用这些模板引擎,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性,具体可见后文:支持JSP的配置 当你使用上述模板引擎中的任何一个,它们默认的模板配置路径为:src/main/resources/templates。当然也可以修改这个路径,具体如何修改,可在后续各模板引擎的配置属性中查询并修改。 Thymeleaf Thymeleaf是一个XML/XHTML/HTML5模板引擎,可用于Web与非Web环境中的应用开发。它是一个开源的Java库,基于Apache License 2.0许可,由Daniel Fernández创建,该作者还是Java加密库Jasypt的作者。 Thymeleaf提供了一个用于整合Spring MVC的可选模块,在应用开发中,你可以使用Thymeleaf来完全代替JSP或其他模板引擎,如Velocity、FreeMarker等。Thymeleaf的主要目标在于提供一种可被浏览器正确显示的、格式良好的模板创建方式,因此也可以用作静态建模。你可以使用它创建经过验证的XML与HTML模板。相对于编写逻辑或代码,开发者只需将标签属性添加到模板中即可。接下来,这些标签属性就会在DOM(文档对象模型)上执行预先制定好的逻辑。 示例模板: <table> <thead> <tr> <th th:text="#{msgs.headers.name}">Name</td> <th th:text="#{msgs.headers.price}">Price</td> </tr> </thead> <tbody> <tr th:each="prod : ${allProducts}"> <td th:text="${prod.name}">Oranges</td> <td th:text="${#numbers.formatDecimal(prod.price,1,2)}">0.99</td> </tr> </tbody> </table> 可以看到Thymeleaf主要以属性的方式加入到html标签中,浏览器在解析html时,当检查到没有的属性时候会忽略,所以Thymeleaf的模板可以通过浏览器直接打开展现,这样非常有利于前后端的分离。 在Spring Boot中使用Thymeleaf,只需要引入下面依赖,并在默认的模板路径src/main/resources/templates下编写模板文件即可完成。 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>

优秀的个人博客,低调大师

Spring Cloud Spring Boot mybatis分布式微服务云架构(八)开发Web应用(2)

在完成配置之后,举一个简单的例子,在快速入门工程的基础上,举一个简单的示例来通过Thymeleaf渲染一个页面。 @Controller public class HelloController { @RequestMapping("/") public String index(ModelMap map) { // 加入一个属性,用来在模板中读取 map.addAttribute("host", "http://blog.didispace.com"); // return模板文件的名称,对应src/main/resources/templates/index.html return "index"; } } <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8" /> <title></title> </head> <body> <h1 th:text="${host}">Hello World</h1> </body> </html> 如上页面,直接打开html页面展现Hello World,但是启动程序后,访问http://localhost:8080/,则是展示Controller中host的值:http://blog.didispace.com,做到了不破坏HTML自身内容的数据逻辑分离。 更多Thymeleaf的页面语法,还请访问Thymeleaf的官方文档查询使用。 Thymeleaf的默认参数配置 如有需要修改默认配置的时候,只需复制下面要修改的属性到application.properties中,并修改成需要的值,如修改模板文件的扩展名,修改默认的模板路径等。 # Enable template caching. spring.thymeleaf.cache=true # Check that the templates location exists. spring.thymeleaf.check-template-location=true # Content-Type value. spring.thymeleaf.content-type=text/html # Enable MVC Thymeleaf view resolution. spring.thymeleaf.enabled=true # Template encoding. spring.thymeleaf.encoding=UTF-8 # Comma-separated list of view names that should be excluded from resolution. spring.thymeleaf.excluded-view-names= # Template mode to be applied to templates. See also StandardTemplateModeHandlers. spring.thymeleaf.mode=HTML5 # Prefix that gets prepended to view names when building a URL. spring.thymeleaf.prefix=classpath:/templates/ # Suffix that gets appended to view names when building a URL. spring.thymeleaf.suffix=.html spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain. spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved. 支持JSP的配置Spring Boot并不建议使用,但如果一定要使用,可以参考此工程作为脚手架:JSP支持

优秀的个人博客,低调大师

OnItemClickListener不响应

根原因:listview(或其他有adapter的view)没有获得焦点 列子: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"//误点一:fill_parent android:orientation="vertical" android:descendantFocusability="blocksDescendants"//误点二 > 正确应该是 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > 切记: adapter的xml的主layout(RelativeLayout)不能用fill_parent 原因有二。 一: 原因:在adapter的xml中设置了 android:descendantFocusability="blocksDescendants" 注释:下面的item就是ListView的item android:beforeFocusability viewgroup在子项处理之前获得焦点 android:afterFocusability viewGroup在子项处理之后获得焦点 android:blocksFocusability viewGroup阻止子项获得焦点(以此子项的子项就能获得焦点) 二:在layout_......设置了fill_parent, 三 Android 长按setOnItemLongClickListener 注意细节 原理是fill_parent原来就是要求本layout全屏,但listview(或其他有adapter的view)限制item的高宽。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 gridview.setOnItemLongClickListener( new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Log.e( "setOnItemLongClickListener" , "setOnItemLongClickListener" ); return true ; } }); gridview.setOnItemClickListener( new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Log.e( "setOnItemClickListener" , "setOnItemClickListener" ); } }); 1.如果返回false那么onItemClick仍然会被调用。而且是先调用onItemLongClick,然后调用onItemClick。 如果返回true那么click就会被吃掉,onItemClick就不会再被调用了。 2.监听onItemClick以及onItemLongClick影响弹出菜单吗? onItemClick不影响;onItemLongClick如果返回true那么就会吃掉click事件,导致菜单不能弹出。 3.如何让包含button的item也能弹出菜单,回调onItemClick以及onItemLongClick的监听器呢? 需要设置Button属性:android:focusable="false" android:focusable="false"android:longClickable="true" android:longClickable="true"否则无法收到onItemLongClick 本文转自lilin9105 51CTO博客,原文链接:http://blog.51cto.com/7071976/1216753,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册