问题列表 - 第44792页

@Autowired对象获取空值

尝试设置项目但在通过Spring自动装配对象时失败.

package se.hsr.web;

public class TestRunner {

    public static void main(String[] args) {
        ContactDAO cd = new ContactDAOImpl();
        Contact contact = new Contact();
        contact.setFirstname("Zorro");
        cd.addContact(contact);
    }

}

package se.hsr.web;
Run Code Online (Sandbox Code Playgroud)

当调用cd.addContact时,运行this会给我一个NullPointerException.ContactDaoImpl:

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ContactDAOImpl implements ContactDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public void addContact(Contact contact) {
        sessionFactory.getCurrentSession().save(contact);
    }
Run Code Online (Sandbox Code Playgroud)

我的servlet文件:

    <?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:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="se.hsr.web"/>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" …
Run Code Online (Sandbox Code Playgroud)

java spring autowired java-ee

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

如何找到最高价的记录?

这将返回最大信号,而不是完整的记录:

self.prices.maximum(:price_field)
Run Code Online (Sandbox Code Playgroud)

目前,我发现这样的记录:

def maximum_price
  self.prices.find(:first, :conditions => "price = #{self.prices.maximum(:price_field)}" )
end
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?因为上面需要两个SQL语句来使它工作,并且它在某种程度上感觉不对.

PS.另外,我希望如果多个记录具有相同的"最大"值,那么它应该得到具有最新updated_at值的记录.这意味着另一个SQL语句?

PPS.有没有人知道Rails中AREL和非AREL事物的详细参考?ActiveRecord查询的Rails指南还不够!

(我正在使用Rails 3)

=== UPDATE ===

使用AREL我执行以下操作:

self.prices.order("updated_at DESC").maximum(:price_field)
Run Code Online (Sandbox Code Playgroud)

但是,这仅给出了最大价值,而不是完整的记录:(
而且,是利用maximum()真AREL?

activerecord max arel ruby-on-rails-3

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

如何知道GraphicsPath是否包含C#中的一个点

我正在使用.NET绘制图表,我想在用户点击它们时突出显示对象.当图形完全包含在矩形中时很容易:

if (figure.Bounds.Contains(p)) // bounds is a rectangle
Run Code Online (Sandbox Code Playgroud)

但如果数字很复杂,我不知道如何管理它GraphicsPath.

GraphicsPath为图(绿色圆圈)定义了以下内容.

的GraphicsPath

我想在用户点击它时突出显示该图.我想知道是否Point包含a GraphicsPath.

有任何想法吗?提前致谢.

.net c# drawing system.drawing

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

替换与图像字段关联的文件,而无需django复制它

我有一个表单的userprofile

class profile():
  #the next line is just an abstract
  profile_images='volumes/media/root/userprofile/profile_images/'
  image=models.ImageField(upload_to=profile_images)
Run Code Online (Sandbox Code Playgroud)

在"profile_images"目录中,用户上传的最后5个文件为个人资料图片,即:

image_1
image_2
image_3
image_4
image_5
Run Code Online (Sandbox Code Playgroud)

让我们说当前的profile.image是image_1.现在我想让用户选择以前的图像之一.我写的函数将图像更改为从表单中收到的图像看起来像:

def change_profile_image(userprofile,path_to_new_image):
  f = open(path_to_new_image, 'r')
  userprofile.image = ImageFile(f)
  userprofile.save()
Run Code Online (Sandbox Code Playgroud)

作为示例,用户选择image_3,并且在执行该代码之后,前述目录看起来像:

image_1
image_2
image_3
image_4
image_5
volumes/media/root/userprofile/profile_images/image_3
Run Code Online (Sandbox Code Playgroud)

当然,这不是我想要的.我想要的只是更改与我的配置文件实例的ImageField相关联的文件,而不是Django复制任何文件.
任何想法如何解决?

django

5
推荐指数
1
解决办法
5662
查看次数

Cipher对象是否可重用?

我可以Cipher跨多个方法使用相同的对象,因为方法参数getInstanceinit不更改?

例如,假设应用程序的多个部分decrypt在实用程序类中使用该方法.传递的所有加密值都使用相同的密钥和算法生成.那么,我可以重用同一个Cipher对象吗?

是不是真的值得担心的多个作品Cipher(这可能导致创建KeySpec,SecretKey对象)?

java encryption performance

13
推荐指数
1
解决办法
4695
查看次数

将(x,y)映射到单个数值

我想要一个函数将(x,y)值映射到单个数字值和Java中相应的反向映射.

例如(2,34)应该映射到某个值100,如果我们有100,我们应该能够找到(2,34).

java algorithm

4
推荐指数
3
解决办法
2799
查看次数

使用SQL查找重叠间隔

我想从一个表中提取行,该表的间隔与查询中指定的间隔相交.假设我有一个简单的ID, DATE_START, DATE_END桌子,两个查询参数P_DATE_STARTP_DATE_END,什么是表达的查询,使我找到其中的所有行的最简单的方法[DATE_START, DATE_END]至少有一个共同的元素用[P_DATE_START, P_DATE_END]


更新:

为了使预期结果更清晰,请在下面找到输入值和预期结果的列表.Colums是 DATE_START, DATE_END, P_DATE_START, P_DATE_END, MATCH.

16, 17, 15, 18, YES
15, 18, 16, 17, YES
15, 17, 16, 18, YES
16, 18, 15, 17, YES
16, 17, 18, 19, NO
18, 19, 16, 17, NO
Run Code Online (Sandbox Code Playgroud)

sql

3
推荐指数
1
解决办法
5444
查看次数

web-app_2_5.xsd在eclipse中验证web.xml时显示错误

我不知道我能做些什么才能导致这种情况因为我花在编程上的时间已经延长了,而且我已经忘记了我可能做过的事情.但现在当我加载Eclipse时,它说:

The errors below were detected when validating the file "web-app_2_5.xsd" via the file "web.xml".  In most cases these errors can be detected by validating "web-app_2_5.xsd" directly.  However it is possible that errors will only occur when web-app_2_5.xsd is validated in the context of web.xml. 
s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'JDK 6 XML-related APIs'.
The entity name must immediately follow the '&' in the entity reference.
Run Code Online (Sandbox Code Playgroud)

我的前几行web.xml看起来就像这样.

<?xml version="1.0" encoding="UTF-8"?> …
Run Code Online (Sandbox Code Playgroud)

java xml java-ee

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

Python和re.compile返回不一致的结果

我试图取代的所有实例href="../directory"href="../directory/index.html".

在Python中,这个

reg = re.compile(r'<a href="../(.*?)">')
for match in re.findall(reg, input_html):
    output_html = input_html.replace(match, match+'index.html')
Run Code Online (Sandbox Code Playgroud)

产生以下输出:

href="../personal-autonomy/index.htmlindex.htmlindex.htmlindex.html"  
href="../paternalism/index.html"  
href="../principle-beneficence/index.htmlindex.htmlindex.html"  
href="../decision-capacity/index.htmlindex.htmlindex.html" 
Run Code Online (Sandbox Code Playgroud)

知道为什么它适用于第二个链接,但其他链接不适用?

相关部分来源:

<p> 

 <a href="../personal-autonomy/">autonomy: personal</a> |
 <a href="../principle-beneficence/">beneficence, principle of</a> |
 <a href="../decision-capacity/">decision-making capacity</a> |
 <a href="../legal-obligation/">legal obligation and authority</a> |
 <a href="../paternalism/">paternalism</a> |
 <a href="../identity-personal/">personal identity</a> |
 <a href="../identity-ethics/">personal identity: and ethics</a> |
 <a href="../respect/">respect</a> |
 <a href="../well-being/">well-being</a> 

</p> 
Run Code Online (Sandbox Code Playgroud)

编辑:重复的'index.html'实际上是多个匹配的结果.(例如,href ="../ personal-autonomy/index.htmlindex.htmlindex.htmlindex.html"是因为../personal-autonomy在原始源中被找到四次).

作为一般的正则表达式问题,如何在不向所有匹配项添加额外"index.html"的情况下替换所有实例?

python regex

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

PayPal ExpressCheckout(Payflow):无效的供应商账户错误代码:26

这真让我抓狂!我不能让PayPal快递(Payflow?)api工作....

paypal沙箱告诉我:

测试帐号:AAAA.B_CCCCCCCCCC_biz@XXXXX.com

API用户名:AAAA.B_CCCCCCCCCC_biz_api1.XXXXX.com

API密码:DDDDDDDDDD

签名:ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

在paypayfunctions.php我写道:

$ API_User = "AAAA.B_CCCCCCCCCC_biz@XXXXX.com";

$ API_Password = "DDDDDDDDDD";

$ API_Vendor = "AAAA.B_CCCCCCCCCC_biz@XXXXX.com";

$ API_Partner = "贝宝";

...

当我测试服务时,我得到的是" SetExpressCheckoutDetails API调用失败.错误消息:无效的供应商帐户错误代码:26 "

PayPal文档和示例非常复杂,我想要做的就是有一个简单的按钮链接到paypal,开始支付XXX欧元到账户YYYY ....

谁能帮我?

提前致谢!

php api paypal

3
推荐指数
1
解决办法
5908
查看次数