• SprinBoot整合SSM之添加


    上一篇博客已经把所需要用到的依赖,分层,配置文件都已经书写好了,这里我们直接说明添加的代码

    从dao层开始:

      //添加
        public int addair(Air air);

    service:

     public int addair(Air air);
      @Override

    //事务的参与 @Transactional
    public int addair(Air air) { return dao.addair(air); }

    Controller:

       //先跳转到添加页面
        @RequestMapping("/goAddPage")
        public String goAddPage(){
            return "add";
        }
        //添加功能
        @RequestMapping("/addAir")
        public String addAir(Air air){
            try{
                int addair = iairService.addair(air);
            }catch (Exception e){
                e.printStackTrace();
            }
            return "forward:/gohome";
        }

    实体层:

    public class Air {
        private Integer id;
        private String district;
        @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")
        @JsonSerialize(using = JsonDateSerializer.class)
        private Date monitorTime;
        private Integer pm10;
        private Integer pm25;
        private String monitoringStation;
        private Date createDate;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public String getDistrict() {
            return district;
        }
    
        public void setDistrict(String district) {
            this.district = district;
        }
    
        public Date getMonitorTime() {
            return monitorTime;
        }
    
        public void setMonitorTime(Date monitorTime) {
            this.monitorTime = monitorTime;
        }
    
        public Integer getPm10() {
            return pm10;
        }
    
        public void setPm10(Integer pm10) {
            this.pm10 = pm10;
        }
    
        public Integer getPm25() {
            return pm25;
        }
    
        public void setPm25(Integer pm25) {
            this.pm25 = pm25;
        }
    
        public String getMonitoringStation() {
            return monitoringStation;
        }
    
        public void setMonitoringStation(String monitoringStation) {
            this.monitoringStation = monitoringStation;
        }
    
        public Date getCreateDate() {
            return createDate;
        }
    
        public void setCreateDate(Date createDate) {
            this.createDate = createDate;
        }
    }

    以上就是全部添加的代码,忽略前台页面哈,太。。。。。

    在添加的时候,会涉及到一个日期类型转换的问题,具体详情请看下一篇博客

  • 相关阅读:
    关于Java中System.currentTimeMillis和System.nanoTime的错误认识
    多线程以外
    vim 小技巧
    Virtual Box HostOnly网络模式配置
    How 30 Minutes a Day Can Increase Your Intelligence
    YUM命令使用
    Hash算法及其应用
    jetty + apache httpd 反向代理配置
    使用SCTP优化网络
    .NET书籍推荐
  • 原文地址:https://www.cnblogs.com/1234AAA/p/9220019.html
Copyright © 2020-2023  润新知