我一直在阅读本网站上有关常量用法的大量帖子.
问题:我应该何时使用枚举作为常量,使用类或接口.
我看到了我想要解决的两个关键情况.
例:
例:
从我所读到的一切来看,这就是我认为我掌握的内容以及我正在寻找的意见.
对于情况1:设计方法:使用最终类和静态导入.
在这里看到:接口常量的用途是什么?
对于情况2:设计方法:应用Enums来表示这些常量作为对象.
要记住的其他要点:
提前感谢您的想法和意见.
我试图将属性文件加载到Spring bean中,然后将该bean注入到类中.
我无法工作的唯一部分似乎是使用@Resource参考.有人可以为我连接最后一块吗?我每次都得到一个空值.似乎不想注入价值.
[编辑] - 我原本以为使用@Resource是最好的方法,但我发现的解决方案更容易.
我在另一篇文章中看到这个解决方案
参考解决方案链接:将 属性值注入Spring - 由DON发布
感谢Don的帖子,但我不知道如何用@Resource完成它.
调试结果:
变量值appProperties始终为null.它没有被注射.
Spring Config.

样品类:
package test;
import java.util.Properties;
import javax.annotation.Resource;
public class foo {
public foo() {}
@Resource private java.util.Properties appProperties;
}
Run Code Online (Sandbox Code Playgroud)
基于以下批准的解决方案中的建议.以下是我所做的更改.
弹簧配置:

Java类:

问题: 从oracle数据库中获取类似50.20的值时,似乎我的大小数的映射类正在下降0.如果它的50.23,它将正确获取值,但最后没有0.我想象我想念的东西很简单.建议?提前致谢.
细节
数据库:Oracle 11G字段定义:数字(8,2)
映射getter/setter
@Column ( name="PRICE", precision = 8, scale = 2 )
private BigDecimal price;
public BigDecimal getPrice()
{
return price;
}
public void setPrice( BigDecimal price )
{
this.price = price;
}
Run Code Online (Sandbox Code Playgroud) 描述:
我似乎无法让我的存根或模拟在我测试的课程中起作用.我正在尝试使用whenNew操作,因此我可以模拟一个返回对象,然后使用返回值模拟该对象上的操作.
我想象它很简单我想念但却没有看到它.
解决方案:最初我在运行MockitoRunner.class时需要更改为PowerMockRunner.class.以下代码反映了解决方案.
类路径上的jar:
测试类
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import static org.powermock.api.mockito.PowerMockito.*;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Matchers.any;
@RunWith(PowerMockRunner.class)
@PrepareForTest(ClassA.class)
public class ClassATest {
@Test
public void test() throws Exception
{
String[] returnSomeValue = {"PowerMockTest"};
String[] inputValue = {"Test1"};
ClassB mockedClassB = mock(ClassB.class);
whenNew( ClassB.class).withNoArguments().thenReturn( mockedClassB );
when( mockedClassB, "getResult", any(String[].class) ).thenReturn(returnSomeValue);
IClassA classUnderTest = new ClassA();
String[] expectedValue = classUnderTest.runTest(inputValue);
}
}
Run Code Online (Sandbox Code Playgroud)
A类实施
public …Run Code Online (Sandbox Code Playgroud) 问题描述:我注入的Spring bean被定义为JSF支持bean的托管属性没有被实例化.当我检索Managed-Bean时,它总是会变为null.
我一整天都在与这个斗争,似乎JSF Managed Bean不会从Spring中读出applicationContext.我可以通过在一个支持bean中使用FacesContext来手动拔出bean,它会找到bean,但是当我尝试通过FacesConfig注入它时,它总是会出现null.我在下面列出了我如何整合它的步骤.有什么建议?
Icefaces 1.85
JSF 1.2(通过冰面servlet)
春天3.0
Websphere 7.5(我认为这是eclipse 3.5)
<listener>
<display-name>SpringListener</display-name>
<icon>
<small-icon>small.gif</small-icon>
<large-icon>large.gif</large-icon>
</icon>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/SpringConfig/SpringHelloWorld.xml
</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
<application><variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver></application>
<managed-bean>
<managed-bean-name>testData</managed-bean-name>
<managed-bean-class>src.test.TestData</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>spring3HelloWorldBean</property-name>
<value>#{spring3HelloWorldBean}</value>
</managed-property>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)
<bean id="spring3HelloWorldBean" class="src.test.Spring3HelloWorld" />
Run Code Online (Sandbox Code Playgroud)
提前致谢
甲骨文: 12c
描述:尝试使用 add_months 将 99 年添加到日期中,该方法可以工作,但是它会在返回日期值中添加额外的一天。我应该如何正确添加日期的年份?
declare
toRetDate DATE;
inputDate DATE;
numYears number;
begin
numYears := 99;
inputDate := TO_DATE('28-FEB-85', 'DD-Mon-YY' );
toRetDate := add_months(inputDate, numYears*12);
DBMS_OUTPUT.put_line(toRetDate);
end;
Run Code Online (Sandbox Code Playgroud)
输出:29-FEB-84