Browse Source

byh24/11/4 更改了结构

byh 1 week ago
parent
commit
4da3931791

+ 78 - 0
src/lsjb/bo/yonghuVO/YongHuVo.java

@@ -0,0 +1,78 @@
+package lsjb.bo.yonghuVO;
+
+import java.sql.Timestamp;
+
+public class YongHuVo {
+    private Integer id;
+    private String username;
+    private String password;
+    private String bumen;
+    private Integer zhuangtai;
+    private Timestamp chuangjiantime;
+    private String yonghuleixing;
+    private String dianhua;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getBumen() {
+        return bumen;
+    }
+
+    public void setBumen(String bumen) {
+        this.bumen = bumen;
+    }
+
+    public Integer getZhuangtai() {
+        return zhuangtai;
+    }
+
+    public void setZhuangtai(Integer zhuangtai) {
+        this.zhuangtai = zhuangtai;
+    }
+
+    public Timestamp getChuangjiantime() {
+        return chuangjiantime;
+    }
+
+    public void setChuangjiantime(Timestamp chuangjiantime) {
+        this.chuangjiantime = chuangjiantime;
+    }
+
+    public String getYonghuleixing() {
+        return yonghuleixing;
+    }
+
+    public void setYonghuleixing(String yonghuleixing) {
+        this.yonghuleixing = yonghuleixing;
+    }
+
+    public String getDianhua() {
+        return dianhua;
+    }
+
+    public void setDianhua(String dianhua) {
+        this.dianhua = dianhua;
+    }
+}

+ 22 - 0
src/lsjb/controller/yonghuController/YongHuController.java

@@ -0,0 +1,22 @@
+package lsjb.controller.yonghuController;
+
+import lsjb.bo.yonghuVO.YongHuVo;
+import lsjb.service.yonghuService.YongHuService;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("yonghu")
+public class YongHuController {
+    @Resource
+    YongHuService yongHuService;
+
+    @RequestMapping("addYongHu")
+    public int addYongHu(YongHuVo vo){
+        yongHuService.saveYongHu(vo);
+        System.out.println("Hello" + vo.getUsername());
+        return 1;
+    }
+}

+ 27 - 4
src/lsjb/lsjbSpring.xml

@@ -10,7 +10,12 @@
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
 ">
-
+<!--    **       **       ****                                     -->
+<!--    ** **    **      **   **                                   -->
+<!--    **  **   **     **     **                                  -->
+<!--    **   **  **     **     **                                  -->
+<!--    **    ** **      **   **                                   -->
+<!--    **     ****       ****                                     -->
 
     <!--json整合     需要导入 jackson-annotations-*.jar,jackson-core-.jar,jackson-databind-.jar -->
     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
@@ -40,11 +45,18 @@
 
 
     <!--    扫描包下所有类,为添加了@Service、@Component、@Controller、@Repository修饰的类创建对象并存入IOC容器-->
+<!--    规则-->
     <context:component-scan base-package="lsjb.controller.guizeController"></context:component-scan>
+    <context:component-scan base-package="lsjb.service.guizeService"></context:component-scan>
+
+<!--    用户-->
+    <context:component-scan base-package="lsjb.controller.yonghuController"></context:component-scan>
+    <context:component-scan base-package="lsjb.service.yonghuService"></context:component-scan>
+
+
     <mvc:default-servlet-handler></mvc:default-servlet-handler>
     <mvc:annotation-driven></mvc:annotation-driven>
 
-    <context:component-scan base-package="lsjb.service.guizeService"></context:component-scan>
 
     <bean id="gydxdb" class="org.apache.commons.dbcp2.BasicDataSource">
         <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
@@ -55,7 +67,12 @@
 
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
         <property name="dataSource" ref="gydxdb"></property>
-        <property name="mapperLocations" value="classpath:lsjb/mapper/guizeMapper/guize.xml"></property>
+        <property name="mapperLocations"
+                  value="classpath:lsjb/mapper/guizeMapper/guize.xml,
+                  classpath:lsjb/mapper/yonghuMapper/yonghu.xml"
+        >
+
+        </property>
 
         <!--        显示SQL-->
         <property name="configuration">
@@ -67,7 +84,13 @@
 
     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
-        <property name="basePackage" value="lsjb.mapper.guizeMapper"></property>
+        <property name="basePackage"
+                  value="lsjb.mapper.guizeMapper,
+                  lsjb.mapper.yonghuMapper"
+        >
+        </property>
+
+<!--        <property name="basePackage" value="lsjb.mapper.guizeMapper"></property>-->
     </bean>
 
     <bean id="transactionManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

+ 16 - 0
src/lsjb/mapper/yonghuMapper/YongHuInterface.java

@@ -0,0 +1,16 @@
+package lsjb.mapper.yonghuMapper;
+
+import lsjb.bo.yonghuVO.YongHuVo;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+@Component
+public interface YongHuInterface {
+    public void addYongHu(YongHuVo vo);
+
+    public void deleteYongHu(YongHuVo vo);
+
+    public void updateYongHu(YongHuVo vo);
+
+    public List queryYongHu(YongHuVo vo);
+}

+ 60 - 0
src/lsjb/mapper/yonghuMapper/yonghu.xml

@@ -0,0 +1,60 @@
+<?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="lsjb.mapper.yonghuMapper.YongHuInterface">
+    <!--    记得改id名-->
+    <parameterMap id="yhvo" type="lsjb.bo.yonghuVO.YongHuVo"></parameterMap>
+    <resultMap id="yhrvo" type="lsjb.bo.yonghuVO.YongHuVo"></resultMap>
+
+    <insert id="addYongHu" parameterMap="yhvo">
+        insert into g2_table_user (username,password,bumen,zhuangtai,chuangjiantime,yonghuleixing,dianhua)
+        values (#{username},#{password},#{bumen},#{zhuangtai},#{chuangjiantime},#{yonghuleixing},#{dianhua})
+    </insert>
+
+<!--    <delete id="deleteYongHu" parameterMap="yhvo">-->
+<!--        delete from g2_table_guize where gzname = #{gzname}-->
+<!--    </delete>-->
+
+<!--    <update id="updateYongHu" parameterMap="yhvo">-->
+<!--        update g2_table_guize-->
+<!--        <set>-->
+<!--            <trim suffixOverrides=",">-->
+<!--                <if test="newgzname != null and newgzname != '' ">-->
+<!--                    gzname = #{newgzname},-->
+<!--                </if>-->
+<!--                <if test="luncishu != null">-->
+<!--                    luncishu = #{luncishu},-->
+<!--                </if>-->
+<!--                <if test="luncitime != null">-->
+<!--                    luncitime = #{luncitime},-->
+<!--                </if>-->
+<!--                <if test="jiangetime != null">-->
+<!--                    jiangetime = #{jiangetime},-->
+<!--                </if>-->
+<!--            </trim>-->
+<!--        </set>-->
+<!--        where gzname = #{gzname}-->
+<!--    </update>-->
+
+<!--    <select id="queryYongHu" parameterMap="yhvo" resultMap="yhrvo">-->
+<!--        select gzname,luncishu,luncitime,jiangetime from g2_table_guize-->
+<!--        <where>-->
+<!--            1=1-->
+<!--            <if test="gzname != null and gzname != '' ">-->
+<!--                and gzname = #{gzname}-->
+<!--            </if>-->
+<!--            <if test="luncishu != null">-->
+<!--                and luncishu = #{luncishu}-->
+<!--            </if>-->
+<!--            <if test="luncitime != null">-->
+<!--                and luncitime = #{luncitime}-->
+<!--            </if>-->
+<!--            <if test="jiangetime != null">-->
+<!--                and jiangetime = #{jiangetime}-->
+<!--            </if>-->
+<!--        </where>-->
+<!--    </select>-->
+
+
+</mapper>

+ 15 - 0
src/lsjb/service/yonghuService/YongHuService.java

@@ -0,0 +1,15 @@
+package lsjb.service.yonghuService;
+
+import lsjb.bo.yonghuVO.YongHuVo;
+
+import java.util.List;
+
+public interface YongHuService {
+    public void saveYongHu(YongHuVo vo);
+
+    public void deleteYongHu(YongHuVo vo);
+
+    public void updateYongHu(YongHuVo vo);
+
+    public List queryYongHu(YongHuVo vo);
+}

+ 36 - 0
src/lsjb/service/yonghuService/YongHuServiceImpl.java

@@ -0,0 +1,36 @@
+package lsjb.service.yonghuService;
+
+import lsjb.bo.yonghuVO.YongHuVo;
+import lsjb.mapper.yonghuMapper.YongHuInterface;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+@Service
+public class YongHuServiceImpl implements YongHuService{
+    @Resource
+    YongHuInterface yongHuInterface;
+    @Override
+    public void saveYongHu(YongHuVo vo) {
+        yongHuInterface.addYongHu(vo);
+        System.out.println(vo.getUsername()+"添加成功");
+    }
+
+    @Override
+    public void deleteYongHu(YongHuVo vo) {
+        yongHuInterface.deleteYongHu(vo);
+
+    }
+
+    @Override
+    public void updateYongHu(YongHuVo vo) {
+        yongHuInterface.updateYongHu(vo);
+
+    }
+
+    @Override
+    public List queryYongHu(YongHuVo vo) {
+
+        return yongHuInterface.queryYongHu(vo);
+    }
+}

+ 85 - 0
src/lsjb/spring/guizeSpring.xml

@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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:mvc="http://www.springframework.org/schema/mvc"
+       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
+">
+
+
+    <!--json整合     需要导入 jackson-annotations-*.jar,jackson-core-.jar,jackson-databind-.jar -->
+    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
+    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
+        <property name="messageConverters">
+            <list>
+                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
+                    <property name="supportedMediaTypes">
+                        <list>
+                            <value>text/html; charset=UTF-8</value>
+                            <value>application/json;charset=UTF-8</value>
+                        </list>
+                    </property>
+                </bean>
+                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
+                    <property name="supportedMediaTypes">
+                        <list>
+                            <value>text/html; charset=UTF-8</value>
+                            <value>application/json;charset=UTF-8</value>
+                        </list>
+                    </property>
+                </bean>
+            </list>
+        </property>
+    </bean>
+
+
+
+    <!--    扫描包下所有类,为添加了@Service、@Component、@Controller、@Repository修饰的类创建对象并存入IOC容器-->
+    <!--    规则-->
+    <context:component-scan base-package="lsjb.controller.guizeController"></context:component-scan>
+    <context:component-scan base-package="lsjb.service.guizeService"></context:component-scan>
+
+
+
+    <mvc:default-servlet-handler></mvc:default-servlet-handler>
+    <mvc:annotation-driven></mvc:annotation-driven>
+
+
+    <bean id="gydxdb" class="org.apache.commons.dbcp2.BasicDataSource">
+        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
+        <property name="url" value="jdbc:mysql://47.92.102.27:53306/gydx"></property>
+        <property name="username" value="gydx"></property>
+        <property name="password" value="gydx123456"></property>
+    </bean>
+
+    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+        <property name="dataSource" ref="gydxdb"></property>
+        <property name="mapperLocations" value="classpath:lsjb/mapper/guizeMapper/guize.xml">
+
+        </property>
+
+        <!--        显示SQL-->
+        <property name="configuration">
+            <bean class="org.apache.ibatis.session.Configuration">
+                <property name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl" />
+            </bean>
+        </property>
+    </bean>
+
+    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
+        <property name="basePackage" value="lsjb.mapper.guizeMapper"></property>
+    </bean>
+
+    <bean id="transactionManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="gydxdb"></property>
+    </bean>
+
+
+
+</beans>

+ 92 - 0
src/lsjb/spring/yonghuSpring.xml

@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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:mvc="http://www.springframework.org/schema/mvc"
+       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
+">
+
+
+    <!--json整合     需要导入 jackson-annotations-*.jar,jackson-core-.jar,jackson-databind-.jar -->
+    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
+    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
+        <property name="messageConverters">
+            <list>
+                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
+                    <property name="supportedMediaTypes">
+                        <list>
+                            <value>text/html; charset=UTF-8</value>
+                            <value>application/json;charset=UTF-8</value>
+                        </list>
+                    </property>
+                </bean>
+                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
+                    <property name="supportedMediaTypes">
+                        <list>
+                            <value>text/html; charset=UTF-8</value>
+                            <value>application/json;charset=UTF-8</value>
+                        </list>
+                    </property>
+                </bean>
+            </list>
+        </property>
+    </bean>
+
+
+
+    <!--    扫描包下所有类,为添加了@Service、@Component、@Controller、@Repository修饰的类创建对象并存入IOC容器-->
+<!--    &lt;!&ndash;    规则&ndash;&gt;-->
+<!--    <context:component-scan base-package="lsjb.controller.guizeController"></context:component-scan>-->
+<!--    <context:component-scan base-package="lsjb.service.guizeService"></context:component-scan>-->
+
+    <!--    用户-->
+    <context:component-scan base-package="lsjb.controller.yonghuController"></context:component-scan>
+    <context:component-scan base-package="lsjb.service.yonghuService"></context:component-scan>
+
+
+    <mvc:default-servlet-handler></mvc:default-servlet-handler>
+    <mvc:annotation-driven></mvc:annotation-driven>
+
+
+    <bean id="gydxdb" class="org.apache.commons.dbcp2.BasicDataSource">
+        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
+        <property name="url" value="jdbc:mysql://47.92.102.27:53306/gydx"></property>
+        <property name="username" value="gydx"></property>
+        <property name="password" value="gydx123456"></property>
+    </bean>
+
+    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+        <property name="dataSource" ref="gydxdb"></property>
+        <property name="mapperLocations"
+                  value="classpath:lsjb/mapper/yonghuMapper/yonghu.xml">
+
+        </property>
+
+        <!--        显示SQL-->
+        <property name="configuration">
+            <bean class="org.apache.ibatis.session.Configuration">
+                <property name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl" />
+            </bean>
+        </property>
+    </bean>
+
+    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
+        <property name="basePackage"
+                  value="lsjb.mapper.yonghuMapper">
+        </property>
+
+    </bean>
+
+    <bean id="transactionManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="gydxdb"></property>
+    </bean>
+
+
+
+</beans>

+ 47 - 11
web/WEB-INF/web.xml

@@ -5,21 +5,57 @@
          version="4.0">
 
 
-<servlet>
-    <servlet-name>lsjbmvc</servlet-name>
-    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+<!--<servlet>-->
+<!--    <servlet-name>lsjbmvc</servlet-name>-->
+<!--    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>-->
 
-    <init-param>
-        <param-name>contextConfigLocation</param-name>
-        <param-value>classpath:lsjb/lsjbSpring.xml</param-value>
-    </init-param>
+<!--    <init-param>-->
+<!--        <param-name>contextConfigLocation</param-name>-->
+<!--        <param-value>classpath:lsjb/lsjbSpring.xml</param-value>-->
+<!--    </init-param>-->
 
-    <load-on-startup>1</load-on-startup>
-</servlet>
+<!--    <load-on-startup>1</load-on-startup>-->
+<!--</servlet>-->
+
+<!--    <servlet-mapping>-->
+<!--        <servlet-name>lsjbmvc</servlet-name>-->
+<!--        <url-pattern>*.lsjb</url-pattern>-->
+<!--    </servlet-mapping>-->
+
+<!--规则-->
+    <servlet>
+        <servlet-name>guizemvc</servlet-name>
+        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+
+        <init-param>
+            <param-name>contextConfigLocation</param-name>
+            <param-value>classpath:lsjb/spring/guizeSpring.xml</param-value>
+        </init-param>
+
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>guizemvc</servlet-name>
+        <url-pattern>*.guize</url-pattern>
+    </servlet-mapping>
+
+<!--用户-->
+    <servlet>
+        <servlet-name>yonghumvc</servlet-name>
+        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+
+        <init-param>
+            <param-name>contextConfigLocation</param-name>
+            <param-value>classpath:lsjb/spring/yonghuSpring.xml</param-value>
+        </init-param>
+
+        <load-on-startup>1</load-on-startup>
+    </servlet>
 
     <servlet-mapping>
-        <servlet-name>lsjbmvc</servlet-name>
-        <url-pattern>*.lsjb</url-pattern>
+        <servlet-name>yonghumvc</servlet-name>
+        <url-pattern>*.yonghu</url-pattern>
     </servlet-mapping>
 
 

+ 1 - 1
web/index.jsp

@@ -11,7 +11,7 @@
     <title>$Title$</title>
 </head>
 <body>
-<form action="./guize/addGuiZe.lsjb">
+<form action="./guize/addGuiZe.guize">
   <input type="text" name="gzname">
   <br>
   <input type="text" name="luncishu">