小编Fee*_*eco的帖子

mysqld:无法将dir更改为数据.服务器无法启动

我用安装程序安装了MySQL服务器,然后启动了.重启后我尝试再次启动它并得到错误:

D:\Program Files\MySQL\MySQL Server 5.7\bin>mysqld -u root -p
mysqld: Can't change dir to 'D:\Program Files\MySQL\MySQL Server 5.7\data\'     (Errcode: 2 - No such file or directory)
2015-11-17T08:30:18.822962Z 0 [Warning] TIMESTAMP with implicit DEFAULT     value is deprecated. Please use --explicit_defaults_for_timestamp server option     (see documentation for more details).
2015-11-17T08:30:18.822962Z 0 [Warning] Insecure configuration for --secure-    file    -priv: Current value does not restrict location of generated files.     Consider setting it to a valid, non-empty path.
2015-11-17T08:30:18.822962Z 0 [Note] mysqld (mysqld 5.7.9) starting as     process …
Run Code Online (Sandbox Code Playgroud)

mysql

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

@ConfigurationProperties在类路径中找不到Spring Boot配置注释处理器

我尝试在Spring Boot中完成自定义属性.
我尝试通过IntelliJ IDEA 2016.3创建一个简单的项目:
1.使用Spring Boot Initializer创建了一个新的Gradle项目(我没有检查任何内容).
2.创建了一个新课程Properties.
3.当我用它注释时@ConfigurationProperties,下一个通知出现了: 通知 文档说我应该在我的项目中添加以下内容:

dependencies {
    optional "org.springframework.boot:spring-boot-configuration-processor"
}

compileJava.dependsOn(processResources)
Run Code Online (Sandbox Code Playgroud)

之后,我尝试重建项目并在设置中启用注释处理器,但通知尚未消失.完成也不起作用(我创建了一个字符串my).

java spring intellij-idea spring-boot

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

从表达式中断或返回

我想做什么:

when(transaction.state) {
    Transaction.Type.EXPIRED,
    //about 10 more types
    Transaction.Type.BLOCKED -> {
        if (transaction.type == Transaction.Type.BLOCKED && transaction.closeAnyway) {
            close(transaction)
            break //close if type is blocked and has 'closeAnyway' flag
        }
        //common logic
    }
    //other types
}
Run Code Online (Sandbox Code Playgroud)

我不能写break:

'when'语句中不允许'break'和'continue'.考虑使用标签从外循环继续/中断.

这是一种return/break来自when陈述的方式吗?或者解决它的最佳方法是什么?

kotlin

15
推荐指数
2
解决办法
7550
查看次数

@JsonCreator'找不到名称为'的创建者属性,即使是ignoreUnknown = true

我有以下课程:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Topic {

    private List<Comment> comments = new ArrayList<>();

    private List<User> users = new ArrayList<>();

    @JsonCreator
    public Topic(@JsonProperty("success") boolean success,
                 @JsonProperty("response_comments") List<ResponseComment> responseComments,
                 @JsonProperty("response_users") List<ResponseUser> responseUsers) {

        if (success) {
            comments = Util.resolveComments(responseComments); 
            users = Util.resolveUsers(responseUsers); //some logic
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

当我尝试反序列化JSON时,它抛出:

找不到名为'comments'的创建者属性(在com.test.domain.mapper.Topic类中)

我不想comments从json 填充,只是在属性的构造函数中.但是,如果我写下一个参数:

@JsonProperty("success") boolean success,
@JsonProperty("response_comments") List<ResponseComment> responseComments,
@JsonProperty("response_users") List<ResponseUser> responseUsers,
@JsonProperty("comments") Object a,
@JsonProperty("users") Object a
Run Code Online (Sandbox Code Playgroud)

一切都有效.

java jackson

11
推荐指数
2
解决办法
5021
查看次数

结合null安全性和assertNotNull

在测试中我们通常有assertNotNull,但它不执行从可空类型到非可空类型的智能转换.我必须写这样的东西:

if (test == null) {
    Assert.fail("")
    return
}
Run Code Online (Sandbox Code Playgroud)

这是一个仅通过assertNotNull调用执行智能转换的解决方法吗?你如何解决?

kotlin kotlin-null-safety

11
推荐指数
2
解决办法
980
查看次数

约曼.文件名,目录名或卷标语法不正确

重新安装Windows 10(版本10.0.14393).重新安装以下内容:

  • Java的

java版"1.8.0_121"
Java(TM)SE运行时环境(版本1.8.0_121-b13)
Java HotSpot(TM)64位服务器VM(版本25.121-b13,混合模式)

  • nodejs(v6.9.5)
  • NPM(3.10.10)
  • 纱线(v0.19.1)
  • Yeoman(已安装yarn global add yo)

当我写yo -vCMD任何文件夹中,拼命地跑与管理员或不,我拿:

文件名,目录名或卷标语法不正确.

更新:
我找到的唯一解决方法是使用以下完整路径yo:

C:\Users\<username>\AppData\Local\Yarn\config\global\node_modules\.bin\yo.cmd
Run Code Online (Sandbox Code Playgroud)

yeoman yarnpkg

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

消费者建设者的陷阱

看下面的代码:

class Person {

    String name;
    int age;

    Person(Consumer<Person> consumer) {
        consumer.accept(this);
    }

}
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我正在使用"消费者构造函数",所以我可以创建一个这样的人:

var person = new Person(p -> {
    p.name = "John";
    p.age = 30;
})
Run Code Online (Sandbox Code Playgroud)

似乎这种方法比构建器模式或所有参数构造函数要好得多.

自Java 8发布以来已经过去了4年,但没有人使用消费者构造函数(至少我以前没见过它).

我不懂为什么?这种方法有一些缺陷或局限吗?

我找到了一个,但我认为它不重要:

class AdvancedPerson extends Person {

    String surname;

    AdvancedPerson(Consumer<AdvancedPerson> consumer) {
        super(); // <-- what to pass?
        consumer.accept(this);
    }

}
Run Code Online (Sandbox Code Playgroud)

当然,我们可以创建一个无参数构造函数,Person并在AdvancedPerson消费者构造函数中调用它.但这是一个解决方案吗?

那你觉得怎么样?
使用消费者构造函数是否安全?
这是建筑商和所有参数构造者的替代品吗?为什么?

java constructor java-8

8
推荐指数
2
解决办法
412
查看次数

行项目之一未显示在 Jetpack Compose 视图中

这是一个测试可组合项:

@Preview
@Composable
fun SliderInRow() {
    Row {
        Text("qwe")
        Slider(value = 0f, onValueChange = {})
        Text("wer")
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要一行包含一个文本、一个滑块和另一个文本。但是,最后一个可组合文本 ( wer) 被遗漏了:

在此输入图像描述

我究竟做错了什么?

android kotlin android-jetpack-compose

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

Hibernate 尝试从 null 一对一属性分配 id

我有两个实体:

@Entity
@Table
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "user")
    private UserDetails userDetails;

}

@Entity
@Table(name="user_details")
public class UserDetails {

    @GenericGenerator(name = "generator", strategy = "foreign",
        parameters = @Parameter(name = "property", value = "user"))
    @Id
    @GeneratedValue(generator = "generator")
    @Column(unique = true, nullable = false)
    private Integer id;

    @OneToOne
    @PrimaryKeyJoinColumn
    private User user;

    public UserDetails(User user) {
        this.user = user;
        user.setUserDetails(this);
    }

}
Run Code Online (Sandbox Code Playgroud)

如果我使用 userDetails 创建用户,它会起作用。但随后它创建了一个 UserDetails 行,我不想要它。我必须从数据库中获取一个 …

java hibernate

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

Hibernate 2 级缓存一对一不起作用

我将 Ehcache 提供程序用于 Hibernate 2 级缓存。它缓存一对多集合,用 注释@Cache,但不缓存一对一:

//hb annotations
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "user")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "user")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "details")
    private Details details;

    //getters, setters, constructors etc.

}

//hb annotations
public class Details {

    @GenericGenerator(name = "generator", strategy = "foreign",
    parameters = @Parameter(name = "property", value = "user"))
    @Id
    @GeneratedValue(generator = "generator")
    @Column(unique = true, nullable = …
Run Code Online (Sandbox Code Playgroud)

java hibernate spring-data-jpa

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