导入模板的操作步骤详解
模板下载地址
- 百度随便搜一下模板下载
- 例如:下面这个,随便找个喜欢的模板下载
- 下载完成后,随便命个名,解压出来
- 解压出来后的样子
assets文件夹,导入idea,存放静态资源static下。这个文件夹里面都是一些图片,样式和封装的js
下面的html就是一些对呀页面,按照自己需求则取
创建springboot项目
此处为员工管理系统
例一:模拟数据库
- controller:IndexController
访问地址写在controller是一种方法,写在配置类里面是第二种方法,此处配置类为(MyMvcConfig)
package com.na.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
// @RequestMapping("/pages-signin.html")
// public String index(){
// return "pages-signin";
// }
// @RequestMapping("/index.html")
// public String index(){
// return "index";
// }
}
- MyMvcConfig
package com.na.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
// @Override
// public void addViewControllers(ViewControllerRegistry registry) {
// registry.addViewController("/").setViewName("index");
// registry.addViewController("/index.html").setViewName("index");
// }
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("pages-signin");
registry.addViewController("/pages-signin.html").setViewName("pages-signin");
}
}
-
dao:
-
DepartmentDao
package com.na.dao; import com.na.pojo.Department; import org.springframework.stereotype.Repository; import java.util.Collection; import java.util.HashMap; import java.util.Map; /** * 〈一句话功能简述〉<br> * 〈〉 * * @author 22724 * @create 2021/12/17 * @since 1.0.0 */ //部门Dao @Repository public class DepartmentDao { //模拟数据库中的数据 private static Map<Integer, Department> departments = null; static { departments = new HashMap<Integer, Department>();//创建一个部门表 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(); } //通过id得到部门 public Department getDepartmentById(Integer id){ return departments.get(id); } }
-
EmployeeDao
package com.na.dao; import com.na.pojo.Department; import com.na.pojo.Employee; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.RequestMapping; import java.util.Collection; import java.util.HashMap; import java.util.Map; /** * 〈一句话功能简述〉<br> * 〈〉 * * @author 22724 * @create 2021/12/17 * @since 1.0.0 */ //员工Dao @Repository public class EmployeeDao { //模拟数据库中的数据 private static Map<Integer, Employee> employees = null; //员工有所属的部门 @Autowired private DepartmentDao departmentDao; static { employees = new HashMap<Integer,Employee>(
-