小编Dón*_*nal的帖子

将进程重定向到stdout

我想在Groovy程序中执行foo.bat并将生成的进程'输出重定向到stdout.Java或Groovy代码示例都可以.

foo.bat可能需要几分钟才能运行并产生大量输出,因此我希望一旦生成就看到输出,而不是必须等到进程完成后才能立即看到所有输出.

java groovy

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

Grails命令对象数据绑定

Grails 非常支持将请求参数绑定到域对象及其关联.这在很大程度上依赖于检测.id以数据库结束并自动加载数据库的请求参数.

但是,目前尚不清楚如何填充命令对象的关联.请看以下示例:

class ProductCommand {

    String name
    Collection<AttributeTypeCommand> attributeTypes 
    ProductTypeCommand productType
}
Run Code Online (Sandbox Code Playgroud)

该对象具有单端关联ProductTypeCommand和多端关联AttributeTypeCommand.所有属性类型和产品类型的列表都可从此接口的实现中获得

interface ProductAdminService {
    Collection<AttributeTypeCommand> listAttributeTypes();
    Collection<ProductTypeCommand> getProductTypes();
}
Run Code Online (Sandbox Code Playgroud)

我使用此界面填充GSP中的产品和属性类型选择列表.我还依赖 - 将此接口注入命令对象,并使用它来"模拟" 命令对象attributeTypesproductType属性

class ProductCommand {

    ProductAdminService productAdminService

    String name   

    List<Integer> attributeTypeIds = []
    Integer productTypeId

    void setProductType(ProductTypeCommand productType) {
        this.productTypeId = productType.id
    }

    ProductTypeCommand getProductType() {
        productAdminService.productTypes.find {it.id == productTypeId}        
    }

    Collection<AttributeTypeCommand> getAttributeTypes() {

        attributeTypeIds.collect {id ->
            productAdminService.getAttributeType(id)
        }
    }

    void setAttributeTypes(Collection<AttributeTypeCommand> attributeTypes) {
        this.attributeTypeIds …
Run Code Online (Sandbox Code Playgroud)

data-binding grails groovy command-objects

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

Replace string in file

I'm looking for a way to replace a string in a file without reading the whole file into memory. Normally I would use a Reader and Writer, i.e. something like the following:

public static void replace(String oldstring, String newstring, File in, File out)
    throws IOException {

    BufferedReader reader = new BufferedReader(new FileReader(in));
    PrintWriter writer = new PrintWriter(new FileWriter(out));
    String line = null;
    while ((line = reader.readLine()) != null)
        writer.println(line.replaceAll(oldstring,newstring));

    // I'm aware of the potential for resource leaks here. Proper …
Run Code Online (Sandbox Code Playgroud)

java io

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

用于实例化初始化集合的紧凑语法

我正在寻找一个紧凑的语法来实例化一个集合并添加一些项目.我目前使用这种语法:

Collection<String> collection = 
    new ArrayList<String>(Arrays.asList(new String[] { "1", "2", "3" }));
Run Code Online (Sandbox Code Playgroud)

我似乎记得有一个更紧凑的方法,使用匿名子类ArrayList,然后添加子类的构造函数中的项目.但是,我似乎无法记住确切的语法.

java collections initialization

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

jQuery - 切换选择所有复选框

与一堆示例进行了斗争,并且仍然是jQuery/Javascript的新手,无法让我的代码运行(这里是我在gsp中的模板):

<table>
    <thead>
    <tr>
       <th><input type="checkbox" name="selectAll" onclick="selectAll(this.checked);"/></th>
    </tr>
    </thead>
    <tbody>
         <td>
            <td><input type="checkbox" name="domainList" value="${domainInstance.id}"/></td>
    </tbody>
<table>
Run Code Online (Sandbox Code Playgroud)

我在我的主gsp中有以下javascript片段,它调用模板:

function selectAll(status) {

}
Run Code Online (Sandbox Code Playgroud)

如何从selectAll名称中选择所有复选框?

checkbox jquery

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

消除重复的枚举代码

我有大量实现此接口的枚举:

/**
 * Interface for an enumeration, each element of which can be uniquely identified by it's code
 */
public interface CodableEnum {

    /**
     * Get the element with a particular code
     * @param code
     * @return
     */
    public CodableEnum getByCode(String code);

    /**
     * Get the code that identifies an element of the enum
     * @return
     */
    public String getCode();
}
Run Code Online (Sandbox Code Playgroud)

一个典型的例子是:

public enum IMType implements CodableEnum {

    MSN_MESSENGER("msn_messenger"),
    GOOGLE_TALK("google_talk"),
    SKYPE("skype"),
    YAHOO_MESSENGER("yahoo_messenger");

    private final String code;

    IMType (String code) { …
Run Code Online (Sandbox Code Playgroud)

java enums enumeration

22
推荐指数
3
解决办法
7381
查看次数

从数据库加载FreeMarker模板

我想将我的FreeMarker模板存储在一个类似于以下内容的数据库表中:

template_name | template_content
---------------------------------
hello         |Hello ${user}
goodbye       |So long ${user}
Run Code Online (Sandbox Code Playgroud)

当收到具有特定名称的模板的请求时,这应该导致执行查询,该查询加载相关的模板内容.然后,应将此模板内容与数据模型(上述示例中的'user'变量的值)一起传递给FreeMarker.

但是,FreeMarker API似乎假设每个模板名称对应于文件系统特定目录中的同名文件.有什么方法可以轻松地从数据库而不是文件系统加载我的模板?

编辑:我应该提到我希望能够在应用程序运行时向数据库添加模板,因此我不能简单地在启动时将所有模板加载到新的StringTemplateLoader中(如下所示).

干杯,唐

java templates freemarker

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

Grails:从另一个中调用一个taglib

我想定义自己的taglib,它将使用它g:datePicker来生成它的一些输出.

class MyTagLib

  def myTag = {attrs ->
    // I need to invoke the `datePicker` tag of the the `FormTagLib` tag library
    // provided by Grails       
  }
}
Run Code Online (Sandbox Code Playgroud)

我想在调用此标记时传递属性映射.当我调用时,g:datePicker我希望它将输出直接写入响应(就像在GSP中调用它时一样).

我怎样才能做到这一点?谢谢.

grails taglib

22
推荐指数
2
解决办法
6264
查看次数

HTTP响应缓存

我想确保我的servet的响应永远不会被broswer缓存,这样即使两个相同的请求(相隔一个纳秒),也总是联系服务器.这是实现这一目标的正确方法:

class MyServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Cache-Control", "no-cache");
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢,唐

java caching servlets http

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

如何将Beyond Compare与ClearCase集成?

我想将Beyond Compare与ClearCase集成,以便我可以使用它来进行差异和合并文件,而不是使用ClearCase提供的糟糕工具.

有没有人有执行此集成的说明?

diff merge clearcase beyondcompare

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