zoukankan      html  css  js  c++  java
  • 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;
        }
    }

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

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

  • 相关阅读:
    AC自动机模板
    KMP 模板
    HDU 2746 Cyclic Nacklace
    LCS模板
    POJ 1159 Palindrome
    LIS n^2&nlogn模板
    Codeforces Round #Pi (Div. 2) C. Geometric Progression
    Codeforces Beta Round #25 (Div. 2 Only)E. Test
    Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland
    bzoj5055 膜法师
  • 原文地址:https://www.cnblogs.com/1234AAA/p/9220019.html
Copyright © 2011-2022 走看看