所以,如果我理解正确,如果有多个候选者,两者都是确定哪个bean自动装配的方法.那究竟是什么区别呢?
假设我有一张带有标签的图像:latest。
我想在我的电脑上复制该图像,然后给它另一个标签,例如:1.4.2
我不想构建图像,只需复制并重新标记它。
在特定的视图中,我确实有一个可扩展的员工列表。每个员工都有 2 个字段,即hoursWorked& advancePayments。单击 1 个按钮,我想发布整个表格。为了实现此目的,我将一个列表发送到包含多个 POJO(基于员工数量)的视图。
添加到列表中的 POJO 如下所示:
@Setter
@Getter
@NoArgsConstructor
public class WorkdayCommand {
private Long employeeId;
private Integer hoursWorked;
private Integer advancePayment;
}
Run Code Online (Sandbox Code Playgroud)
在控制器中,我确实有一行将列表添加到模型中:
model.addAttribute("workdayCommands", employeeService.getListOfWorkdayCommandsWithIds());
Run Code Online (Sandbox Code Playgroud)
以及形成实际列表的方法:
public List<WorkdayCommand> getListOfWorkdayCommandsWithIds(){
List<WorkdayCommand> listOfCommands = new ArrayList<>();
List<Long> listOfIds = employeeRepository.getListOfIds();
for(int i = 0; i < employeeRepository.getNumberOfEmployees(); i++){
WorkdayCommand workdayCommand = new WorkdayCommand();
workdayCommand.setEmployeeId(listOfIds.get(i));
listOfCommands.add(workdayCommand);
}
return listOfCommands;
}
Run Code Online (Sandbox Code Playgroud)
现在我的观点有问题:
<div class="table-responsive" th:if="${not #lists.isEmpty(employees)}">
<form th:object="${workdayCommands}" th:action="@{/addworkday}">
some table headers...
<tr th:each="employee : ${employees}"> …Run Code Online (Sandbox Code Playgroud) 我使用 Jackson 作为 Json 解析器,但出现错误:
No suitable constructor found for type ~ can not instantiate from JSON object
Run Code Online (Sandbox Code Playgroud)
所以我尝试添加@NoArgsConstructor,但现在我得到了这个:
constructor AccountItem in class AccountItem cannot be applied to given types
Run Code Online (Sandbox Code Playgroud)
这是我的课:
@Getter
@Builder
public class AccountItem {
/**
* Accounti dentifier
*/
private Long accountId;
/**
* Account name
*/
private String accountName;
/**
* Account priority
*/
private int accountPriority;
}
Run Code Online (Sandbox Code Playgroud)
可能是什么原因?
所以,我花了像最后一个小时试图解决它,但我只是无法获得自定义 .css 文件与Spring 5 中的html 文件链接。我正在使用 Thymeleaf、Bootstrap和jQuery进行前端工作。我正在使用 Intellij 社区版。
我的文件层次结构如下所示:
java
project_files
resources
static
css
main.css
templates
main.html
Run Code Online (Sandbox Code Playgroud)
我有一行main.html:
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" href="../../css/main.css"/>
Run Code Online (Sandbox Code Playgroud)
这应该将我的样式与 .html 文件链接起来。有什么问题?
示例代码在这里:
static class stack
{
int top=-1;
char items[] = new char[100];
void push(char x)
{
if (top == 99)
System.out.println("Stack full");
else
items[++top] = x;
}
}
Run Code Online (Sandbox Code Playgroud)
当 items[++top] 出现时到底发生了什么?
java ×4
spring ×3
spring-mvc ×2
thymeleaf ×2
annotations ×1
arrays ×1
bootstrap-4 ×1
css ×1
docker ×1
iteration ×1
jackson ×1
lombok ×1