Freemark

对一个列表的遍历,如果要对第一个已经最后一个元素做特殊的处理如何的判断呢?

<#list books as book>

<#if book_index = 0>...</#if><!--判断是否是第一个元素-->

<#if !book_has_next>...</#if><!--判断是否是最后一个元素-->

</#list>

使用jQuery.ajax()进行表单提交时,需要传递参数,最直接的方法便是使用Form的serializa()将表单序列化,前提只是将Form表单中的name属性与数据库的字段名保持一致便可;但如果遇到再次往其中增加参数的状况呢,我们该如何处理?

First:

其实,jQuery ajax的serialize() 方法是将表单序列化为键值对(key1=value1&key2=value2…)后提交,使用标准的 URL-encoded 编码表示文本字符串,而jQuery ajax-param()方法也是将其序列化一个 key/value 对象,如:

var params = { width:1900, height:1200 };
var str = jQuery.param(params);
$("#results").text(str);

  结果为:

width=1680&height=1050

  恰好两者转换的形式一样,于是在serialize()中想要增加其他参数的时候,就可以:

jQuery.post(url, $.param({aa:'aa1',bb:'bb'})+'&'+jQuery('#fm').serialize(), function (result) {
 ...
}

于是传到后台的参数中,除过form表单中的含有name属性的字段外,就额外增加了aa以及bb两个参数,我们的问题也便迎刃而解了!

spring boot 默认是不支持Druid数据源的,个人想用阿里的druid数据源提供的监控功能

maven引入的其它必要jar包就不提了,这里明提醒一下要使用到@ConfigurationProperties,所以要引入spring-boot-configuration-processor

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5

在application.properties写上druid的配置信息如下,注意到前缀用spring.datasource.druid,为我的自定义配置前缀

# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mboot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.name=druid


# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
spring.datasource.druid.initialSize=5
spring.datasource.druid.minIdle=5
spring.datasource.druid.maxActive=20
# 配置获取连接等待超时的时间
spring.datasource.druid.maxWait=60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.druid.minEvictableIdleTimeMillis=300000
spring.datasource.druid.validationQuery=SELECT 1 FROM t_user
spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testOnBorrow=true
spring.datasource.druid.testOnReturn=false
# 打开PSCache,并且指定每个连接上PSCache的大小
spring.datasource.druid.poolPreparedStatements=true
spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.druid.filters=stat,wall,log4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
#spring.datasource.druid.useGlobalDataSourceStat=true

第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde

2018年06月10日 00:42:00
阅读数:539
[java]  view plain  copy
  1. ***************************  
  2. APPLICATION FAILED TO START  
  3. ***************************  
  4.   
  5. Description:  
  6.   
  7. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.  
  8.   
  9. Reason: Failed to determine a suitable driver class  
  10.   
  11.   
  12. Action:  
  13.   
  14. Consider the following:  
  15.     If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.  
  16.     If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).  

解决方法:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

[java]  view plain  copy
  1. @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)  
  2. public class BdservoApplication {  
  3.   
  4.     public static void main(String[] args) {  
  5.         SpringApplication.run(BdservoApplication.class, args);  
  6.     }  
  7. }  
文章标签:  springboot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

非ban必选

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值