栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

我的实习期,不合格的增删改查

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

我的实习期,不合格的增删改查

进入人生第一家公司,一个月,增删改查,用的被封装的各种东西。所以最终只能查,增删改不能被保存,很多东西我也不知道怎样去配,当然也有可能有多了的、不需要的东西,所以不要问我,我也是小白,我解答不了~0.0~

 以下是我的springmvc(model,controller,service及其实现类,dao,dao.xml,jsp)和数据库

 LwxModel.java:

@Scope(value = "prototype")
public class LwxModel extends baseModel {
    private String SID;
    private String SNAME;
    private String SSEX;
    private String SBIRTHDAY;
    private String SCLASS;


    public String getSID() {
        return SID;
    }

    public void setSID(String SID) {
        this.SID = SID;
    }

    public String getSNAME() {
        return SNAME;
    }

    public void setSNAME(String SNAME) {
        this.SNAME = SNAME;
    }

    public String getSSEX() {
        return SSEX;
    }

    public void setSSEX(String SSEX) {
        this.SSEX = SSEX;
    }

    public String getSBIRTHDAY() {
        return SBIRTHDAY;
    }

    public void setSBIRTHDAY(String SBIRTHDAY) {
        this.SBIRTHDAY = SBIRTHDAY;
    }

    public String getSCLASS() {
        return SCLASS;
    }

    public void setSCLASS(String SCLASS) {
        this.SCLASS = SCLASS;
    }

    private String ParentPageNumber;

    public String getParentPageSize() {
        return ParentPageSize;
    }

    public void setParentPageSize(String parentPageSize) {
        ParentPageSize = parentPageSize;
    }

    private String ParentPageSize;

    public String getParentPageNumber() {
        return ParentPageNumber;
    }

    public void setParentPageNumber(String parentPageNumber) {
        ParentPageNumber = parentPageNumber;
    }

    private String pageNumber;
    private String pageSize;

    public String getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(String pageNumber) {
        this.pageNumber = pageNumber;
    }

    public String getPageSize() {
        return pageSize;
    }

    public void setPageSize(String pageSize) {
        this.pageSize = pageSize;
    }

    private String add;
    private String edi;
    private String del;
    private String studentDatas;

    public String getAdd() {
        return add;
    }

    public void setAdd(String add) {
        this.add = add;
    }

    public String getEdi() {
        return edi;
    }

    public void setEdi(String edi) {
        this.edi = edi;
    }

    public String getDel() {
        return del;
    }

    public void setDel(String del) {
        this.del = del;
    }

    public String getStudentDatas() {
        return studentDatas;
    }

    public void setStudentDatas(String studentDatas) {
        this.studentDatas = studentDatas;
    }

    public void loadFromMap(Map map) {
        this.setSID(CommonTools.nullObject2String(map.get("SID")));
        this.setSNAME(CommonTools.nullObject2String(map.get("SNAME")));
        this.setSSEX(CommonTools.nullObject2String(map.get("SSEX")));
        this.setSBIRTHDAY(CommonTools.nullObject2String(map.get("SBIRTHDAY")));
        this.setSCLASS(CommonTools.nullObject2String(map.get("SCLASS")));
    }
}

 LwxController.java:

@Controller

public class LwxController {
//    @Autowired
//    @Qualifier("lwxService")
//    private LwxService lwxServices = null;
    @Autowired
    @Qualifier("BdinfostudentServices")
    private BdinfostudentServices bdinfostudentServices;

    @RequestMapping("lwx.act")
    public String execute(@ModelAttribute("lwxModel") LwxModel lwxModel, Model model,
                          String addStu,String ediStu,String delStu){
        try{
            this.selectModel(model);
        String type = CommonTools.null2String(lwxModel.getOperationType());
        if (baseModel.ADD.equals(type)){
            bdinfostudentServices.addData(lwxModel,model);
               return "basicData/lwx/studentADD";
        }else if (baseModel.SAVE.equals(type)) {
            bdinfostudentServices.saveData(lwxModel, addStu, ediStu, delStu);
            return "";
        }else if (baseModel.EDIT.equals(type)){
            bdinfostudentServices.editData(lwxModel,model);
            return "basicData/lwx/studentUpdate";
        }else if (baseModel.UPDATE.equals(type)){
            bdinfostudentServices.updateData(lwxModel,addStu,ediStu,delStu);
            return "";
        }else if (baseModel.DELETEALL.equals(type)){
            bdinfostudentServices.deleteStudent(lwxModel.getSID());
            return "";
        }else {
            bdinfostudentServices.queryData(lwxModel,model);
            return "basicData/lwx/lwx";
        }
        }catch (Exception e){

        }
        return "basicData/lwx/lwx";
    }

    private void selectModel(Model model) throws Exception{
        TreeMap V_ISFLAG = new TreeMap<>();
        V_ISFLAG.put("-1","请选择");
        V_ISFLAG.put("0", "女");
        V_ISFLAG.put("1", "男");
        model.addAttribute("V_ISFLAG", V_ISFLAG);
    }

}

BdinfostudentServices.java:

public interface BdinfostudentServices {
    public void addData(LwxModel lwxModel, Model model);//新增跳转加权限
    public void saveData(LwxModel lwxModel,String addStu,String ediStu,String delStu) throws Exception;//新增
    public void editData(LwxModel lwxModel,Model model);//回显数据
    public void updateData(LwxModel lwxModel,String addStu,String ediStu,String delStu);//更新
    public int deleteStudent(String sid) throws Exception;//单行删除
    public void queryData(LwxModel lwxModel,Model model);//分页
}

 BdinfostudentServicesImpl.java:

@Service("BdinfostudentServices")
public class BdinfostudentServicesImpl implements BdinfostudentServices {
    @Autowired
    private BdinfostudentDao dao=null;
    @Override
    public void addData(LwxModel lwxModel, Model model) {
        lwxModel.setSID(new GUID().toString());
        model.addAttribute("teshuButton",true);
        Boolean b= UserInfoUtils.getQuanxianByRoles("平台数据查看");
        if (b){
            model.addAttribute("teshuButton",false);
        }
    }

    @Override
    public void saveData(LwxModel lwxModel, String addStu, String ediStu, String delStu) throws Exception {
        Map map= BeanUtils.describe(lwxModel);
        String sid=UserInfoUtils.getCurrenUser().getId();
        String sname=UserInfoUtils.getCurrenUser().getName();


        map.put("SID",sid);
        map.put("SNAME",sname);
        map.put("SBIRTHDAY",map.get("SBIRTHDAY"));
        map.put("SSEX",map.get("SSEX"));
        map.put("SCLASS",map.get("SCLASS"));
        this.dao.insertData(map);
    }

    @Override
    public void editData(LwxModel lwxModel, Model model) {
        try{
            Map dto=new HashMap();
            dto.put("SID",lwxModel.getSID());
            Map map=this.dao.selectByID(dto);
            lwxModel.loadFromMap(map);
            model.addAttribute("teshuButton",true);
            Boolean b=UserInfoUtils.getQuanxianByRoles("平台数据查看");
            if (b){
                model.addAttribute("teshuButton",false);
            }
        }catch (Exception e){

        }
    }

    @Override
    public void updateData(LwxModel lwxModel, String addStu, String ediStu, String delStu) {
        String sid=UserInfoUtils.getCurrenUser().getId();
        String sname=UserInfoUtils.getCurrenUser().getName();
        try{
            Map map= BeanUtils.describe(lwxModel);
            Date date = new Date();
            java.sql.Date time = new java.sql.Date(date.getTime());
            String sbirthday = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time);
            map.put("SID",sid);
            map.put("SNAME",sname);
            map.put("SBIRTHDAY",sbirthday);
            map.put("SSEX",map.get("SSEX"));
            map.put("SCLASS",map.get("SCLASS"));
            this.dao.updateData(map);
        }catch (Exception e){}
    }

    @Override
    public int deleteStudent(String sid) throws Exception {
        Map map=new HashMap();
        map.put("SID",sid);
        return this.dao.updateData(map);
    }

    @Override
    public void queryData(LwxModel lwxModel, Model model) {
        try{
            if(lwxModel.getParentPageNumber()!=null
                    && !lwxModel.getParentPageNumber().equals("")){
                PageInfo pi=new PageInfo();
                pi.setPageNum(Integer.parseInt(lwxModel.getParentPageNumber()));
                pi.setPageSize(Integer.parseInt(lwxModel.getParentPageSize()));
                lwxModel.setPageInfo(pi);
                model.addAttribute("pageNumBack",lwxModel.getParentPageNumber());
                model.addAttribute("pageSizeBack",lwxModel.getParentPageSize());
            }
            PageManager.USE_PAGE_BEGIN(lwxModel);
            lwxModel.getConditions().put("order",lwxModel.getOrder());
            lwxModel.getConditions().put("sort",lwxModel.getSort());
            CommonTools.addParamToMapForPermission(lwxModel.getConditions());
            List list=this.dao.studentlist(lwxModel.getConditions());
            lwxModel.setList(list);
            PageManager.USE_PAGE_END(lwxModel);
            model.addAttribute("teshuButton",true);
            Boolean b=UserInfoUtils.getQuanxianByRoles("平台数据查看");
            if (b){
                model.addAttribute("teshuButton",false);
            }
        }catch (Exception e){}
    }

}

 BdinfostudentDao.java

public interface BdinfostudentDao {
    public int insertData(Map dto) throws Exception;//新增
    public Map selectByID(Map dto) throws Exception;//回显
    public int updateData(Map dto);//列表
    public int deleteData(Map dto);
    public List studentlist(Map dto) throws Exception;//学生列表
}

 BdinfostudentDao.xml




    
        INSERT INTO 'student'('sid','sname','ssex','sbirthday','sclass')
        VALUES(#{SID},#{SNAME},#{SSEX},#{SBIRTHDAY},#{SCLASS})
    
    
        DELETE FROM 'student'
        WHERe SID=#{SID}
    
    
        UPDATE 'student'
        
            
                SID=#{SID},
            
            
                SNAME=#{SNAME},
            
            
                SSEX=#{SSEX},
            
            
                SBIRTHDAY=#{SBIRTHDAY},
            
            
                SCLASS=#{SCLASS},
            
        
        WHERe SID=#{SID}
    
    
        SELECT sid,sname,ssex,sbirthday,sclass
        FROM STUDENT
        WHERe SID=#{SID}
    

lwx.jsp

<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="v"%>
<%@ taglib uri="http://www.hepow.com/html/tags/form" prefix="hepow"%>
<%@ taglib uri="http://www.hepow.com/easyui/tags/form" prefix="ve"%>

<%@ page isELIgnored="false"%>


    
    
    

    lwx
    
    <%@ include file="/common/lib/common-easyui-lib.jsp" %>

    


    
        
        
        
        
        
            
                
                    
                        
                        
                    
                
            
            

                
                    学号:
                      

                    姓名:
                      

                    性别:
                    
                        
                    

                    出生日期:
                     

                    班级:
                     

                
            
        

        

            
            
            
            
            
            
            
            

            
                
                
                
            

            
            
        
    



studentUpdate.jsp

<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="v"%>
<%@ taglib uri="http://www.hepow.com/html/tags/form" prefix="hepow"%>
<%@ taglib uri="http://www.hepow.com/easyui/tags/form" prefix="ve"%>

<%@ page isELIgnored="false"%>


    
    
    
    添加学生
    

    <%@ include file="/common/lib/common-easyui-lib.jsp" %>
    
    
        

    
        
        
        
        
        
        
        
        
        
        

        
        
            
            
                
                    
                    
                
            
            
        
        
            
                学号:
                
                姓名:
                
                性别:
                
                出生日期:
                
                班级:
                
            
        
        

        
            
            
            
            
            
            
        

        
            

                
                
                
                
                
            
            
            
            
                
                
                
                
                
            
        
    


studentADD.jsp

<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="v"%>
<%@ taglib uri="http://www.hepow.com/html/tags/form" prefix="hepow"%>
<%@ taglib uri="http://www.hepow.com/easyui/tags/form" prefix="ve"%>

<%@ page isELIgnored="false"%>


    
    
    
    添加学生

    
    <%@ include file="/common/lib/common-easyui-lib.jsp" %>
    
    


    
        
        
        
            
                
                    
                        
                    
                
            
            
                
                    学号:
                    

                    姓名:
                    

                    性别:
                    

                    出生日期:
                    

                    班级:
                    

                

            
        
        
            
            
            
            
            
        

        
            

                
                
                
                
                
            
            
            
            
                
                
                
                
                
            
        
    


数据库:

 

页面展示:

页面中查询,重置,添加,删除是可以用的,不过后三个应该是被封装的,我没写

编辑,新增,删除是坏的

进公司一个月了,没人主动教,自己也不敢多问,问多了怕烦,不过自己百度真的很慢,有些问题也解决不了,第一次写这个是想记录一下自己的成长历程,加油吧陌生人!

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/631025.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号