小编Red*_*ddy的帖子

使用Spring动态加载属性文件

我编写了一个PropertyUtils类(来自互联网),它将加载属性

<bean id="propertiesUtil" class="com.myApp.PropertiesUtil" >
    <property name="locations">
        <list>
            <value>classpath:myApp/myApp.properties</value>         
        </list>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

和一个PropertiesUtil类如下所示

public class PropertiesUtil extends PropertyPlaceholderConfigurer {

    private static Map<String, String> properties = new HashMap<String, String>();

    @Override
    protected void loadProperties(final Properties props) throws IOException {
        super.loadProperties(props);
        for (final Object key : props.keySet()) {
            properties.put((String) key, props.getProperty((String) key));
        }
    }

    public String getProperty(final String name) {
        return properties.get(name);
    }

}
Run Code Online (Sandbox Code Playgroud)

稍后,我可以通过调用PropertiesUtil.getProperty()方法获取属性.

但是现在我想略微修改它,如果myApp.properties被用户修改/更改,它应该再次加载

可能我需要FileWatcher类

public abstract class FileWatcher extends TimerTask {
    private long timeStamp;
    private File file;

    public FileWatcher(File file) …
Run Code Online (Sandbox Code Playgroud)

java resources spring configuration-files

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

在Bootstrap 3中将列数据宽度限制为固定大小

我正在使用Bootstrap 3响应表来显示数据.但是,其中一列与其他列相比具有巨大的数据,如下所示

在此输入图像描述

但我想展示有限的描述长度.简而言之,I would like to display first 2 to 3 lines of data [or 300 characters] and followed by .....

如果可能,将鼠标悬停在描述列上应该显示完整的描述 tooltip

我该如何实现这一目标?

html css fixed-length-record twitter-bootstrap twitter-bootstrap-3

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

Liferay /可折叠导航中的手风琴

在Liferay 6.2中,我可以看到以下所有选项基本上都是可折叠的. 在此输入图像描述

我想在我的portlet中列出相同的列表.我的样本数据是

<ul> Header 1
    <li> Sub Header 1</li>
    <li> Sub Header 2</li>
</ul>
<ul> Header 2
    <li> Sub header 1</li>
    <li> Sub header 2</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

任何人都可以发布一个例子或如何实现这一目标?

html jquery portlet liferay alloy-ui

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

生成项目的所有唯一组合

我试图生成所有可能的独特项目组合.

Ex: item1, item2, item3

Combinations: 
   item1+item2+item3
   item1+item2
   item1+item3
   item2+item3
   item1
   item2
   item3
Run Code Online (Sandbox Code Playgroud)

我无法知道如何解决这个问题?

for(int i=0;i<size;i++){
   for(int j=i+1;j<size;j++){
       System.out.println(list.item(i)+list.item(j));
   }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码肯定适用于两个元素的所有独特组合.但不是3元素对和更多..

java algorithm combinations unique

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

Hibernate Exception - 未知的名称值

我有类似的问题[ Hibernate异常:枚举类的未知名称值

但就我而言,

Unable to filter, so returning non filtered results.Unknown name value for enum class com.xxxx.enums.Status: DELIVERED
java.lang.IllegalArgumentException: Unknown name value for enum class com.xxxx.enums.Status: DELIVERED
    at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:128)
    at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:109)
    at org.hibernate.type.AbstractType.hydrate(AbstractType.java:104)


@Enumerated(value = EnumType.STRING)
@Column(name = "status", length = 10)
@AuditableField
private Status status;

public enum ReleaseStatus {
     DL("Delivered"),
}
Run Code Online (Sandbox Code Playgroud)

一切似乎都很好,我仍然得到那个例外.

java enums hibernate

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

Java.sql.Date到Oracle数据库的日期和时间戳

我正在使用Spring JDBC模板进行jdbc操作.由于我使用的是BeanPropertySqlParameterSource,因此bean的START_TIME变量分配了java.sql.date类型.在Oracle db中,该列被称为"DATE"类型(并且没有TIMESTAMP类型,即使db是10.2 ver)

现在,当我设置

bean.setStartTime(new Date(System.currentTime()) 
Run Code Online (Sandbox Code Playgroud)

它以日期和时间戳存储为00:00:00

请告诉我如何存储时间戳.

sql spring date jdbc

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

从Java中的特定IP生成HttpRequest

我正在使用Apache HttpClient生成Post请求并提交数据.由于远程应用程序在提交数据的用户的IP地址上进行中继,因此我想发送用户指定IP地址的发布请求.

我该如何配置?

public static void loginUser(String username, String password, String ip) throws Exception{
      try {
            HttpClient client = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://login.myapp.com/");

            // Request parameters and other properties.
            List<NameValuePair> params = new ArrayList<NameValuePair>(2);
            params.add(new BasicNameValuePair("username",username));
            params.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

            // Execute and get the response.
            HttpResponse response = client.execute(httppost);
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                //etc....
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

编辑:为避免混淆,

我想在httprequest标头中包含自定义IP地址,以便最终应用程序知道,[来自我的应用程序]的此请求来自自定义IP地址,但不是来自我的应用程序运行的IP地址

假设我的应用程序在服务器上运行,IP地址为"1.1.1.0".现在我的用户正在使用"test","test","199.199.199.0"执行loginUser方法.现在,从应用程序到目标URL的HTTP请求应该是从"199.199.199.0"发送的

java http ip-address spoofing apache-httpclient-4.x

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

SEC7113:由于mime类型不匹配,CSS被忽略

我正在开发一个Jsp-Servlet应用程序.我使用Eclipse和Default Tomcat 7部署了应用程序.

但是,在部署应用程序后,在Chrome/Firefox中,UI会正确呈现.IE10或更高版本中的位置在控制台中显示此警告,并且未加载任何UI元素.

SEC7113: CSS was ignored due to mime type mismatch
Run Code Online (Sandbox Code Playgroud)

这是css文件的引用方式

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <link rel="shortcut icon" href="images/rpt.ico" type="image/x-icon">
        <link href="css/custom.css" rel="stylesheet" type="text/css" />
    </head>
...............
</html>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

更新如果我在兼容模式下运行网站,它可以正常渲染.但即使没有启用它,我应该如何使其工作.

我可以看到Type不是以text/css形式出现的.但为什么? 在此输入图像描述

html css internet-explorer tomcat mime-types

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

选择最低成本的组合

我有不同餐厅的不同项目的数据

    Rest    Item     Price
    ----------------------
    ABC     dosa      14
    ABC     idly      30
    ABC     idly+upma 25

    123     dosa      30
    123     idly      7
    123     upma      12

    XYZ     dosa      20
    XYZ     idly      12
    XYZ     upma      20
    XYZ     dosa+upma 30
    XYZ     dosa+idly+upma 40
Run Code Online (Sandbox Code Playgroud)

Now I need to pickup a restaurant which gives me the best deal of "dosa+idly+upma" items.

从上面的例子:它将是餐厅"ABC"

我无法设计有效的方法来做这个或不知道怎么做?任何的想法?

更新

这是我的对象的样子

Class Rest{
  Map<String,Integer> menu; //item,price map
}
Run Code Online (Sandbox Code Playgroud)

java algorithm minimum

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

Powershell cmd 跟踪目录中的文件

我正在寻找Powershellcmd 来打印目录中任何文件的最后 5 行数据。

理想情况下

Get-Content -Tail 5 -Wait .\test.log

将在最后 5 行的特定文件上打印尾部。如果有任何新内容被附加到该文件,它将继续打印。

同样,我想跟踪目录中的所有文件。如果任何文件被修改,则打印内容。

试过这样的东西,没有用!

Get-Content -Tail 5 -Wait .\folder*.log

powershell tail

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