From b61cee0454ee596327b369b50e03ca84f0d907da Mon Sep 17 00:00:00 2001 From: Mth Zhang Date: Mon, 1 Jan 2024 23:56:49 +0800 Subject: [PATCH] 2024 0101 23:56 --- logistics-parent/logistics-common/pom.xml | 51 ++++++++++ .../logistics-manager-dao/pom.xml | 52 ++++++++++ .../logistics-manager-pojo/pom.xml | 15 +++ .../logistics-manager-service/pom.xml | 43 ++++++++ logistics-parent/logistics-manager/pom.xml | 21 ++++ .../logustucs-manager-web/pom.xml | 83 ++++++++++++++++ springboot_all/springboot01/pom.xml | 39 +++++++- .../zhangzeyuan/SpringBoot01Application.java | 21 +++- .../zhangzeyuan/config/MyConfiguration.java | 15 +++ .../zhangzeyuan/controller/EmpController.java | 1 - .../controller/FreemarkerController.java | 2 +- .../zhangzeyuan/controller/MyController.java | 1 - .../controller/ThymeleafController.java | 54 +++++++++- .../interceptors/MyInterceptor.java | 31 ++++++ .../interceptors/MyInterceptorConfig.java | 26 +++++ .../com/zhangzeyuan/mapper/EmpMapper.java | 4 + .../com/zhangzeyuan/service/EmpService.java | 4 + .../service/impl/EmpServiceImpl.java | 12 +++ .../src/main/resources/mybatis/EmpMapper.xml | 11 ++- .../src/main/resources/templates/error.html | 10 ++ .../src/main/resources/templates/index.html | 17 +++- .../resources/templates/showEmpThyme.html | 98 +++++++++++++++++++ .../SpringBoot01ApplicationTest.java | 29 ++++++ 23 files changed, 626 insertions(+), 14 deletions(-) create mode 100644 logistics-parent/logistics-common/pom.xml create mode 100644 logistics-parent/logistics-manager-dao/pom.xml create mode 100644 logistics-parent/logistics-manager-pojo/pom.xml create mode 100644 logistics-parent/logistics-manager-service/pom.xml create mode 100644 logistics-parent/logistics-manager/pom.xml create mode 100644 logistics-parent/logustucs-manager-web/pom.xml create mode 100644 springboot_all/springboot01/src/main/java/com/zhangzeyuan/config/MyConfiguration.java create mode 100644 springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptor.java create mode 100644 springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptorConfig.java create mode 100644 springboot_all/springboot01/src/main/resources/templates/error.html create mode 100644 springboot_all/springboot01/src/main/resources/templates/showEmpThyme.html create mode 100644 springboot_all/springboot01/src/test/java/com/zhangzeyuan/SpringBoot01ApplicationTest.java diff --git a/logistics-parent/logistics-common/pom.xml b/logistics-parent/logistics-common/pom.xml new file mode 100644 index 0000000..2a904b0 --- /dev/null +++ b/logistics-parent/logistics-common/pom.xml @@ -0,0 +1,51 @@ + + + + logistics-parent + com.zhangzeyuan + 1.0-SNAPSHOT + + 4.0.0 + + logistics-common + + + + + joda-time + joda-time + + + + org.apache.commons + commons-lang3 + + + org.apache.commons + commons-io + + + commons-net + commons-net + + + + com.fasterxml.jackson.core + jackson-databind + + + + junit + junit + test + + + + org.slf4j + slf4j-log4j12 + + + + \ No newline at end of file diff --git a/logistics-parent/logistics-manager-dao/pom.xml b/logistics-parent/logistics-manager-dao/pom.xml new file mode 100644 index 0000000..d4bde02 --- /dev/null +++ b/logistics-parent/logistics-manager-dao/pom.xml @@ -0,0 +1,52 @@ + + + + logistics-parent + com.zhangzeyuan + 1.0-SNAPSHOT + + 4.0.0 + + logistics-manager-dao + jar + + + com.zhangzeyuan + logistics-manager-pojo + 1.0-SNAPSHOT + + + + org.mybatis + mybatis + + + org.mybatis + mybatis-spring + + + com.github.miemiedev + mybatis-paginator + + + com.github.pagehelper + pagehelper + + + com.github.jsqlparser + jsqlparser + + + + mysql + mysql-connector-java + + + + com.alibaba + druid + + + \ No newline at end of file diff --git a/logistics-parent/logistics-manager-pojo/pom.xml b/logistics-parent/logistics-manager-pojo/pom.xml new file mode 100644 index 0000000..ef7a148 --- /dev/null +++ b/logistics-parent/logistics-manager-pojo/pom.xml @@ -0,0 +1,15 @@ + + + + logistics-manager + com.zhangzeyuan + 1.0-SNAPSHOT + + 4.0.0 + + logistics-manager-pojo + + + \ No newline at end of file diff --git a/logistics-parent/logistics-manager-service/pom.xml b/logistics-parent/logistics-manager-service/pom.xml new file mode 100644 index 0000000..8b2f7be --- /dev/null +++ b/logistics-parent/logistics-manager-service/pom.xml @@ -0,0 +1,43 @@ + + + + logistics-manager-dao + com.zhangzeyuan + 1.0-SNAPSHOT + + 4.0.0 + + logistics-manager-service + + + + com.zhangzeyuan + logistics-manager-dao + 1.0-SNAPSHOT + + + + org.springframework + spring-context + + + org.springframework + spring-jdbc + + + org.springframework + spring-aspects + + + org.springframework + spring-context-support + + + org.springframework + spring-jms + + + + \ No newline at end of file diff --git a/logistics-parent/logistics-manager/pom.xml b/logistics-parent/logistics-manager/pom.xml new file mode 100644 index 0000000..463c480 --- /dev/null +++ b/logistics-parent/logistics-manager/pom.xml @@ -0,0 +1,21 @@ + + + + logistics-parent + com.zhangzeyuan + 1.0-SNAPSHOT + + 4.0.0 + + logistics-manager + + + com.zhangzeyuan + logistics-common + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/logistics-parent/logustucs-manager-web/pom.xml b/logistics-parent/logustucs-manager-web/pom.xml new file mode 100644 index 0000000..e8d1f0c --- /dev/null +++ b/logistics-parent/logustucs-manager-web/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + com.zhangzeyuan + logustucs-manager-web + 1.0-SNAPSHOT + war + + logustucs-manager-web Maven Webapp + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + + junit + junit + 4.12 + test + + + + + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + / + 8082 + + + + + diff --git a/springboot_all/springboot01/pom.xml b/springboot_all/springboot01/pom.xml index d4f4eb1..ae75734 100644 --- a/springboot_all/springboot01/pom.xml +++ b/springboot_all/springboot01/pom.xml @@ -7,21 +7,45 @@ org.springframework.boot spring-boot-starter-parent - 2.4.2 + 2.4.5 org.zhangzeyuan springboot01 1.0-SNAPSHOT - + war + + 1.8 + org.springframework.boot spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-tomcat + + provided + + org.springframework.boot spring-boot-starter-test - + + + org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.3 @@ -74,6 +98,12 @@ spring-boot-starter-thymeleaf 2.4.5 + + org.springframework.boot + spring-boot-devtools + 2.4.5 + true + @@ -82,6 +112,9 @@ org.springframework.boot spring-boot-maven-plugin + + true + diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java index 3e4d4c5..b78bfce 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java @@ -1,7 +1,11 @@ package com.zhangzeyuan; +import com.zhangzeyuan.pojo.Emp; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.stereotype.Component; /** @@ -11,8 +15,21 @@ import org.springframework.stereotype.Component; */ @SpringBootApplication //@Component("com.zhangzeyuan.mapper") -public class SpringBoot01Application { +public class SpringBoot01Application extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + + return application.sources(SpringBoot01Application.class); + } + public static void main(String[] args) { - SpringApplication.run(SpringBoot01Application.class, args); + ConfigurableApplicationContext run = SpringApplication.run(SpringBoot01Application.class, args); + Emp bean = run.getBean("com.zhangzeyuan.pojo.Emp",Emp.class); + System.out.println(bean); + String[] beanDefinitionNames = run.getBeanDefinitionNames(); + for (String beanDefinitionName : beanDefinitionNames) { + System.out.println(beanDefinitionName); + } } } diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/config/MyConfiguration.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/config/MyConfiguration.java new file mode 100644 index 0000000..0271fe7 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/config/MyConfiguration.java @@ -0,0 +1,15 @@ +package com.zhangzeyuan.config; + +import com.zhangzeyuan.pojo.Emp; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +/** + * @Author ZZY_1 + * @Date 2024/1/1 10:21 + * @Version 1.0 + */ +@Configuration(proxyBeanMethods = true) +@Import(Emp.class) +public class MyConfiguration { +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java index bbeafe0..e397c01 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java @@ -5,7 +5,6 @@ import com.zhangzeyuan.pojo.Emp; import com.zhangzeyuan.service.EmpService; import org.springframework.stereotype.Controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java index feddeaa..cb0fcfe 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java @@ -16,7 +16,7 @@ import java.util.Map; * @Date 2023/12/30 17:37 * @Version 1.0 */ -@Controller +@Controller("/freemarker.do") public class FreemarkerController { @Autowired private EmpService empService; diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java index f36319d..97c3564 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java @@ -2,7 +2,6 @@ package com.zhangzeyuan.controller; import com.zhangzeyuan.pojo.User; import com.zhangzeyuan.service.UserService; -import com.zhangzeyuan.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java index 461b6b6..ed7db26 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java @@ -1,8 +1,20 @@ package com.zhangzeyuan.controller; +import com.github.pagehelper.PageInfo; +import com.zhangzeyuan.pojo.Emp; +import com.zhangzeyuan.service.EmpService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -10,11 +22,49 @@ import java.util.Map; * @Date 2023/12/30 19:19 * @Version 1.0 */ -@Controller +@RequestMapping("/thymeleaf.do") +@Controller() public class ThymeleafController { + @Autowired + private EmpService empService; @RequestMapping("/showIndex") - public String showIndex(Map map) { + public String showIndex(Map map, HttpServletRequest req, HttpSession session) { + // 向request域放数据 + req.setAttribute("msg", "requestMessage"); + // 向session域放数据 + session.setAttribute("msg", "sessionMessage"); + // 向application域放数据 + req.getServletContext().setAttribute("msg", "applicationMessage"); map.put("msg", "testMessage"); + int i = 1 / 0; return "index"; } + + @RequestMapping("/findAllEmp") + public String findAll(Map map){ + List emps = empService.findAll(); + map.put("emps", emps); + return "showEmpThyme"; + } + + @RequestMapping("/findEmp") + public String findEmp(Map map){ + Emp emp = empService.findByEmpno(7839); + map.put("emp", emp); + return "showEmpThyme"; + } + @RequestMapping("removeEmp") + public ModelAndView removeEmp(String empno,String ename){ + ModelAndView mv = new ModelAndView(); + System.out.println("removeEmp"); + System.out.println(empno+":"+ename); + Boolean bool= empService.removeEmp(empno, ename); + mv.setViewName("redirect:findAllEmp"); + if (!bool){ + Map model = mv.getModel(); + model.put("error", "删除失败"); + return mv; + } + return mv; + } } diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptor.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptor.java new file mode 100644 index 0000000..74737c4 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptor.java @@ -0,0 +1,31 @@ +package com.zhangzeyuan.interceptors; + +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @Author ZZY_1 + * @Date 2023/12/31 22:09 + * @Version 1.0 + */ +@Component +public class MyInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + return false; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptorConfig.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptorConfig.java new file mode 100644 index 0000000..648ed84 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/interceptors/MyInterceptorConfig.java @@ -0,0 +1,26 @@ +package com.zhangzeyuan.interceptors; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * @Author ZZY_1 + * @Date 2023/12/31 22:11 + * @Version 1.0 + */ +@Component +public class MyInterceptorConfig implements WebMvcConfigurer { + @Autowired + MyInterceptor myInterceptor; + //配置拦截器的路径 + + @Override + public void addInterceptors(InterceptorRegistry registry) { + InterceptorRegistration interceptorRegistration = + registry.addInterceptor(myInterceptor).addPathPatterns("/**").excludePathPatterns("/login"); + + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java index a1524e8..a55ed4d 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java @@ -13,4 +13,8 @@ import java.util.List; @Mapper public interface EmpMapper { List findAll(); + + Emp findByEmpno(int i); + + int removeEmp(String empno, String ename); } diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java index f5f5c76..7d7a8af 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java @@ -13,4 +13,8 @@ import java.util.List; public interface EmpService { PageInfo findByPage(Integer pageNum, Integer pageSize); List findAll(); + + Emp findByEmpno(int i); + + Boolean removeEmp(String empno, String ename); } diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java index a15da29..870475c 100644 --- a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java @@ -46,4 +46,16 @@ public class EmpServiceImpl implements EmpService { List list =empMapper.findAll(); return list; } + + @Override + public Emp findByEmpno(int i) { + Emp emp = empMapper.findByEmpno( i); + return emp; + } + + @Override + public Boolean removeEmp(String empno, String ename) { + int i = empMapper.removeEmp(empno, ename); + return i>0; + } } diff --git a/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml b/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml index 0f85777..a927c24 100644 --- a/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml +++ b/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml @@ -3,9 +3,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + delete from emp where empno = #{empno} and ename =#{ename} + + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/error.html b/springboot_all/springboot01/src/main/resources/templates/error.html new file mode 100644 index 0000000..9f7dfb3 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/templates/error.html @@ -0,0 +1,10 @@ + + + + + Title + + +您的电脑将要10s内爆炸 + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/index.html b/springboot_all/springboot01/src/main/resources/templates/index.html index 6513172..44a992b 100644 --- a/springboot_all/springboot01/src/main/resources/templates/index.html +++ b/springboot_all/springboot01/src/main/resources/templates/index.html @@ -5,8 +5,19 @@ Title - this is first thymeleaf! - - + this is first thymeleaf!
+ +
request: + + + +
session: + + + +
applcation: + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/showEmpThyme.html b/springboot_all/springboot01/src/main/resources/templates/showEmpThyme.html new file mode 100644 index 0000000..92416dd --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/templates/showEmpThyme.html @@ -0,0 +1,98 @@ + + + + + Title + + +this is first thymeleaf! + + +工号: +: +: +: +: +: +: + + + + + +工号: +: +: +: +: +: +: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
索引序号总人数偶数索引?奇数索引?第一?最后?工号姓名职务上级入职日期yearmonthday工资补助部门号
删除
+ + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/test/java/com/zhangzeyuan/SpringBoot01ApplicationTest.java b/springboot_all/springboot01/src/test/java/com/zhangzeyuan/SpringBoot01ApplicationTest.java new file mode 100644 index 0000000..2181223 --- /dev/null +++ b/springboot_all/springboot01/src/test/java/com/zhangzeyuan/SpringBoot01ApplicationTest.java @@ -0,0 +1,29 @@ +package com.zhangzeyuan; + +import com.zhangzeyuan.pojo.Emp; +import com.zhangzeyuan.service.EmpService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * @Author ZZY_1 + * @Date 2023/12/31 21:58 + * @Version 1.0 + */ +@SpringBootTest(classes = SpringBoot01Application.class) +public class SpringBoot01ApplicationTest { + + @Autowired + private EmpService empService; + @Test + public void testFindAll() { + List list = empService.findAll(); + list.forEach(System.out::println); + } + +} \ No newline at end of file