学习流程-2024-11
学习流程2024-11-15:
1.如何理解springboot项目,将.html资源文件放在resources/templates文件夹下?
分析:这是一种“约定大于配置”。一般将.html模版文件放在resouces/templates文件夹下。
2.那将图片文件、css文件、js文件等分别放到单独的文件夹,然后再把文件夹放到resources/images文件夹下,也是springboot的约定大于配置是吧?
分析:是的。
学习流程2024-11-23:
1.问题:idea直接创建springboot项目时jdk最低要求17。
解决方法:在idea新建springboot项目时spring initializr选项卡将server url由https://start.spring.io改为https://start.aliyun.com
补充:新建项目时依赖里,选web、devtools(用于热部署)、lombok。
学习流程2024-11-27:
1.流程:
1.1maven下载完依赖后删掉项目文件夹结构里没用的maven、git相关:.mvn文件夹、.gitignore、mvnw、mvnw.cmd、HELP.md文件。
学习流程2024-11-28:
/** * @RestController声明返回的不应被解释为视图名 * * @author konglingchao * @Description: * @date 2024/11/28 */ @RestController public class HelloController { @GetMapping("/hello") public String hello() { return "hello, world"; } }
运行项目,浏览器访问localhost:8086/hello,(8086是自己配的端口),页面成功显示"hello, world"。
@Data @AllArgsConstructor @NoArgsConstructor public class Department { private Integer id; private String departmentName; }
public class DepartmentDao { private static Map<Integer, Department> departments = null; static { departments = new HashMap<>(); departments.put(101, new Department(101, "教学部")); departments.put(102, new Department(102, "市场部")); departments.put(103, new Department(103, "教研部")); departments.put(104, new Department(104, "运营部")); departments.put(105, new Department(105, "后勤部")); } public Collection<Department> getDepartments() { return departments.values(); } public Department getDepartmentById(Integer id) { return departments.get(id); } }
学习流程2024-11-29:
@Data @NoArgsConstructor public class Employee { private Integer id; private String lastName; private String email; private String gender; // M:男male /meɪl/;F:女female /ˈfiː.meɪl/ private Department department; private Date birth; public Employee(Integer id, String lastName, String email, String gender, Department department) { this.id = id; this.lastName = lastName; this.email = email; this.gender = gender; this.department = department; // 仅用于测试 this.birth = new Date(); } }
学习流程2024-11-30:
public class EmployeeDao { @Autowired private DepartmentDao departmentDao; private static Map<Integer, Employee> employees = null; static { employees = new HashMap<Integer, Employee>(); employees.put(1001, new Employee(1001, "AA", "A24734673@qq.com", "M", new Department(101, "教学部"))); employees.put(1002, new Employee(1002, "BB", "B24734673@qq.com", "F", new Department(102, "市场部"))); employees.put(1003, new Employee(1003, "CC", "C24734673@qq.com", "M", new Department(103, "教研部"))); employees.put(1004, new Employee(1004, "DD", "D24734673@qq.com", "F", new Department(104, "运营部"))); employees.put(1005, new Employee(1005, "EE", "E24734673@qq.com", "M", new Department(105, "后勤部"))); } /** * 初始id,主键自增 */ private int initId = 1006; /** * 新增雇员 */ public int addEmployee(Employee employee) { if (StringUtils.isEmpty(employee.getId())) { employee.setId(initId++); } employee.setDepartment(departmentDao.getDepartmentById(employee.getDepartment().getId())); employees.put(employee.getId(), employee); return 1; } /** * 删除雇员 */ public int deleteEmployee(int id) { if (employees.containsKey(id)) { employees.remove(id); return 1; } else { return 0; } } /** * 修改雇员 */ public int updateEmployee(Employee employee) { int id = employee.getId(); if (employees.containsKey(id)) { employee.setDepartment(departmentDao.getDepartmentById(employee.getDepartment().getId())); employees.put(id, employee); return 1; } else { return 0; } } /** * 通过id查询雇员 */ public Employee getEmployeeById(int id) { return employees.get(id); } /** * 获取所有雇员 */ public Collection<Employee> getAllEmployees() { return employees.values(); } }