我正在尝试迁移到Spring-boot,我从git-hub下载了很多项目并尝试使用start.spring.io但是每次当我尝试运行maven-package时我都会遵循错误:
Error configuring: org.springframework.boot:spring-boot-maven-plugin. Reason: Unable to retrieve component configurator for plugin configuration
Run Code Online (Sandbox Code Playgroud)
因为我尝试了很多开源模板,我认为我必须对我的env配置有问题,但我不知道从哪一点开始.我有maven-2和java-8 jdk,没有"普通"pom项目的问题.
我正在编写一个程序,它的字符串处理功能可能有点太多了。我将大部分文字消息移至常量;我不确定这在 Rust 中是否正确,但我习惯用 C 编写。
我发现我不能轻易地使用我的static &str内部match表达式。我可以使用文本本身,但不知道如何正确地做到这一点。
我知道这是一个编译器问题,但不知道如何以 Rust 风格正确编写该结构。我应该使用枚举而不是类似 C 的静态变量吗?
static SECTION_TEST: &str = "test result:";
static STATUS_TEST_OK: &str = "PASSED";
fn match_out(out: &String) -> bool {
let s = &out[out.find(SECTION_TEST).unwrap() + SECTION_TEST.len()..];
match s {
STATUS_TEST_OK => {
println!("Yes");
true
}
_ => {
println!("No");
false
}
}
}
Run Code Online (Sandbox Code Playgroud)
static SECTION_TEST: &str = "test result:";
static STATUS_TEST_OK: &str = "PASSED";
fn match_out(out: &String) -> bool {
let s = &out[out.find(SECTION_TEST).unwrap() + SECTION_TEST.len()..];
match …Run Code Online (Sandbox Code Playgroud) 我在 hibernate 中遇到了简单的一对一映射问题。我有两个简单的类:
第一个实体:
@Entity
public class GrantingOfLoanData {
@Id
@GeneratedValue
private Long id;
@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="loan", referencedColumnName="loan_id")
public Loan getLoan() {
return loan;
}
private Loan loan;
}
Run Code Online (Sandbox Code Playgroud)
第二实体:
@Entity
public class Loan {
@Id
@GeneratedValue
@Column(name="loan_id")
private Long loan_id;
public Long getLoan_id() {
return loan_id;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 hibernate 运行此代码时,出现了以下异常:
Caused by: org.hibernate.MappingException: Could not determine type for: org.finance.app.core.domain.common.loan.Loan, at table: GrantingOfLoanData, for columns: [org.hibernate.mapping.Column(loan)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.mapping.Property.isValid(Property.java:241) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at …Run Code Online (Sandbox Code Playgroud) 我试图用java lambda expresions替换现有的循环.
我有简单的数据结构,如下所示:
class DbObject{
private Long objectId;
private Long basedOnObjectId; //<- this field can be null
public Long getObjectId() {
return objectId;
}
public void setObjectId(Long objectId) {
this.objectId = objectId;
}
public Long getBasedOnObjectId() {
return basedOnObjectId;
}
public void setBasedOnObjectId(Long basedOnObjectId) {
this.basedOnObjectId = basedOnObjectId;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个DbObjects列表
我尝试使用指定的basedOnObjectId过滤每个DbObject:
(1) list.stream().filter(object -> obejct.getBasedOnObjectId()
.equals(basedOnObject.getObjectId()))
.collect(Collector.of(List))
Run Code Online (Sandbox Code Playgroud)
当然这个代码给了我NullPointer,因为有些od DbObject没有BasedOnObjectId因为它们是根.
很自然的事情是替换字段"Long basedOnObjectId;" 通过可选,但正如我在开始时提到的那样,现有的生产代码是不是快速修复.
所以我试着做一些改变,我评估下面的句子:
Optional<Long> option = Optional.ofNullable(objectWithNullBasedOnId.getBasedOnObjectId());
Run Code Online (Sandbox Code Playgroud)
并尝试使用.get()方法或.ifPresent(),但.get()也会抛出空指针异常,ifPresent不专用于使用流.
我注意到这一事实,当我有DbObject with null basedOnObjectId时,我不必检查值是否完全为null但只跳过此执行步骤.
所以我决定使用.orElse()方法并返回一些假值.在这种情况下,我返回0L值,因为这个索引在DB中不存在:)
所以我的代码:
(2) List newList = …Run Code Online (Sandbox Code Playgroud) 嗨,我在简单的程序上挣扎,在整数数组上执行lex排序
(完整程序:https://pastebin.com/UMqEP62n)
在足够大的int向量上运行排序会导致数组中出现随机数,然后依赖于导致segfault的数据.
sort(nums.begin(), nums.end(), lex_compare);
Run Code Online (Sandbox Code Playgroud)
比较功能:
bool lex_compare(const int &a, const int &b) {
int ap = a, bp = b;
vector<int> da, db;
if (ap == 0) da.insert(da.begin(), ap%10);
while (ap > 0) {
da.insert(da.begin(), ap%10);
ap /= 10;
}
if (bp == 0) db.insert(db.begin(), bp%10);
while (bp > 0) {
db.insert(db.begin(), bp%10);
bp /= 10;
}
size_t size;
if (da.size() < db.size()) {
size = da.size();
} else {
size = db.size();
} …Run Code Online (Sandbox Code Playgroud) 我正在将一些Go代码移植到Rust,我意识到在乘法过程中发生溢出时Rust会慌乱,而Go允许溢出发生。
下面的测试代码不会引起溢出,但是会打印出减少的值。(通过以下网址测试:https : //play.golang.org/)
func main() {
fmt.Println("test\n")
var key uint64 = 15000;
key = key*2862933555777941757 + 1
fmt.Println(key)
}
Run Code Online (Sandbox Code Playgroud)