我有一个设置用户设置的 API。因为两个输入都不是强制性的,所以我想先检查该值是否存在,然后将其设置为模型属性以避免空值。
$this->InputValidator->validate($request, [
'firsname' => 'string',
'lastname' => 'string',
'email' => 'email',
'mobile_phone' => 'string',
'address' => 'string',
'language' => 'string',
'timezone' => 'string',
'nationality' => 'string',
'profile_photo' => 'url'
]);
$userInformation = new UserInformation([
'firstname' => $request->input('firstname'),
'lastname' => $request->input('lastname'),
'email' => $request->input('email'),
'mobile_phone' => $request->input('mobile_phone'),
'address' => $request->input('address'),
'profile_photo' => $request->input('profile_photo')
]);
$User->information()->save($userInformation);
Run Code Online (Sandbox Code Playgroud)
特别是当输入之一不存在时,我不想将其传递给模型。我也不想做需要的输入
我想用Java 8创建一个日历.到目前为止,我有这个:
YearMonth yearMonthObject = YearMonth.of(year, month);
int daysOfCurrentMonth = yearMonthObject.lengthOfMonth();
int i = 1;
ArrayList<Integer> Dayes = new ArrayList<Integer>();
for(i=1; i<=daysOfCurrentMonth; i++){
Dayes.add(i);
}
Dayes.forEach(value -> System.out.print(value));
Run Code Online (Sandbox Code Playgroud)
它打印当月的日期(例如5月).
我怎样才能确定1是星期日,2是星期一,3星期二,...,8是星期日(下周)等等?
我想在Java中为多个JButton添加一个EventHandler.我使用JButton数组JButton[] buttons = new JButton[120].我用过这个解决方案
for (int i=0; i<btns.length; i++){
buttons[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
}
Run Code Online (Sandbox Code Playgroud)
但我认为上面的代码很糟糕.
我有以下代码
ArrayList<ArrayList<String>> reservation = new ArrayList<ArrayList<String>>();
ArrayList<String> singleList = new ArrayList<String>();
while (rs.next()){
singleList.add(rs.getString("name"));
singleList.add(rs.getString("type"));
singleList.add(rs.getString("view"));
singleList.add(rs.getString("service"));
singleList.add(rs.getString("checkin"));
singleList.add(rs.getString("date"));
reservation.add(singleList);
// correct line System.out.println(reservation.get(0).get(0));
singleList.clear();
}
catch (Exception e) {
e.printStackTrace();
}
// wrong lineSystem.out.println(reservation.get(0).get(0));
return reservation;
}
Run Code Online (Sandbox Code Playgroud)
当我取消注释错误的行(第二个System.out)时,我得到一个 Index: 0, Size: 0 error但是如果我取消注释正确的行(第一个System.out),程序运行正常并得到正确的结果.为什么我的reservationList在while循环后变空?