我有一个带键和字符串值的地图.
此Map已构建为读取资源包,其中数据按以下方式组织:
height=160
weight=80
name=bob
Run Code Online (Sandbox Code Playgroud)
我有一个类人物,其字段有:身高,体重和名字.
class Person{
int height;
int weight;
String name;
//..getter and setter..
}
Run Code Online (Sandbox Code Playgroud)
我想从Map创建一个Person类的实例:height:160,weight:80,name:bob最好的是通用解决方案,或者使用某些实用程序的东西.
你有什么主意吗?我怎么能用Java做到这一点?或者使用框架Spring?
我有一个包含年份的月份列表,例如:[12-2014,11-2012,5-2014,8-2012]并且我必须将它们排序为最近的在顶部(或最新的日期在顶部),例如。[12-2014,5-2014,11-2012,8-2012]。
有人知道如何Java有效地做到这一点吗?
编辑:
该课程YearMonth不可用,我正在上课Java 7
我正在编写一个云形成模板,并且在我的堆栈中创建一个资源取决于环境。
因此,我检查参数(环境)的值,并基于它创建该资源(条件:ISProduction)。
但是,我的问题是,在创建资源 (MyProductionResource) 的情况下,另一个资源 (AnotherResource) 依赖于它并且需要使用另一个资源 (MyProductionResource) 的输出属性。
这里的代码:
Conditions:
ISProduction:
"Fn::Equals":
- !Ref Environment
- production
...
MyProductionResource:
Type: AWS::CloudFormation::Stack
Condition: ISProduction
Properties:
[.. properties..]
AnotherResource:
Type: AWS::CloudFormation::Stack
DependsOn:
- AResource
- MyProductionResource
Properties:
TemplateURL: whatever
Parameters:
AParameter: !GetAtt MyProductionResource.Outputs.SomeString
Run Code Online (Sandbox Code Playgroud)
我的问题是,只有当 ISProduction 为真时,我才希望 AnotherResource 依赖于 MyProductionResource。一个想法是在 DependsOn 项中添加某种条件,或者任何可以带来相同结果的条件。
我如何在 AWS Cloud Formation 上做到这一点?
此外,我不确定当未创建dependsOn 列表中列出的资源时会发生什么。云形成模板会产生错误吗?我怎样才能使这个属性读取安全!GetAtt MyProductionResource.Outputs.SomeString ?
我有一些 Gradle 项目,但我想避免在build.gradle文件中显式加载凭据。我想避免的一个例子是:
maven {
credentials {
username "$maven_user"
password "$maven_password"
}
url 'https://my-maven-repo'
}
Run Code Online (Sandbox Code Playgroud)
我想,以避免有用户名和密码字段gradle.build,即使这些值可以从本地主机例如,从装载~/.gradle/gradle.properties。
我想实现的是加载从证书~/.m2/settings.xml和唯一指定Maven仓库网址gradle.build。
有可能这样做吗?我做了几次尝试,但看起来 Gradle 忽略了settings.xml
continuous-integration dependencies artifactory gradle maven
我不知道如何在Hibernate中强制只读列.
我想将idgroup设置为只读列.即使我设置insertable=false和updatable=false,在休眠SQL我可以读:
Hibernate: insert into groups (description, name, account_idaccount, idgroup) values (?, ?, ?, ?)
Run Code Online (Sandbox Code Playgroud)
但我想获得:
insert into groups (description, name, account_idaccount) values (?, ?, ?)
Run Code Online (Sandbox Code Playgroud)
这是我的课程:
@Entity
@Table(name = "groups")
public class Group implements java.io.Serializable {
private static final long serialVersionUID = -2948610975819234753L;
private GroupId id;
private Account account;
private String name;
private String description;
@EmbeddedId
@AttributeOverrides({@AttributeOverride(name = "idgroup", column = @Column(name = "idgroup", insertable = false)),
@AttributeOverride(name = "accountIdaccount", column = @Column(name = "account_idaccount", …Run Code Online (Sandbox Code Playgroud) 我有一个Spring MVC应用程序,在我的页面中我有一个输入字段,用户写下他/她的名字,我想避免他们键入charatcters,如@,?,!,, $,%..等.
在我的验证器中,我想使用一个允许最大字符集的表达式,例如撇号,重音符号等.
@Override
public void validate(Object target, Errors errors)
{
//the email must be unique
super.validate(target, errors);
User user= (User) target;
if (!user.matches("[a-zA-Z ]"))) {
errors.rejectValue("user.name", "user.name.invalid");
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人可以帮助我添加比[a-zA-Z]更广泛的验证?
我有一个查询字符串,可能是:
/fr/hello?language=en
Run Code Online (Sandbox Code Playgroud)
要么
/fr/welcome?param1=222¶m2=aloa&language=en
Run Code Online (Sandbox Code Playgroud)
要么
/it/welcome?param1=222&language=en¶m2=aa
Run Code Online (Sandbox Code Playgroud)
我想从每个查询字符串中删除参数语言及其值,因此结果将是:
/fr/hello
Run Code Online (Sandbox Code Playgroud)
和
/fr/welcome?param1=222¶m2=aloa
Run Code Online (Sandbox Code Playgroud)
和
/it/welcome?param1=222¶m2=aa
Run Code Online (Sandbox Code Playgroud)
编辑:参数值的长度可能大于2
有没有人知道在String.replaceAll([regex],[replace])中使用的任何好的正则表达式?
java ×5
spring ×3
regex ×2
spring-mvc ×2
arrays ×1
artifactory ×1
bundle ×1
cloud ×1
database ×1
date ×1
datetime ×1
dependencies ×1
gradle ×1
hibernate ×1
map ×1
maven ×1
orm ×1
string ×1
time ×1
validation ×1