总结文件配置

总结文件配置,第1张

总体大概目录
主要 配置:pom.xml 配置、web.xml配置、applicationContext.xml配置、springmvc.xml配置
日志log4j2.xml、xxMapper.xml配置;
对三层的MVC搭建:entity层、service层、controller层;
对象和SQL映射mapper层;

第一部分:文件初始化,文件配置

1 对pom.xml依赖下载



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0modelVersion>

  <groupId>org.examplegroupId>
  <artifactId>EpidemicBigDataartifactId>
  <version>1.0-SNAPSHOTversion>
  <packaging>warpackaging>

  <name>EpidemicBigData Maven Webappname>
  
  <url>http://www.example.comurl>

  <properties>
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    <maven.compiler.source>1.7maven.compiler.source>
    <maven.compiler.target>1.7maven.compiler.target>

    <spring-version>5.1.6.RELEASEspring-version>
  properties>

  <dependencies>
    <dependency>
      <groupId>junitgroupId>
      <artifactId>junitartifactId>
      <version>4.11version>
      <scope>testscope>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-contextartifactId>
      <version>${spring-version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-aspectsartifactId>
      <version>${spring-version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-ormartifactId>
      <version>${spring-version}version>
    dependency>

    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatis-springartifactId>
      <version>2.0.5version>
    dependency>

    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatisartifactId>
      <version>3.5.5version>
    dependency>

    <dependency>
      <groupId>mysqlgroupId>
      <artifactId>mysql-connector-javaartifactId>
      <version>8.0.20version>
    dependency>

    <dependency>
      <groupId>com.zaxxergroupId>
      <artifactId>HikariCPartifactId>
      <version>3.4.5version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webmvcartifactId>
      <version>${spring-version}version>
    dependency>

    <dependency>
      <groupId>org.projectlombokgroupId>
      <artifactId>lombokartifactId>
      <version>1.18.12version>
    dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.coregroupId>
      <artifactId>jackson-databindartifactId>
      <version>2.11.2version>
    dependency>

    
    
    <dependency>
      <groupId>org.apache.logging.log4jgroupId>
      <artifactId>log4j-slf4j-implartifactId>
      <version>2.11.2version>
    dependency>

    
    <dependency>
      <groupId>org.apache.logging.log4jgroupId>
      <artifactId>log4j-webartifactId>
      <version>2.11.2version>
    dependency>

    
    <dependency>
      <groupId>org.apache.logging.log4jgroupId>
      <artifactId>log4j-jclartifactId>
      <version>2.11.2version>
    dependency>






  dependencies>

  <build>
    <finalName>EpidemicBigDatafinalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-pluginartifactId>
          <version>3.1.0version>
        plugin>
        
        <plugin>
          <artifactId>maven-resources-pluginartifactId>
          <version>3.0.2version>
        plugin>
        <plugin>
          <artifactId>maven-compiler-pluginartifactId>
          <version>3.8.0version>
        plugin>
        <plugin>
          <artifactId>maven-surefire-pluginartifactId>
          <version>2.22.1version>
        plugin>
        <plugin>
          <artifactId>maven-war-pluginartifactId>
          <version>3.2.2version>
        plugin>
        <plugin>
          <artifactId>maven-install-pluginartifactId>
          <version>2.5.2version>
        plugin>
        <plugin>
          <artifactId>maven-deploy-pluginartifactId>
          <version>2.8.2version>
        plugin>
      plugins>
    pluginManagement>
  build>
project>

3、对web.xml进行配置


<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
  
  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>classpath:META-INF/applicationContext.xmlparam-value>
  context-param>

  <servlet>
    <servlet-name>mvcservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    
    <init-param>
      
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:META-INF/springmvc.xmlparam-value>
    init-param>
    
    <load-on-startup>1load-on-startup>
  servlet>

  <servlet-mapping>
    <servlet-name>mvcservlet-name>
    
    <url-pattern>/url-pattern>
  servlet-mapping>

  
  <filter>
    <filter-name>encodingfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
      <param-name>encodingparam-name>
      <param-value>utf-8param-value>
    init-param>
  filter>
  <filter-mapping>
    <filter-name>encodingfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>

  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListenerlistener-class>
  listener>

  <listener>
    <listener-class>org.apache.logging.log4j.web.Log4jServletContextListenerlistener-class>
  listener>

  <context-param>
  <param-name>log4jConfigurationparam-name>
  
  <param-value>classpath:log4j2.xmlparam-value>
context-param>
web-app>

4、对applicationContext.xml配置


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

   
   <context:component-scan base-package="org.lsj">
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
      <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
   context:component-scan>

   
   <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
      <property name="driverClassName" value="com.mysql.cj.jdbc.Driver">property>
      <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/patient?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8">property>
      <property name="username" value="root">property>
      <property name="password" value="123456">property>
      
      <property name="maximumPoolSize" value="20">property>
      
      <property name="connectionTestQuery" value="select 1">property>
   bean>
   
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      
      <property name="dataSource" ref="dataSource">property>
      
      <property name="mapperLocations" value="classpath:org/lsj/**/*.xml">property>
   bean>
   
   <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
      <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory">property>
      
      <property name="basePackage" value="org.lsj">property>
      
      <property name="annotationClass" value="org.apache.ibatis.annotations.Mapper">property>
   bean>
   
   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   
   <property name="dataSource" ref="dataSource">property>
bean>

   
   <tx:advice id="txAdvice" transaction-manager="transactionManager">
      
      
      <tx:attributes>
         <tx:method name="get*" propagation="SUPPORTS"/>
         <tx:method name="find*" propagation="SUPPORTS"/>
         <tx:method name="select*" propagation="SUPPORTS"/>
         <tx:method name="query*" propagation="SUPPORTS"/>
         <tx:method name="*" propagation="REQUIRED"/>
      tx:attributes>
   tx:advice>


   <aop:config>
      
      <aop:pointcut id="txPointcut" expression="execution(* org.lsj.service.*.*(..))"/>
      
      <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut">aop:advisor>
   aop:config>



beans>

5、对springmvc.xml进行配置

<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                     http://www.springframework.org/schema/beans/spring-beans.xsd
                     http://www.springframework.org/schema/context
                     http://www.springframework.org/schema/context/spring-context.xsd
                     http://www.springframework.org/schema/mvc
                     http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
    <context:component-scan base-package="org.lsj">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
    context:component-scan>

    
    <mvc:annotation-driven>mvc:annotation-driven>

    
    <mvc:default-servlet-handler>mvc:default-servlet-handler>

    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        <property name="prefix" value="/">property>
        
        <property name="suffix" value=".jsp">property>
    bean>
    
    
    

beans>
第二部分:三层编写

controller控制层

详情代码

package org.lsj.controller;

import com.sun.org.apache.regexp.internal.RE;
import org.lsj.entity.Province;
import org.lsj.service.ProvinceService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * @Author: Laishijin
 * @Email Lai_shijin@163.com
 * @Date: 2021/12/24 17:07
 */
@RestController
@RequestMapping("/province")
public class ProvinceController {
    private ProvinceService provinceService;

    public ProvinceController(ProvinceService provinceService) {
        this.provinceService = provinceService;
    }
    //    获取登记总人数
    @RequestMapping("/getTotal")
    public int getTotalPeople(){
        return provinceService.getTotalPeople();
    }
    //    获取有确诊人数
    @RequestMapping("/getConfirmed")
    public int getConfirmedPeople(){
        return provinceService.getConfirmedPeople();
    }
    //    获取无症状人数
    @RequestMapping("/getAsymptomatic")
    public int getAsymptomaticPeople(){
        return provinceService.getAsymptomaticPeople();
    }
    //    获取有症状人数
    @RequestMapping("/getSymptomatic")
    public int getSymptomaticPeople(){
        return provinceService.getSymptomaticPeople();
    }
    //    获取疑似病例
    @RequestMapping("/getSuspected")
    public int getSuspectedPeople(){
        return provinceService.getSuspectedPeople();
    }
    //    获取治愈病例
    @RequestMapping("/getCure")
    public int getCurePeople(){
        return provinceService.getCurePeople();
    }
    //    获取重症病例
    @RequestMapping("/getSevere")
    public int getSeverePeople(){
        return provinceService.getSeverePeople();
    }
    //    获取死亡病例
    @RequestMapping("/getDeaths")
    public int getDeathsPeople(){
        return provinceService.getDeathsPeople();
    }
    //    获取省份总病例
    @RequestMapping("getAllProvince")
    public List<Province> getAllProvincePeople(){
        return provinceService.getAllProvincePeople();
    }


}

entity层视图

详情代码

package org.lsj.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@AllArgsConstructor
@NoArgsConstructor
@Data
public class Province {
    private String province ;
    private int total;
}

Service层视图


详情代码

package org.lsj.service.impl;

import org.lsj.entity.Province;
import org.lsj.mapper.ProvinceMapper;
import org.lsj.service.ProvinceService;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProvinceServiceImpl implements ProvinceService {
    private ProvinceMapper provinceMapper;
//    进行注入
    public ProvinceServiceImpl(ProvinceMapper provinceMapper) {
        this.provinceMapper = provinceMapper;
    }
    //    获取登记总人数
    @Override
    public int getTotalPeople() {
        return provinceMapper.getTotalPeople();
    }
    //    获取有确诊人数
    @Override
    public int getConfirmedPeople() {
        return provinceMapper.getConfirmedPeople();
    }
    //    获取无症状人数
    @Override
    public int getAsymptomaticPeople() {
        return provinceMapper.getAsymptomaticPeople();
    }
    //    获取有症状人数
    @Override
    public int getSymptomaticPeople() {
        return provinceMapper.getSymptomaticPeople();
    }
    //    获取疑似病例
    @Override
    public int getSuspectedPeople() {
        return provinceMapper.getSuspectedPeople();
    }
    //    获取治愈病例
    @Override
    public int getCurePeople() {
        return provinceMapper.getCurePeople();
    }
    //    获取重症病例
    @Override
    public int getSeverePeople() {
        return provinceMapper.getSeverePeople();
    }
    //    获取死亡病例
    @Override
    public int getDeathsPeople() {
        return provinceMapper.getDeathsPeople();
    }
    //    获取省份总病例
    @Override
    public List<Province> getAllProvincePeople() {
        return provinceMapper.getAllProvincePeople();
    }
}

Mapper层

详情代码

package org.lsj.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.lsj.entity.Province;

import java.util.List;
@Mapper
public interface ProvinceMapper {
//    获取登记总人数
    public int getTotalPeople();
//    获取累计确诊人数
    public int getConfirmedPeople();
//    获取无症状人数
    public int getAsymptomaticPeople();
//    获取有症状人数
    public int getSymptomaticPeople();
//    获取疑似病例
    public int getSuspectedPeople();
//    获取治愈病例
    public int getCurePeople();
//    获取重症病例
    public int getSeverePeople();
//    获取死亡病例
    public int getDeathsPeople();
//    获取省份总病例
    public List<Province> getAllProvincePeople();

}

第三部分 SQL编写

mapper.xml

代码详情

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.lsj.mapper.ProvinceMapper">

<!--   获取登记总人数 public int getTotalPeople();-->
    <select id="getTotalPeople" resultType="int">
        select count(1) from  patient;
    </select>
<!-- 获取有确诊人数 public int getConfirmedPeople();    -->
    <select id="getConfirmedPeople" resultType="int">
        select count(1) from patient  where patient_type = 1;
    </select>

<!-- 获取无症状人数 public int getAsymptomaticPeople();-->
    <select id="getAsymptomaticPeople" resultType="int">
        select count(1) from patient  where patient_type = 2;
    </select>

<!--      获取有症状人数 public int getSymptomaticPeople();-->
    <select id="getSymptomaticPeople" resultType="int">
        select count(1) from patient  where patient_state = 1;
    </select>

<!--     获取疑似病例 public int getSuspectedPeople();-->
    <select id="getSuspectedPeople" resultType="int">
        select count(1) from patient  where patient_state = 0;
    </select>
<!--      获取治愈病例  public int getCurePeople();-->
   <select id="getCurePeople" resultType="int">
        select count(1) from patient  where patient_state = 2;
   </select>
<!--     获取重症病例 public int getSeverePeople();-->
    <select id="getSeverePeople" resultType="int">
         select count(1) from patient  where patient_state = 3;
    </select>
<!--   获取死亡病例 public int getDeathsPeople();-->
    <select id="getDeathsPeople" resultType="int">
        select count(1) from patient  where patient_state = 4;
    </select>
<!-- 获取省份总病例 public List<Province> getAllProvincePeople();-->
    <select id="getAllProvincePeople" resultType="org.lsj.entity.Province">
        select province,count(id) total from patient group by province ;
    </select>





</mapper>

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/877587.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存