小编Tom*_*icz的帖子

Backbone.js将更改事件绑定到模型内的集合

我对Backbone很新,请原谅我这个问题有点明显.我对模型中的集合有问题.当集合发生更改时,它不会注册为模型中的更改(并且不会保存).

我已经设置了我的模型:

var Article = Backbone.Model.extend({

   defaults: {
       "emsID" :  $('html').attr('id')
   },

   initialize: function() { 
       this.tags = new App.Collections.Tags();
   },

   url: '/editorial_dev.php/api/1/article/persist.json'
});
Run Code Online (Sandbox Code Playgroud)

如果我更新标签集合并手动保存模型,这可以正常工作:

this.model.tags.add({p : "a"});

this.model.save();
Run Code Online (Sandbox Code Playgroud)

但是如果未保存模型,则视图不会注意到更改.谁能看到我做错了什么?

javascript jquery backbone.js

9
推荐指数
1
解决办法
2万
查看次数

无法将名称'repository:repository'解析为(n)'type definition'组件.

我在尝试集成Spring Data时遇到此错误.完整的堆栈跟踪是

nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/data/jpa/spring-jpa.xsd; lineNumber: 18; columnNumber: 48; src-resolve: Cannot resolve the name 'repository:repository' to a(n) 'type definition' component.
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
Run Code Online (Sandbox Code Playgroud)

XML文件是

<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://www.springframework.org/schema/data/jpa"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
    <repositories base-package="com.interviewedonline.poc.repositories" />
Run Code Online (Sandbox Code Playgroud)

xml spring spring-data-jpa

9
推荐指数
1
解决办法
2万
查看次数

简单的常规运算符问题:Math.min(params.max?params.int('max'):10,100)

你能告诉我表达方式吗?

Math.min(params.max ? params.int('max') : 10, 100)
Run Code Online (Sandbox Code Playgroud)

作品?如果,它不适合常规三元组,那么这个特殊的算子是什么?

谢谢

grails groovy

8
推荐指数
2
解决办法
1万
查看次数

Spring MVC是否支持JSR 311注释?

虽然帮助了别人,我注意到他们试图用做Spring开发@GET,@Consumes和@Path注释.据我所知,这些注释来自JSR-311规范.

我只是建议他们使用Spring @RequestMapping注释将端点映射到他们的控制器,但它让我对Spring MVC(任何版本)是否支持JSR 311感到好奇?

rest spring jax-rs spring-mvc jsr311

8
推荐指数
1
解决办法
3054
查看次数

没有XML的Boot-strapping Spring Data JPA

什么是Java @Configuration相当于:

<repositories base-package="com.acme.repositories" />
Run Code Online (Sandbox Code Playgroud)

在Spring Data JPA中?我试图摆脱XML配置@Configuration,而不是类,但是通过JpaRepositoryConfigDefinitionParser来源阅读是徒劳的.

我能得到的最接近的是:

@Bean
public RepositoryFactorySupport repositoryFactory() {
    return new JpaRepositoryFactory(entityManagerFactory().createEntityManager())
}

@Bean
public BookDao bookDao() {
    return repositoryFactory().getRepository(BookDao.class)
}
Run Code Online (Sandbox Code Playgroud)

但是<repositories/>标记功能更强大:它会自动为CrudRepositoryCLASSPATH上的所有接口创建DAO .此外,似乎我的解决方案不会将事务应用于DAO,而不是默认的Spring Data JPA行为.

java spring jpa spring-data spring-data-jpa

8
推荐指数
2
解决办法
3130
查看次数

如何避免在Quartz中同时运行两个作业?

我在下面编写代码,我正在运行两个工作.首先是10秒的间隔,另一个是3秒的间隔.但最终在某些时候它们会同时执行.有没有机制来避免这种情况

    JobDetail jDetail = new JobDetail("Job1", "group1", MyJob.class);
    CronTrigger crTrigger = new CronTrigger("cronTrigger", "group1", "0/10 * * * * ?");
    sche.scheduleJob(jDetail, crTrigger);

    jDetail = new JobDetail("Job2","group2",MyJob2.class);
    crTrigger = new CronTrigger("cronTrigger2","group2","0/3 * * * * ?");
    sche.scheduleJob(jDetail, crTrigger);
Run Code Online (Sandbox Code Playgroud)

java quartz-scheduler

8
推荐指数
1
解决办法
7335
查看次数

Scala中的括号匹配---功能方法

假设我想解析一个带有各种开括号和右括号的字符串(我在标题中使用了括号,因为我认为它更常见 - 但问题仍然相同),这样我就可以在列表中分隔所有更高级别.

鉴于:

[hello:=[notting],[hill]][3.4(4.56676|5.67787)][the[hill[is[high]]not]]
Run Code Online (Sandbox Code Playgroud)

我想要:

List("[hello:=[notting],[hill]]", "[3.4(4.56676|5.67787)]", "[the[hill[is[high]]not]]")
Run Code Online (Sandbox Code Playgroud)

我这样做的方法是计算开始和结束括号,并在我将计数器设置为0时添加到列表中.但是,我有一个丑陋的命令性代码.您可以假设原始字符串格式正确.

我的问题是:对于这个问题,什么是一个很好的功能方法?

注意:我曾考虑过使用for ... yield结构,但是考虑到计数器的使用我不能得到一个简单的条件(我必须有条件只是为了更新计数器)而且我不知道如何使用它在这种情况下构建.

functional-programming scala

8
推荐指数
1
解决办法
2901
查看次数

随机选择两个值

在我的算法中,我有两个值,我需要随机选择,但每个值必须选择预定次数.

到目前为止,我的解决方案是将选项放入向量中正确的次数,然后将其洗牌.在C++中:

// Example choices (can be any positive int)
int choice1 = 3; 
int choice2 = 4;

int number_of_choice1s = 5;
int number_of_choice2s = 1;

std::vector<int> choices;
for(int i = 0; i < number_of_choice1s; ++i) choices.push_back(choice1);
for(int i = 0; i < number_of_choice2s; ++i) choices.push_back(choice2);
std::random_shuffle(choices.begin(), choices.end());
Run Code Online (Sandbox Code Playgroud)

然后我保留一个迭代器choices,每当我需要一个新的迭代器时,我会增加迭代器并获取该值.

这有效,但似乎可能有一种更有效的方式.因为我总是知道我将使用的每个值中有多少我想知道是否有更多的算法方法来执行此操作,而不仅仅是存储值.

c++ random algorithm

8
推荐指数
1
解决办法
2355
查看次数

春天的单身人士被召唤两次

在我的春季申请中遇到一些问题.

我有非常简单的春豆,它们被注入各种其他春豆.在我发现调试时,它们被调用了两次,Constructor和@PostConstruct都被调用了两次.

我的应用程序没有前端技术.它仅用于与后端任务相关.

弹簧配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">


    <context:component-scan base-package="com.green.integration" />

    <!-- ######################################################## -->
    <!-- EXPOSING SPRING BEAN VIA HTTPINVOKER SPRING REMOTING -->
    <!-- ######################################################## -->

    <bean name="/switch"
        class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
        <property name="service" ref="SwitchController" />
        <property name="serviceInterface"
            value="com.green.ISwitchController" />
    </bean>

    <!-- Load in application properties reference -->
    <bean id="applicationProperties"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:application.properties" />
    </bean>


    <bean id="mongo" class="com.mongodb.Mongo">
        <constructor-arg value="${mongo.server}" />
        <constructor-arg value="${mongo.port}" />
    </bean>

    <bean id="morphia" class="com.google.code.morphia.Morphia"> …
Run Code Online (Sandbox Code Playgroud)

java singleton spring postconstruct

8
推荐指数
2
解决办法
1万
查看次数

春天原型豆和春天的好处

我已经逐渐掌握了Spring一段时间,并且认为我对这些概念有一个合理的想法,但是我在另一个线程中遇到了信息,这让我的事情变得颠倒了......

"...虽然无论范围如何都在所有对象上调用初始化生命周期回调方法,但在原型的情况下,不会调用已配置的销毁生命周期回调.客户端代码必须清理原型范围的对象并释放原型bean的昂贵资源为了让Spring容器释放原型范围的bean所拥有的资源,尝试使用自定义bean后处理器,它包含对需要清理的bean的引用."

这让我觉得我有真正的用例,我想使用原型bean,例如,我需要每个请求一个"新"bean实例.但是根据我对这个片段的理解(来自Spring 3文档),Spring坚持引用需要清理的bean(引用本身意味着bean不会被垃圾收集器自动清除).此外,我认为必须手动清理原型bean所拥有的资源.

如果这是正确的,有人可以告诉我吗?如果是这样,有一个典型的模式来处理这个?我很欣赏一个答案,它可以描述Spring以这种方式实现原型bean的架构原因.

java architecture spring garbage-collection

8
推荐指数
3
解决办法
8603
查看次数