关于 javax.validation
@NotNull(message = "From can't be null")
@Min(value = 1, message = "From must be greater than zero")
private Long from;
@NotNull(message = "To can't be null")
@Min(value = 1, message = "To must be greater than zero")
private Long to;
Run Code Online (Sandbox Code Playgroud)
我还想验证FROM应该小于TO并且TO应该大于FROM?我们如何使用 javax 验证的注释来做到这一点?
我正在使用 JSF + Spring+ Hibernate
protected @Inject ChartOfAccount chartOfAccount;
Run Code Online (Sandbox Code Playgroud)
chartOfAccount我基本上想从列表中填充
for (DistributionEntry de : getDistributionEntries()) {
chartOfAccount.setAccount(de.getAccount());
chartOfAccountList.add(chartOfAccount);
}
Run Code Online (Sandbox Code Playgroud)
对于每次迭代,我想要新的对象,chartOfAccount否则你知道列表包含具有最新值的相同对象。
解决方案一:使用 new 关键字 :-p
for (DistributionEntry de : getDistributionEntries()) {
ChartOfAccount coa= new ChartOfAccount();
coa.setAccount(de.getAccount());
chartOfAccountList.add(coa);
}
Run Code Online (Sandbox Code Playgroud)
解决方案二:applicationContext.getBean
for (DistributionEntry de : getDistributionEntries()) {
chartOfAccount= applicationContext.getBean(ChartOfAccount.class);
chartOfAccount.setAccount(de.getAccount());
chartOfAccountList.add(chartOfAccount);
}
Run Code Online (Sandbox Code Playgroud)
但我读过某些文章,以避免使用applicationContext.getBean
如果我避免使用applicationContext.getBean,处理这种情况的最佳方法是什么?两种行为都会相同吗?(ApplicationContext.getBean 与 new 关键字)
注意:我的托管bean是@Scope(“session”),模型是@Scope(BeanDefinition.SCOPE_PROTOTYPE),所以我们都知道,对于一个会话,它是单例,而不同会话的原型。
我正在使用@Transactional 来管理交易
@Override
@Transactional
public List<FooBo> save(Foo foo, Foo foo2) {
logger.debug(() -> String.format("FooService.save()"));
repository.save(foo);
return repository1.save(foo2);
}
Run Code Online (Sandbox Code Playgroud)
我在使用时找不到交易 ID TransactionAspectSupport.currentTransactionInfo()
还有其他方法吗?(如果 Spring 维护事务的唯一 ID)
更新:我的场景是我想根据事务 ID 在静态上下文中添加一些信息。并在事务提交后需要该信息。
例如..基于事务ID,我想将一些对象放在静态上下文中的地图中,提交后需要利用这些对象..这就是我的想法
HTML
<input id="1" name="myText" type="text" value="20"/>
<input id="2" name="myText" type="text" value="30"/>
<input id="3" name="myText" type="text" value="40"/>
Run Code Online (Sandbox Code Playgroud)
如何index使用名称获取id值?
以下代码段无效
var getVal = $('[name="myText"]').index(1);
Run Code Online (Sandbox Code Playgroud) 我有两个JavaScript文件:
我也用厚盒子(Ajax调用)
在Main.js
$(document).ready(function() {
var cnt=0;
$("#btnPmt").click(function(){
cnt=cnt+1;
tb_show('Void Transaction','pmt.jsp?height=310&width=400', null);
});
});
Run Code Online (Sandbox Code Playgroud)
该Pmt.js文件包含在pmt.jsp作为
<script src="js/Pmt.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
在Pmt.js
$("#btnPmtClose").click(function(){
cnt=0;
parent.tb_remove();
});
Run Code Online (Sandbox Code Playgroud)
我们如何重置在Main.js中decadered的Pmt.js中var cnt的值?以上是行不通的,当我关闭thickbox时,我发现增加的值,而不是在关闭时设置的零,甚至是Ajax调用.
我正在使用Spring MVC + Hibernate
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
// save
public <T> int save(T entity) throws DataAccessException {
Session session = sessionFactory.getCurrentSession();
session.save(entity);
}
Run Code Online (Sandbox Code Playgroud)
作为新记录保存,生成的新主键在自动增量(db.MySQL)中生成.我想获得并返回与上述方法相关的新的自动递增值.
告诉我 !
我使用<p:selectCheckboxMenu>上List<Long>:
<p:selectCheckboxMenu value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
</p:selectCheckboxMenu>
Run Code Online (Sandbox Code Playgroud)
private List<Long> selectedItems;
private Map<String, Long> availableItems;
Run Code Online (Sandbox Code Playgroud)
提交表单并循环显示所选项目时,如下所示,
for (int i = 0; i < selectedItems.size(); i++) {
Long id = selectedItems.get(i);
// ...
}
Run Code Online (Sandbox Code Playgroud)
然后我得到一个类强制转换异常:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
at com.example.Bean.submit(Bean.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 27 more
Run Code Online (Sandbox Code Playgroud)
与出现同样的问题<p:selectManyCheckbox>,<p:selectManyMenu>,<h:selectManyMenu>等所有多选组件基本.它在<p:selectOneMenu>单个值Long属性上和所有其他单选组件中都可以正常工作.
这是怎么造成的,我该如何解决?
我使用以下代码只从用户获取数字和一个小数点,这对我来说在 KeyPress 事件上工作正常:
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
{
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
现在我想限制小数点/点后的数字/数字,即 35.25468,这意味着点/小数点后只需要 6 个数字/数字。
告诉我 !
java ×2
javascript ×2
jquery ×2
jsf ×2
spring ×2
spring-boot ×2
c# ×1
datasource ×1
decimal ×1
digit ×1
get ×1
hibernate ×1
html ×1
javax ×1
jsf-2 ×1
limit ×1
numbers ×1
primary-key ×1
primefaces ×1
reset ×1
return ×1
scope ×1
spring-mvc ×1
thickbox ×1
validation ×1