小编PDS*_*tat的帖子

如何在Spring Data(JPA)派生的查询中按多个属性进行排序?

我正在查看关于方法命名的页面上的示例(http://docs.spring.io/spring-data/jpa/docs/current/reference/html/jpa.repositories.html),是否可以创建一个复杂的链方法名称,如

findByProgrammeAndDirectorAndProgDateBetweenOrderByProgDateStartTimeAsc
Run Code Online (Sandbox Code Playgroud)

在他们给出的示例中,他们只在一个值上执行OrderBy.在上面的示例中ProgDate,StartTime将是两个单独的值.

java spring jpa spring-data spring-data-jpa

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

JSF控制器,服务和DAO

我正在尝试习惯JSF如何处理数据(来自弹簧背景)

我正在创建一个维护用户列表的简单示例,我有类似的东西

<h:dataTable value="#{userListController.userList}" var="u">
    <h:column>#{u.userId}</h:column>
    <h:column>#{u.userName}</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)

然后"控制器"有类似的东西

@Named(value = "userListController")
@SessionScoped
public class UserListController {
    @EJB
    private UserListService userListService;

    private List<User> userList;

    public List<User> getUserList() {
        userList = userListService.getUsers();
        return userList;
    }
}
Run Code Online (Sandbox Code Playgroud)

而"服务"(虽然看起来更像是DAO)有

public class UserListService {

    @PersistenceContext
    private EntityManager em;

    public List<User> getUsers() {
        Query query = em.createQuery("SELECT u from User as u");
        return query.getResultList();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是正确的做事方式吗?我的术语是对的吗?"服务"感觉更像是DAO?控制器感觉它正在做一些服务工作.

jsf dao ejb jpa java-ee

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

不兼容的类型:推理变量T具有不兼容的边界

我有以下代码

public int solution(int X, int[] A) {

    List<Integer> list = Arrays.asList(A);
Run Code Online (Sandbox Code Playgroud)

由于某种原因,它抛出了以下编译错误

Solution.java:11:错误:不兼容的类型:推理变量T具有不兼容的边界List list = Arrays.asList(A); ^等式约束:整数下限:int []其中T是一个类型变量:T扩展方法asList(T ...)中声明的Object

我假设这是一个Java 8功能,但我不知道如何解决该错误

java java-8

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

根据字符串值对字典键进行排序

我有一个像这样的python字典设置

mydict = { 'a1': ['g',6],
           'a2': ['e',2],
           'a3': ['h',3],
           'a4': ['s',2],
           'a5': ['j',9],
           'a6': ['y',7] }
Run Code Online (Sandbox Code Playgroud)

我需要编写一个函数,在列表中返回有序键,具体取决于你的排序列,例如,如果我们在mydict上排序[key] [1](升序)

我应该像这样收到一份清单

['a2', 'a4', 'a3', 'a1', 'a6', 'a5']
Run Code Online (Sandbox Code Playgroud)

它主要起作用,除了你有多个键的相同值的列,例如.'a2':['e',2]和'a4':['s',2].在这个例子中,它返回列表,如此

['a4', 'a4', 'a3', 'a1', 'a6', 'a5']
Run Code Online (Sandbox Code Playgroud)

这是我定义的功能

def itlist(table_dict,column_nb,order="A"):
    try:
        keys = table_dict.keys()
        values = [i[column_nb-1] for i in table_dict.values()]
        combo = zip(values,keys)
        valkeys = dict(combo)
        sortedCols = sorted(values) if order=="A" else sorted(values,reverse=True)
        sortedKeys = [valkeys[i] for i in sortedCols]
    except (KeyError, IndexError), e:
        pass
    return sortedKeys
Run Code Online (Sandbox Code Playgroud)

如果我想对数字列进行排序,例如它就像这样被调用

sortedkeysasc = itmethods.itlist(table,2)
Run Code Online (Sandbox Code Playgroud)

那有什么建议吗?

保罗

python sorting

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

按钮单击时更改framelayout的内容

我正确定了一个主要布局,它有一个框架,一个框架在那个框架中,然后在底部有一个水平滚动视图和一堆按钮.单击按钮时,框架的内容应更改为新表,就像在选项卡布局教程中选择不同选项卡一样(不使用选项卡布局,因为我有许多不适合屏幕的按钮,除非滚动)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <FrameLayout
            android:id="@+id/tabcontent"
            android:layout_width="fill_parent"            
            android:layout_height="wrap_content"
            android:layout_weight="1.2"            
            android:padding="5dp" android:background="@color/white">
            <TableLayout android:id="@+id/Jobs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*">
                <TableRow android:id="@+id/JobRow" android:layout_width="wrap_content" android:layout_height="wrap_content">
                    <TextView android:id="@+id/JobID" android:layout_column="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
                    <TextView android:id="@+id/JobStatus" android:layout_column="2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
                    <TextView android:id="@+id/Customer" android:layout_column="3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
                    <TextView android:id="@+id/Department" android:layout_column="4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
                    <TextView android:id="@+id/DocType" android:layout_column="5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
                </TableRow> 
            </TableLayout>
        </FrameLayout>
        <HorizontalScrollView 
            android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="bottom" android:scrollbars="none">
            <LinearLayout 
                android:orientation="horizontal" android:layout_height="wrap_content"
                android:layout_width="fill_parent">
                <ImageButton android:id="@+id/batching" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/batching"></ImageButton>
                <ImageButton android:id="@+id/merging" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/merging"></ImageButton>
                <ImageButton android:id="@+id/processing" …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-framelayout

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

使用带有logging.config的TimedRotatingFileHandler日志记录

我正在尝试使用带有logging.config文件的TimedRotatingFileHandler进行测试,没有任何复杂但它应该每10秒滚动到一个新的日志文件中.

但是我得到以下内容

Traceback (most recent call last):
  File "testLogging.py", line 6, in <module>
    logging.config.fileConfig(logDir+'logging.conf')
  File "C:\Python26\Lib\logging\config.py", line 84, in fileConfig
    handlers = _install_handlers(cp, formatters)
  File "C:\Python26\Lib\logging\config.py", line 159, in _install_handlers
    h = klass(*args)
  File "C:\Python26\Lib\logging\handlers.py", line 195, in __init__
    raise ValueError("You must specify a day for weekly rollover from 0 to 6 (0
is Monday): %s" % self.when)
ValueError: You must specify a day for weekly rollover from 0 to 6 (0 is Monday)
: WHEN='S'
Run Code Online (Sandbox Code Playgroud)

python非常简单,只是设置了一个不断记录的无限循环

import logging
import …
Run Code Online (Sandbox Code Playgroud)

python logging

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

Gradle 集成测试构建但未运行

我正在设置一个多模块 gradle 项目并尝试为所有子项目分离集成测试。我设法创建了 integTest 任务,我可以看到它构建了集成测试类并在不同的目录中为单元测试创​​建了集成测试报告。然而,它并没有运行我的集成测试。

项目结构类似于

|_ gradle
| |_ integration-test.gradle
|_ subproject
| |_ src
| |  |_ main
| |  | |_ java
| |  | |_ resources
| |  |_ test
| |  | |_ java
| |  | |_ resources
| |  |_ integTest
| |    |_ java
| |    | |_sit
| |    |   |_ MyTest.java
| |    |_ resources
| |_ build.gradle
|_ build.gradle
|_ gradle.properties
|_ settings.gradle
Run Code Online (Sandbox Code Playgroud)

在 integration-test.gradle 我有

sourceSets {
    integTest …
Run Code Online (Sandbox Code Playgroud)

integration-testing gradle junit5

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

Spring 4 MVC验证无效-BindingResult hasErrors为false

我正在对Spring控制器的post方法(使用org.springframework.test.web.servlet.MockMvc)进行单元测试,并且试图确认表单中存在验证错误时,它将通过检查BindingResult.hasErrors方法将视图发送回表单。

这是我的测试

  @Test
  public void testFilterChannelProgrammesWhenChannelListAndGenreListAreEmptyAndProgNameIsTooLong() throws Exception {
    String progName = TestUtil.createStringWithLength(301);

    mockMvc.perform(post("/api/filter")
        .contentType(MediaType.APPLICATION_FORM_URLENCODED)
        .param("progName", progName)
        .sessionAttr("filter", new ProgrammeSearchDTO())
        )
        .andExpect(status().isOk())
        .andExpect(view().name("api/filter"))
        .andExpect(forwardedUrl("/WEB-INF/jsp/api/filter.jsp"))
        .andExpect(model().attributeHasFieldErrors("filter", "progName"))
        .andExpect(model().attributeHasFieldErrors("filter", "genreIdList"))
        .andExpect(model().attributeHasFieldErrors("filter", "channelIdList"))        
        .andExpect(model().attribute("filter", hasProperty("progName", is(progName))));

    verifyZeroInteractions(channelProgrammeServiceMock);
  }
Run Code Online (Sandbox Code Playgroud)

这是会话属性绑定到的DTO

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

public class ProgrammeSearchDTO {

  @NotEmpty
  private String[] channelIdList;

  @NotEmpty
  private String[] genreIdList;

  private String fromDateTime;
  private String toDateTime;

  @Length(max = 200)
  private String progName;

  private boolean subtitled;
  private boolean signed;
  private boolean film;

  public String[] getChannelIdList() …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-validator

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

Couchbase cbdocloader 错误

我正在尝试使用cbdocloader 工具将多个 JSON 文档从 zip 文件添加到我的 couchbase 服务器(每个 JSON 文档都在它自己的文件中,并且该文件以 id.json 命名)。使用以下命令语法

./cbdocloader -n localhost:8091 -u Administrator -p xxx -b ships -s 100 ~/json-docs.zip
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下回复

[2015-08-21 21:08:35,522] - [rest_client] [140411799267072] - INFO - existing buckets : [u'beer-sample', u'default']
[2015-08-21 21:08:35,530] - [rest_client] [140411799267072] - INFO - http://localhost:8091//pools/default/buckets with param: proxyPort=11211&bucketType=membase&authType=sasl&name=ships&replicaNumber=1&saslPassword=&ramQuotaMB=100
[2015-08-21 21:08:35,543] - [rest_client] [140411799267072] - ERROR - http://localhost:8091//pools/default/buckets error 400 reason: Warning: you do not have enough servers to support this number of replicas., RAM quota specified …
Run Code Online (Sandbox Code Playgroud)

document-oriented-db nosql couchbase

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

位移和位掩码 - 示例代码

我已经遇到了一些代码,有位掩码0xff0xff00或16位二进制形式00000000 1111111111111111 00000000.

/**
 * Function to check if the given string is in GZIP Format.
 *
 * @param inString String to check.
 * @return True if GZIP Compressed otherwise false.
 */
public static boolean isStringCompressed(String inString)
{
    try
    {
        byte[] bytes = inString.getBytes("ISO-8859-1");
        int gzipHeader = ((int) bytes[0] & 0xff)
            | ((bytes[1] << 8) & 0xff00);
        return GZIPInputStream.GZIP_MAGIC == gzipHeader;
    } catch (Exception e)
    {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图弄清楚在这种情况下使用这些位掩码的目的是什么(针对字节数组).我看不出会有什么不同?

在GZip压缩字符串的上下文中,因为此方法似乎是为GZip编写的幻数 …

java bit-manipulation

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