小编Lav*_*Lav的帖子

Spring Data JPA如何在内部工作

我正在阅读Spring Data JPA Tutorial.我很困惑这个框架如何在内部工作.让我说明具体情况

有特定的代码

/**
 * Custom finder
 */
public List<Location> getLocationByStateName(String name) {
    @SuppressWarnings("unchecked")
    List<Location> locs = entityManager
        .createQuery("select l from Location l where l.state like :state")
        .setParameter("state", name + "%").getResultList(); // note
        return locs;
}
Run Code Online (Sandbox Code Playgroud)

这只是由以下界面取代

@Repository
public interface LocationJPARepository extends JpaRepository<Location, Long> {
    List<Location> findByStateLike(String stateName);
}
Run Code Online (Sandbox Code Playgroud)

相应的测试用例运行良好

@Test
public void testFindWithLike() throws Exception {
   List<Location> locs = locationRepository.getLocationByStateName("New");
   assertEquals(4, locs.size());
}
Run Code Online (Sandbox Code Playgroud)

新的测试案例

@Test
public void testFindWithLike() throws Exception {
   List<Location> locs = locationJPARepository.findByStateLike("New"); …
Run Code Online (Sandbox Code Playgroud)

spring jpa spring-data spring-data-jpa

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

使用MyBatis和Spring在项目中记录SQL查询

在我的项目中我有

<bean id="ABCSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="ABCDataSource" />
  <property name="mapperLocations">
      <list>
        <value>classpath:com/myco/dao/XYZMapper.xml</value>
       </list>
  </property>
<bean>
Run Code Online (Sandbox Code Playgroud)

log4j.logger.java.sql.Connection=debug, stdout, abclog
log4j.logger.java.sql.PreparedStatement=debug, stdout, abclog
log4j.logger.java.sql=debug, stdout, abclog
log4j.logger.org.mybatis=debug, stdout, abclog
log4j.logger.org.apache.ibatis=debug, stdout, abclog
Run Code Online (Sandbox Code Playgroud)

当我在日志中运行applicartion时,我没有看到SQL查询想知道我错过了什么

看到这篇文章如何为Mybatis配置log4j以打印我的SQL 建议更改mybatis类配置但不确定如何处理spring SqlSessionFactoryBean

logging spring log4j ibatis mybatis

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

java hashing linkedHashSet的意义

我知道关于linkedHashSet的一些事情

  • 它维持插入顺序
  • 使用LinkedList来保存订单
  • 我的问题是哈希如何进入图片?

我知道如果使用散列,那么存储的概念就会出现

但是,通过检查JDK中的代码,似乎LinkedHashSet实现只包含构造函数而没有实现,所以我猜所有的逻辑都发生在HashSet中?

  • 所以hashSet默认使用LinkedList?

让我以这种方式提出我的问题......如果客观是写一个集合

  1. 保持独特的价值观
  2. 使用链接列表保留插入顺序然后...它可以很容易地完成而不需要散列...可能我们可以调用此集合LinkedSet

看到一个类似的问题HashSet和LinkedHashSet之间的区别是什么,但不是很有帮助

如果我需要更多地解释我的问题,请告诉我

java collections hash

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

同步三个线程

在接受采访时被问到这个问题,试图解决它......但没有成功.我想过使用CyclicBarrier

有三个线程T1打印1,4,7 ... T2打印2,5,8 ...和T3打印3,6,9 .... 如何将这三个同步到打印顺序1,2,3,4,5,6,7,8,9 ....

我尝试编写并运行以下代码

public class CyclicBarrierTest {
    public static void main(String[] args) {
        CyclicBarrier cBarrier = new CyclicBarrier(3);
        new Thread(new ThreadOne(cBarrier,1,10,"One")).start();
        new Thread(new ThreadOne(cBarrier,2,10,"Two")).start();
        new Thread(new ThreadOne(cBarrier,3,10,"Three")).start();
    }
}

class ThreadOne implements Runnable {
    private CyclicBarrier cb;
    private String name;
    private int startCounter;
    private int numOfPrints;

    public ThreadOne(CyclicBarrier cb, int startCounter,int numOfPrints,String name) {
        this.cb = cb;
        this.startCounter=startCounter;
        this.numOfPrints=numOfPrints;
        this.name=name;
    }

    @Override
    public void run() {
        for(int counter=0;counter<numOfPrints;counter++)
        {
            try {
            // System.out.println(">>"+name+"<< "+cb.await()); …
Run Code Online (Sandbox Code Playgroud)

java multithreading java.util.concurrent

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

用JSON表示矩阵

我试图在JSON中使用矩阵样式数据,但它似乎不起作用.谁能帮我理解我做错了什么?

        {
   "took": 12,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 44,
      "max_score": 1,
      "hits": [
      {
            "_index": "transactions",
            "_type": "transaction",
            "_id": "trans0007",
            "_score": 1,
            "_source": {
                "fundRelation": "[1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,1,0,1,0,0],
                                [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0],
                                [0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [1,0,0,1,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0],
                                [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0],
                                [0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0],
                                [0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0],
                                [0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0],
                                [1,0,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,1,1,0],
                                [1,0,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,1,1,0],
                                [1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,0,0,1,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0],
                                [0,0,1,1,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0],
                                [0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0],
                                [0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0]
                            ",
                "fundName": ["Fund A","Fund B","Fund C","Fund D","Fund E","Fund F","Fund G","Fund H","Fund I","Fund J","Fund K","Fund L","Fund M","Fund N","Fund O","Fund P","Fund Q","Fund R","Fund S","Fund T"],
                "fundColor": ["#9ACD32","#377DB8","#F5DEB3","#EE82EE","#40E0D0","#FF6347","#D8BFD8","#D2B48C","#4682B4","#00FF7F","#FFFAFA","#708090","#708090","#6A5ACD","#87CEEB","#A0522D","#FFF5EE","#2E8B57","#F4A460","#FA8072"] …
Run Code Online (Sandbox Code Playgroud)

json matrix

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

在GXT中为Date触发Change事件

我有这样的UI

在此输入图像描述

它使用com.extjs.gxt.ui.client.widget.form.DateField 在Date的"change"事件中我有一个监听器.这里的问题是

  1. 当用户更改日期然后单击外部(表单的空白区域中的某处)时,才会触发"更改事件"
  2. 如果用户只更改日期并且未在表单上单击外部,则不会触发更改事件.
  3. 我尝试过像Focus,Blur这样的其他事件.这些问题的问题是日期是空的(而不是新的更改值)我想只在日期值改变时调用我的代码(用户不需要点击外部)

我的问题是我只想在更改日期值调用我的代码,而无需用户点击外面...有没有办法?

java gwt gxt

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

SonarQube REST API:读取指标

我正在使用SonarQube版本6.7.1

我正在尝试为我们的项目获取JSON响应sonarQube统计信息只需要简单的细节,例如

  • 错误计数,漏洞计数,代码重复百分比,代码覆盖率
  • 尝试使用URL http:// sonar-server:9000 / api / metrics&json = true但收到错误未知url,有人可以指出正确的URL
  • 最终目的是在时间序列DB中存储每次运行的以上计数。.有什么建议怎么做?

可能是我没有清楚地阅读/理解文档,可能是指向教程或示例的指针或其他一些指针会帮助我,

sonarqube devops

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

如何使用模板生成器生成kubernetes yaml文件?

我是kubernetes新手,我有一个基本问题

我对https://kubernetes.io/docs/reference/kubectl/conventions/的理解是,我们可以使用“ kubernetes run”命令生成yaml模板

但是当我尝试这样做时,它没有用 附件

不知道我的理解是错误的还是命令中的错误

kubernetes kubectl

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

Java Auto Boxing和条件运算符

在声纳中,我看到了代码的重大违规警告

  public Long getValue(FieldType fieldType) {
    Long value = paramLevelMap.get(fieldType); // ok returns Long not long
    return value == null ? UNSPECIFIED_PARAMETER_KEY : value; // complaints here
  } 
Run Code Online (Sandbox Code Playgroud)

其中'UNSPECIFIEDpa_PARAMETER_KEY'是pvt static long,'value'也很长.

盒装值未装箱,然后立即重新装箱

它在第二行抱怨.我不太明白它,何时原始长度被转换为相应的类对象?然后回来 ?

java autoboxing sonarqube

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

Maven 连接重置错误

我有一个 linux 上的 Maven 项目。直到上周,它都建设得很好。今天我遇到以下错误

[ERROR] Failed to execute goal on project my-integration-service: Could not resolve
dependencies for project com.mycompany.myproj:my-integration-service:jar:0.0.1-SNAPSHOT:
Failed to collect dependencies for [org.springframework:spring-core:jar:4.0.4.RELEASE
(compile), org.springframework:spring-tx:jar:4.0.4.RELEASE (compile), ...]: No versions
available for joda-time:joda-time:jar:[2.2,) within specified range -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

我检查了我的 settings.xml ,在本地存储库中我可以看到这个的许多版本...库 2.2 , 2.4 ... 2.9.1

我还看到了文件 M2_REPO/joda-time/joda-time/resolver-status.properties

maven-metadata-codehaus.xml.error=Could not transfer metadata joda-time\:joda-time/maven-metadata.xml from/to codehaus (http\://repository.codehaus.org/org/codehaus)\: Error transferring file\: repository.codehaus.org
...
maven-metadata-spring-milestone.xml.error=Could not transfer metadata joda-time\:joda-time/maven-metadata.xml from/to spring-milestone (http\://maven.springframework.org/milestone)\: Error transferring file\: Connection reset
....
maven-metadata-com.springsource.repository.maven.releases.xml.error=Could not …
Run Code Online (Sandbox Code Playgroud)

maven

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

AWS CodeBuild 无法使用 CD 命令

我在 CodeCommmit 中有一个非常简单的 Hello World Java 项目,具有以下结构

\n\n
This is a sample template for sam-app - Below is a brief explanation of what we have generated for you:\n\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md                                   <-- This instructions file \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HelloWorldFunction                          <-- Source for HelloWorldFunction Lambda Function \n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pom.xml                                 <-- Java dependencies \n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src \n\xe2\x94\x82       \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main \n\xe2\x94\x82       \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 java \n\xe2\x94\x82       \xe2\x94\x82       \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 helloworld \n\xe2\x94\x82       \xe2\x94\x82           \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 App.java                <-- Lambda function code \n\xe2\x94\x82       \xe2\x94\x82           \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 GatewayResponse.java    <-- POJO for API Gateway Responses object …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda aws-codecommit aws-codebuild

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

Java HashMap 哈希函数

我正在通过 Java 的 HashMap hash() 实现,如下所示

final int hash(Object k) {
            // some checks
            h ^= k.hashCode();
            // This function ensures that hashCodes that differ only by
            // constant multiples at each bit position have a bounded
            // number of collisions (approximately 8 at default load factor).
            h ^= (h >>> 20) ^ (h >>> 12);
            return h ^ (h >>> 7) ^ (h >>> 4);
                   // >>> is Unsigned right shift
    }
Run Code Online (Sandbox Code Playgroud)

我不确定为什么添加下面的代码,以及相同的好处是什么?

        h ^= (h >>> 20) ^ …
Run Code Online (Sandbox Code Playgroud)

java collections hash hashmap

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