小编Can*_*hiu的帖子

servlet映射url模式中/和/*之间的区别

熟悉的代码:

<servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

我的理解是/*地图http://host:port/context/*.

怎么样/?它肯定不会映射到http://host:port/contextroot.事实上,它会接受http://host:port/context/hello,但拒绝http://host:port/context/hello.jsp.

任何人都可以解释如何http://host:port/context/hello映射?

web.xml servlets url-pattern

171
推荐指数
4
解决办法
17万
查看次数

如何使用BOOST_FOREACH同时迭代两个向量?

我想用BOOST FOREACH复制以下内容

std::vector<int>::const_iterator i1;
std::vector<int>::const_iterator i2;
for( i1 = v1.begin(), i2 = v2.begin();
     i1 < v1.end() && i2 < v2.end();
     ++i1, ++i2 )
{
     doSomething( *i1, *i2 );
}
Run Code Online (Sandbox Code Playgroud)

c++ boost iterator boost-foreach

33
推荐指数
3
解决办法
2万
查看次数

通过身份函数后,左值引用变为无效

有人解释为什么在通过"身份"功能后引用变得无效,foo1?是不是A传入和返回的"地址" foo1

struct A {
    A(int x) : x_(x) {}
    int x_;
};

int main() {

    function<const A&(const A& r)> foo1 = [](const A& r) { 
        return r;
    };

    vector<A> vec{1, 2, 3};
    cout << foo1(vec[0]).x_ << endl;   // RUNTIME ERROR

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题行与以下方面有何不同:

const A& r = vec[0];
const A& r1 = r;
Run Code Online (Sandbox Code Playgroud)

c++ c++11

32
推荐指数
2
解决办法
1502
查看次数

使用Cobertura Maven插件运行集成测试

我无法让Cobertura插件在Maven中运行集成测试.我找到的这个问题最接近的答案是http://jira.codehaus.org/browse/MCOBERTURA-86.但是,这个问题仍然存在漏洞.我在03年4月3日尝试了Stevo建议的配置,它没有用.

我的POM

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.3-SNAPSHOT</version>
            <reportSets>
            <reportSet>
                <reports>
                    <report>cobertura-integration</report>
                </reports>
            </reportSet>
            </reportSets>               
        </plugin>   
    </plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)

这与Stevo提供的配置片段完全相同.

integration-testing maven-2 cobertura

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

Linq:在TransactionScope中删除并插入相同的主键值

我想用一个事务中的新记录替换DB中的现有记录.使用TransactionScope,我有

using ( var scope = new TransactionScope())
{
     db.Tasks.DeleteAllOnSubmit(oldTasks);
     db.Tasks.SubmitChanges();

     db.Tasks.InsertAllOnSubmit(newTasks);
     db.Tasks.SubmitChanges();

     scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)

我的节目扔了

System.InvalidOperationException: Cannot add an entity that already exists.
Run Code Online (Sandbox Code Playgroud)

经过一些反复试验,我发现罪魁祸首在于删除和插入之间没有任何其他执行指令.如果我在第一个SubmitChanges()和InsertAllOnSubmit()之间插入其他代码,一切正常.谁能解释为什么会这样?这非常令人担忧.

我尝试了另一个来更新对象:

IEnumerable<Task> tasks = ( ... some long query that involves multi tables )
.AsEnumerable()
.Select( i => 
{
    i.Task.Duration += i.LastLegDuration;
    return i.Task;
}
db.SubmitChanges();
Run Code Online (Sandbox Code Playgroud)

这既不起作用.db没有获取任务的任何更改.

编辑:

此行为似乎与交易无关.最后,我采用了效率极低的更新:

newTasks.ForEach( t =>
{
     Task attached = db.Tasks.Single( i => ... use primary id to look up ... );
     attached.Duration = ...;
     ... more updates, Property …
Run Code Online (Sandbox Code Playgroud)

c# transactionscope linq-to-sql

15
推荐指数
1
解决办法
2326
查看次数

C#模糊扩展方法

LinqKit有一个扩展方法ForEach用于IEnumerable与相冲突System.Collections.Generic.IEnumerable.

Error   4   The call is ambiguous between the following methods or properties: 
'LinqKit.Extensions.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)' 
and 
'System.Linq.EnumerableExtensionMethods.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)'
Run Code Online (Sandbox Code Playgroud)

我怎样才能摆脱这个错误?

c# extension-methods

14
推荐指数
1
解决办法
6765
查看次数

如何在std :: for_each中为一个lambda捕获std :: unique_ptr"by move"

我正在学习c ++ 11中的新功能并遇到了这个问题.我想通过在lambda中移动它作为for_each的参数来捕获unique_ptr.

建立:

std::array<int,4> arr = {1,3,5,6};
std::unique_ptr<int> p(new int);  (*p) = 3;
Run Code Online (Sandbox Code Playgroud)

尝试1 - 不起作用,因为unique_ptr没有复制构造函数.c ++ 0x没有指定移动语法.

std::for_each(arr.begin(), arr.end(), [p](int& i) { i+=*p; });
Run Code Online (Sandbox Code Playgroud)

尝试2 - 使用bind将p的移动副本绑定到一个带有int&的函数:

std::for_each(arr.begin(), arr.end(),
     std::bind([](const unique_ptr<int>& p, int& i){
          i += (*p);
     }, std::move(p))
);
Run Code Online (Sandbox Code Playgroud)

编译器抱怨说 'result' : symbol is neither a class template nor a function template.

这个练习的主要目的是了解如何在lambda中捕获可移动变量,该lambda被缓存以供以后使用.

c++ lambda c++11

12
推荐指数
1
解决办法
5466
查看次数

c ++ 11:std :: forward的微妙之处:身份真的有必要吗?

我设置了一个测试用例来了解完美转发.

std::string inner(const std::string& str ) {
return "const std::string&";
}
std::string inner(std::string& str ) {
    return "std::string&";
}
std::string inner(const std::string&& str ) {
    return "const std::string&&";
}
std::string inner(std::string&& str ) {
    return "std::string&&";
}

template <typename T> void outer(T&& t) {
  std::cout << "t: " << t << std::endl;
  std::cout << "perfect forward: " << inner(std::forward<T>(t)) << std::endl;
  std::cout << std::endl;
}

void PerfectForwarding()
{
     outer("literal");
     outer(lvalue);
     outer(constlvalue);
     outer(rvalue());
     outer(constrvalue());
}
Run Code Online (Sandbox Code Playgroud)

std::forward按预期工作.当我实现我自己的没有身份的转发函数时,有趣的行为出现了:

template <typename T> T&& …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010 visual-c++ c++11

12
推荐指数
1
解决办法
1920
查看次数

C#:Array.CreateInstance:无法将[*]类型的对象强制转换为类型[]

我想通过调用在c#中创建一个非零下界一维数组

Array.CreateInstance(typeof(int), new int[] { length }, new int[] { lower });
Run Code Online (Sandbox Code Playgroud)

返回数组的类型不是int [],而是int [*].任何人都可以详细说明这是什么意思?我希望能够将此数组返回给调用者,例如,

int[] GetArray() { ... }
Run Code Online (Sandbox Code Playgroud)

谢谢.

c#

12
推荐指数
1
解决办法
2103
查看次数

将序列与hsqldb中的标识链接

在PostgreSql中,可以定义一个序列并将其用作表的主键.在HsqlDB中,仍然可以完成创建自动增量标识列,该列不链接到任何用户定义的序列.是否可以使用用户定义的序列作为HsqlDB中自动增量标识列的生成器?

PostgreSql中的示例sql:

CREATE SEQUENCE seq_company_id START WITH 1;

CREATE TABLE company (
  id bigint PRIMARY KEY DEFAULT nextval('seq_company_id'),
  name varchar(128) NOT NULL CHECK (name <> '')
);
Run Code Online (Sandbox Code Playgroud)

什么是HsqlDB中的等价物?

谢谢.

sql sequence hsqldb

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