underscore用法,完整示例,喜欢就点赞加关注,以后会有更多惊喜

html

引入underscore.js

<script id='tab1-content' type='text/html'>

    ##for(var i=0;i<tab1.length;i++){## <div class="contentLeft">
        <img src="{{tab1[i].imgUrl}}" alt="">
        </div>
        <div class="contentright">
            <ul class="contentright1 clear">
                <li class="crightli1">{{tab1[i].username}}</li>
                <li><img src="../images/community/icon.png" alt=""></li>
                <li>在 <a href="#" title="">{{tab1[i].address}}</a> 发布的游记</li>
                <li><span class="iconfont">&#xe610;</span><span class="li4span">{{tab1[i].people}}</span>人赞</li>
                <li><span class="iconfont">&#xe612;</span> {{tab1[i].lastResponse}}</li>
            </ul>
            <ul class="contentright2 clear">
                <li class="cr2li1">
                    <p class="p1"><a href="#">{{tab1[i].p1}}</a></p>
                    <p class="p2">{{tab1[i].p2}}</p>
                </li>
                <li class="cr2li2"><img src="{{tab1[i].cr2li2}}" alt=""></li>
            </ul>
        </div>
        ##}##

</script>

js

 $.ajax({
                url: "../json/community.json",
                success: function(res) {
                    var tab1 = res.tab1;
                    var _html = $('#tab1-content').html();
                    var _html_fn = _.template(_html);//_.template模板
                    var html = _html_fn({ tab1: tab1 });
                    $('#c1').html(html);

}

})

json


到此结束,本人比较喜欢用实例来说明其功能,如果有不懂的就直接找相关的api


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是在application.yml文件中配置多个数据源,默认使用第一个数据源的示例: ```yaml spring: datasource: # 第一个数据源配置 primary: url: jdbc:mysql://localhost:3306/primary_db?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false username: primary_user password: primary_password driver-class-name: com.mysql.cj.jdbc.Driver # 第二个数据源配置 secondary: url: jdbc:mysql://localhost:3306/secondary_db?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false username: secondary_user password: secondary_password driver-class-name: com.mysql.cj.jdbc.Driver # 配置多数据源时,需要手动指定默认数据源为primary mybatis-plus: configuration: # 指定默认数据源为primary default-enum-type-handler: com.baomidou.mybatisplus.extension.handlers.MybatisEnumTypeHandler default-scripting-language-type: org.apache.ibatis.scripting.xmltags.XMLLanguageDriver map-underscore-to-camel-case: true mapper-locations: classpath*:mapper/**/*.xml global-config: db-config: logic-delete-value: -1 logic-not-delete-value: 1 id-type: auto field-strategy: not_empty ``` 以上示例中,我们配置了两个数据源:primary和secondary。 在mybatis-plus配置中,我们手动指定了默认数据源为primary。这样,当我们使用mybatis-plus进行数据库操作时,默认使用primary这个数据源。 当然,如果需要使用secondary数据源,也可以手动指定。例如: ```java @Service public class UserServiceImpl implements UserService { @Autowired @Qualifier("secondaryDataSource") private DataSource dataSource; @Autowired private UserMapper userMapper; @Override public List<User> listUsers() { // 指定使用secondary数据源 DynamicDataSourceContextHolder.setDataSourceKey("secondary"); List<User> userList = userMapper.selectList(null); // 切换回默认数据源 DynamicDataSourceContextHolder.clearDataSourceKey(); return userList; } } ``` 以上示例中,我们首先注入了名为secondaryDataSource的数据源。然后,在需要使用secondary数据源的方法中,手动指定使用secondary数据源。最后,记得切换回默认数据源。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值