小编Man*_*uel的帖子

比较BigDecimal是否大于零

如果BigDecimal值大于零,我该如何比较?

java compare bigdecimal

227
推荐指数
4
解决办法
26万
查看次数

找不到当前线程的会话(Spring 3.1.X和Hibernate 4)

我正在尝试使用Spring 3.1和Hibernate 4来设置我的项目.我一直在线学习一些教程.我得到一个奇怪的错误,根据Spring论坛应该已经修复了Spring 3.1. 春虫追踪器

当我的服务调用时getCurrentSession(),它会抛出以下异常:

org.hibernate.HibernateException: **No Session found for current thread**] with root cause org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at
org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881)
Run Code Online (Sandbox Code Playgroud)

****编辑:根据Spring Spring 3.1 Transactions for Transactions更新了我的spring-dao.xml .我尝试使用org.apache.commons.dbcp.BasicDataSource替换我的数据源.我的配置中是否有任何可能导致此问题的属性?****

这是我的spring-dao.xml:

 <!-- Enable annotation style of managing transactions -->
<tx:annotation-driven transaction-manager="transactionManager" />   

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <value>hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect</value>
    </property>
</bean>

<!-- Declare a datasource that has pooling capabilities-->   
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close"
            p:driverClass="${app.jdbc.driverClassName}"
            p:jdbcUrl="${app.jdbc.url}"
            p:user="${app.jdbc.username}"
            p:password="${app.jdbc.password}"
            p:acquireIncrement="5"
            p:idleConnectionTestPeriod="60"
            p:maxPoolSize="100" …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-3 hibernate-4.x

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

后端处理的进度条主要表面

如果有人能给我一些关于进度条和ajax后端处理的提示,我将不胜感激.

澄清我需要遵循的细节:

我有一个命令按钮在后端进行一些处理.我想在支持bean完成处理后端指令时显示一个达到100%的进度条.我看了很多线程,但没有运气.他们中的大多数都没有展示具体的样本如何做到这一点.以下是我的代码片段:

</h:panelGrid>
<p:commandButton id="btn" value="DoSomeAction"
styleClass="ui-priority-primary" update="panel"
onclick="PF('pbAjax').start();PF('startButton1').disable();"
widgetVar="startButton1"
actionListener="#{actionBean.DoSomeAction}" />

<p:progressBar widgetVar="pbAjax" ajax="true"
value="#{progressBean.progress}" labelTemplate="{value}%"
styleClass="animated">
<p:ajax event="complete" listener="#{progressBean.onComplete}"
update="growl" oncomplete="startButton2.enable()" />
</p:progressBar>
</p:panel>
Run Code Online (Sandbox Code Playgroud)

这是Progress Brean的代码:

@ManagedBean(name="progressBean")
public class ProgressBean implements Serializable {  

  private Integer progress;  

  public Integer getProgress() {  
    if(progress == null)  
      progress = 0;  
    else {  
      progress = progress + (int)(Math.random() * 35);      
      if(progress > 100)  
      progress = 100;  
    }  

    return progress;  
  }  

  public void setProgress(Integer progress) {  
    this.progress = progress;  
  }  

  public void onComplete() …
Run Code Online (Sandbox Code Playgroud)

jsf primefaces

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

Spring托管事务,EclipseLink JPA,自定义隔离级别

我怀疑这是令人尴尬的,我以一种可怕的方式做错了,但请耐心等待我.

我有一个Spring应用程序与Spring管理的事务.它使用EclipseLink JPA.我有一个方法,findByNativeQuery()后跟一个merge().我需要在真正的SERIAL事务隔离级别中实现这一点.我尝试添加 @Transactional(isolation=Isolation.SERIALIZABLE)

这不起作用,因为org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect#beginTransaction 不支持任何事务隔离级别,但默认值.那么我尝试使用ElcipseLink的UnitOfWork内部并开始/编写我自己的事务,但后来我收到一个错误:

"java.lang.IllegalStateException : Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
Run Code Online (Sandbox Code Playgroud)

这当然有道理......但我该怎么办?

java spring jpa transactions eclipselink

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

response.setContentType("应用/八位字节流")

我有一个非常基本的问题,可能有点傻.

我正在编写代码以使用JSP和Servlet下载CSV文件.我从互联网论坛获得了代码并且工作正常,但我试图理解两行的重要性

response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\""
            + filename + "\"");
Run Code Online (Sandbox Code Playgroud)

现在第一行response.setContentType- 根据我的理解,它告诉浏览器服务器期望什么样的数据.我的问题是它告诉浏览器有什么价值application/octet-stream.我看到这用于下载各种文件.如果此行通知浏览器该页面将下载文件,则导致下一行的差异.response.setHeader将附件作为参数.

any1能告诉我这两行文件下载的重要性吗?如果我无法清楚地解释我的问题,请告诉我.

关心塔伦

java jsp content-type

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

Spring Security - 编码密码看起来不像 BCrypt

我无法使用正确的详细信息登录,因为程序不断指出编码的密码看起来不像 bcrypt。有谁知道如何解决这个问题?我正在使用 JDBC 身份验证。

我也有正确的数据库表,有足够的空间用于编码密码。我不确定哪里出了问题。

JSP 表单: <form:form method="post" modelAttribute="user" action="${pageContext.request.contextPath}/processLogin">

                <div class="form-group">
                    <div class="form-label-group">
                        <label for="inputUser">Username: </label> <input name="username"
                            type="text" path="username" id="inputUser" class="form-control"
                            placeholder="Username" required="required" autofocus="autofocus">
                    </div>
                </div>
                
                <div class="form-group">
                    <div class="form-label-group">
                        <label for="inputPassword">Password: </label> 
                        <input name="username" type="password" path="password"
                            id="inputPassword" class="form-control" placeholder="Password"
                            required="required">
                    </div>
                </div>
                
                <div class="form-group">
                    <div class="checkbox">
                        <label> <input type="checkbox" value="remember-me">
                            Remember Password
                        </label>
                    </div>
                </div>
                
                <input type="submit" value="Login"/>
                    
            </form:form>
Run Code Online (Sandbox Code Playgroud)

安全配置:

@Autowired
private DataSource securityDataSource;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication().dataSource(securityDataSource).passwordEncoder(passwordEncoder());
}

@Override
protected …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

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