1.结束8080端口占用
netstat -ano | findstr :8080
taskkill /PID 7036 /F
2.提示Junit-vintage错误
TestEngine with ID’junit-vintage’failedto discover tests” with Spring
导包错误,改成下面:
import org.junit.Test;
3.自己手动导入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
4.设置模板
File=》Editor=》File and Code Templates=》File Header=》自己设置模板样式
/**
* @Author:
* @Date: ${DATE} ${TIME}
* @Version 1.0
*/
5.
@Scope("prototype")
@Scope("singleton")
@Qualifier
7.依赖注入
@Autowired
private AlphaDao alphaDao;
@Autowired
private AlphaService alphaService;
@Autowired
private SimpleDateFormat simpleDateFormat;
@Test
public void testDI() {
System.out.println(alphaDao);
System.out.println(alphaService);
System.out.println(simpleDateFormat.format(new Date()));
}}
8.响应HTML数据
1.controller
//响应HTML数据
@RequestMapping(path = "/teacher", method = RequestMethod.GET)
public ModelAndView getTeacher() {
ModelAndView mav = new ModelAndView();
mav.addObject("name", "张三");
mav.addObject("age", "20");
mav.setViewName("/demo/view");
return mav;}
<!DOCTYPE html><html lang="en" xmlns:th =" http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Teacher</title>
</head>
<body>
<p th:text="${name}"></p>
<p th:text="${age}"></p>
</body>
</html>
2.第二种方式
@RequestMapping(path ="/school",method = RequestMethod.GET)
public String getSchool(Model model){
model.addAttribute("name","北京大学");
model.addAttribute("age",80);
return "/demo/view";
}
9.集合
@RequestMapping(path = "/emps", method = RequestMethod.GET)
@ResponseBody
public List<Map<String, Object>> getEmps() {
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> emp = new HashMap<>();
emp.put("name","张三");
emp.put("age",23);
emp.put("salary",800.00);
list.add(emp);
emp = new HashMap<>();
emp.put("name","李四");
emp.put("age",30);
emp.put("salary",900.00);
list.add(emp);
emp = new HashMap<>();
emp.put("name","王五");
emp.put("age",80);
emp.put("salary",7000.00);
list.add(emp);
return list;}