我用安装程序安装了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) 我尝试在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
).
我想做什么:
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
陈述的方式吗?或者解决它的最佳方法是什么?
我有以下课程:
@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)
一切都有效.
在测试中我们通常有assertNotNull
,但它不执行从可空类型到非可空类型的智能转换.我必须写这样的东西:
if (test == null) {
Assert.fail("")
return
}
Run Code Online (Sandbox Code Playgroud)
这是一个仅通过assertNotNull
调用执行智能转换的解决方法吗?你如何解决?
重新安装Windows 10(版本10.0.14393).重新安装以下内容:
java版"1.8.0_121"
Java(TM)SE运行时环境(版本1.8.0_121-b13)
Java HotSpot(TM)64位服务器VM(版本25.121-b13,混合模式)
yarn global add yo
)当我写yo -v
在CMD任何文件夹中,拼命地跑与管理员或不,我拿:
文件名,目录名或卷标语法不正确.
更新:
我找到的唯一解决方法是使用以下完整路径yo
:
C:\Users\<username>\AppData\Local\Yarn\config\global\node_modules\.bin\yo.cmd
Run Code Online (Sandbox Code Playgroud) 看下面的代码:
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
消费者构造函数中调用它.但这是一个解决方案吗?
那你觉得怎么样?
使用消费者构造函数是否安全?
这是建筑商和所有参数构造者的替代品吗?为什么?
这是一个测试可组合项:
@Preview
@Composable
fun SliderInRow() {
Row {
Text("qwe")
Slider(value = 0f, onValueChange = {})
Text("wer")
}
}
Run Code Online (Sandbox Code Playgroud)
我想要一行包含一个文本、一个滑块和另一个文本。但是,最后一个可组合文本 ( wer
) 被遗漏了:
我究竟做错了什么?
我有两个实体:
@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 行,我不想要它。我必须从数据库中获取一个 …
我将 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)