Browse Source

byh24/11/6用户增删改查

byh 1 week atrás
parent
commit
ce480b3c8b

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

@@ -11,6 +11,7 @@ public class YongHuVo {
     private Timestamp chuangjiantime;
     private String yonghuleixing;
     private String dianhua;
+    private String newusername;//update时用来存新的用户名
 
     public Integer getId() {
         return id;
@@ -75,4 +76,12 @@ public class YongHuVo {
     public void setDianhua(String dianhua) {
         this.dianhua = dianhua;
     }
+
+    public String getNewusername() {
+        return newusername;
+    }
+
+    public void setNewusername(String newusername) {
+        this.newusername = newusername;
+    }
 }

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

@@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 @RestController
 @RequestMapping("yonghu")
@@ -19,4 +20,21 @@ public class YongHuController {
         System.out.println("Hello" + vo.getUsername());
         return 1;
     }
+
+    @RequestMapping("deleteYongHu")
+    public int deleteYongHu(YongHuVo vo){
+        yongHuService.deleteYongHu(vo);
+        return 1;
+    }
+
+    @RequestMapping("updateYongHu")
+    public int updateYongHu(YongHuVo vo){
+        yongHuService.updateYongHu(vo);
+        return 1;
+    }
+
+    @RequestMapping("queryYongHu")
+    public List queryYongHu(YongHuVo vo){
+        return yongHuService.queryYongHu(vo);
+    }
 }

+ 49 - 43
src/lsjb/mapper/yonghuMapper/yonghu.xml

@@ -8,53 +8,59 @@
     <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 into g2_table_user (username,password,bumen,zhuangtai,yonghuleixing,dianhua)
+        values (#{username},#{password},#{bumen},#{zhuangtai},#{yonghuleixing},#{dianhua})
     </insert>
 
-<!--    <delete id="deleteYongHu" parameterMap="yhvo">-->
-<!--        delete from g2_table_guize where gzname = #{gzname}-->
-<!--    </delete>-->
+    <delete id="deleteYongHu" parameterMap="yhvo">
+        delete from g2_table_user where username = #{username}
+    </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>-->
+    <update id="updateYongHu" parameterMap="yhvo">
+        update g2_table_user
+        <set>
+            <trim suffixOverrides=",">
+                <if test="newusername != null and newusername != '' ">
+                    username = #{newusername},
+                </if>
+                <if test="password != null and password != '' ">
+                    password = #{password},
+                </if>
+                <if test="bumen != null and bumen != '' ">
+                    bumen = #{bumen},
+                </if>
+                <if test="zhuangtai != null">
+                    zhuangtai = #{zhuangtai},
+                </if>
+                <if test="yonghuleixing != null and yonghuleixing != '' ">
+                    yonghuleixing = #{yonghuleixing},
+                </if>
+                <if test="dianhua != null and dianhua != '' ">
+                    dianhua = #{dianhua},
+                </if>
+            </trim>
+        </set>
+        where username = #{username}
+    </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>-->
+    <select id="queryYongHu" parameterMap="yhvo" resultMap="yhrvo">
+        select id,username,password,bumen,zhuangtai,chuangjiantime,yonghuleixing,dianhua from g2_table_user
+        <where>
+            1=1
+            <if test="username != null and username != '' ">
+                and username = #{username}
+            </if>
+            <if test="dianhua != null and username != '' ">
+                and dianhua = #{dianhua}
+            </if>
+            <if test="zhuangtai != null">
+                and zhuangtai = #{zhuangtai}
+            </if>
+            <if test="chuangjiantime != null and username != '' ">
+                and chuangjiantime = #{chuangjiantime}
+            </if>
+        </where>
+    </select>
 
 
 </mapper>

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

@@ -2,11 +2,13 @@ package lsjb.service.yonghuService;
 
 import lsjb.bo.yonghuVO.YongHuVo;
 import lsjb.mapper.yonghuMapper.YongHuInterface;
+import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.List;
 @Service
+//@Primary 当一个接口有多个实现时,实现打上这个注解的类
 public class YongHuServiceImpl implements YongHuService{
     @Resource
     YongHuInterface yongHuInterface;

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

@@ -40,10 +40,6 @@
 
 
     <!--    扫描包下所有类,为添加了@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>