1.先创建实体类:

2.创建mapper层

  1. package cn.kgc.mapper;
  2.  
  3. import cn.kgc.Account;
    import org.apache.ibatis.annotations.Delete;
    import org.apache.ibatis.annotations.Insert;
    import org.apache.ibatis.annotations.Select;
    import org.apache.ibatis.annotations.Update;
  4.  
  5. import java.util.List;
  6.  
  7. /**
    * Created by 86182 on 2019/7/1.
    */
    public interface AccountMapper {
    //查询所有
    @Select("select * from account")
    List<Account> selectAccount();
    //查询单条
    @Select("select * from account where id=#{id}")
    Account selectByid(Integer id);
    //添加
    @Insert("insert into account(id,number,pwd,money,status,createtime) values(#{id},#{number},#{pwd},#{money},#{status},now())")
    Integer insertAccount(Account account);
    //修改
    @Update("update account set number =#{number},pwd=#{pwd},money=#{money},status=#{status} WHERE id =#{id}")
    Integer updateAccount(Account account);
    //删除
    @Delete("delete from account where id=#{id}")
    Integer deleteAccount(Integer id);
    }
    3.创建service
    3.1接口层:
  1. package cn.kgc.service;
  2.  
  3. import cn.kgc.Account;
  4.  
  5. import java.util.List;
  6.  
  7. /**
    * Created by 86182 on 2019/7/1.
    */
    public interface AccountService {
    //页面展示
    List<Account> showData();
    //查询单条
    Account findByData(Integer id);
    //添加
    Integer add(Account account);
    //修改
    Integer edit(Account account);
    //删除
    Integer del(Integer id);
    }
    3.2实现类
  1. package cn.kgc.service;
  2.  
  3. import cn.kgc.mapper.AccountMapper;
    import cn.kgc.Account;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
  4.  
  5. import java.util.List;
  6.  
  7. /**
    * Created by 86182 on 2019/7/1.
    */
    @Service
    @Transactional
    public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountMapper accountMapper;
    @Override
    public List<Account> showData() {
    return accountMapper.selectAccount();
    }
  8.  
  9. @Override
    public Account findByData(Integer id) {
    return accountMapper.selectByid(id);
    }
  10.  
  11. @Override
    public Integer add(Account account) {
    return accountMapper.insertAccount(account);
    }
  12.  
  13. @Override
    public Integer edit(Account account) {
    return accountMapper.updateAccount(account);
    }
  14.  
  15. @Override
    public Integer del(Integer id) {
    return accountMapper.deleteAccount(id);
    }
    }
    4.controller
  1. package cn.kgc.controller;
  2.  
  3. import cn.kgc.service.AccountService;
    import cn.kgc.Account;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
  4.  
  5. import java.util.List;
  6.  
  7. /**
    * Created by 86182 on 2019/7/1.
    */
    @RestController
    public class AccountController {
    @Autowired
    private AccountService accountService;
  8.  
  9. //查询全部
    @RequestMapping("/init.do")
    public List<Account> showData(){
    return accountService.showData();
    }
    //添加
    @RequestMapping("/add.do")
    public int addData(Account account){
    return accountService.add(account);
    }
    //查询单条
    @RequestMapping("/info.do")
    public Account getInfo(Integer id){
    return accountService.findByData(id);
    }
    //修改
    @RequestMapping("/edit.do")
    public int editData(Account account){
    return accountService.edit(account);
    }
    //删除
    @RequestMapping("/del.do")
    public int deleteData(Integer id){
    return accountService.del(id);
    }
    }
    前台页面html

js页面

  1. $(function () {
    initData();
    })
    function initData() {
    $.ajax({
    url:"init.do",
    type:"post", //post的方式提交
    dataType:"json", //数据类型是json格式
    data:{},
    async:true,
    success:function (obj) {
    // alert("success");
    console.log(obj);
    var str="";
    $.each(obj,function(i) {
    str+="<tr>";
    str+=" <td>"+obj[i].id+"</td>";
    str+=" <td>"+obj[i].number+"</td>";
    str+=" <td>"+obj[i].money+"</td>";
    str+=" <td>"+obj[i].status+"</td>";
    str+=" <td>"+obj[i].createtime+"</td>";
    str+=" <td>" +
    "<a href='edit.html?id="+obj[i].id+"'>修改</a>" +
    "|<a href='javascript:void(0);' onclick='delFun("+obj[i].id+")'>删除</a>" +
    "</td>";
    str+="</tr>";
    });
    $("table").append(str);
    },
    error:function () {
    alert("error")
    }
    });
    }
    function delFun(id) {
    $.ajax({
    url:"del.do",
    type:"post",
    dataType:"json",
    data:{"id":id},
    async:true,
    success:function (obj) {
    location.href="main.html";
    },
    error:function () {
    alert("del error")
    }
    });
    }
  1.  

SSM 前后端分离 这里controll层的返回值和之前那个不一样的更多相关文章

  1. SSM前后端分离 ssm+html+js(ajax) 这种controll层的返回值是结合或者网址

    提示: 1.单表查询多条数据用 list<实体类名字> mapper层 1.1单表查询单条数据用  对象 2.两表关联查多条 list<map<String,Object> ...

  2. SSM前后端分离/不分离对比Demo

    之前某些原因,整理了一个小的Demo,用于演示.个人认为在SSM前后端不分离的基础上在前端处理上比较麻烦一点之后就是注解的使用.总结一些对比,仅是自己掌握的,不够严谨,不足之处请大佬批评指正. 路由控 ...

  3. SSM框架中的前后端分离

    认识前后端分离 在传统的web应用开发中,大多数的程序员会将浏览器作为前后端的分界线.将浏览器中为用户进行页面展示的部分称之为前端,而将运行在服务器,为前端提供业务逻辑和数据准备的所有代码统称为后端. ...

  4. 从MVC到Ajax再到前后端分离的思考

    前言 一位小妹去面试前端,前端leader问了"什么是ajax?",答:"接收后台的数据,然后然后自己填充和渲染样式":一位小哥去面试后台,技术经理问了&quo ...

  5. REST风格框架实战:从MVC到前后端分离(附完整Demo)

    既然MVC模式这么好,难道它就没有不足的地方吗?我认为MVC至少有以下三点不足:(1)每次请求必须经过“控制器->模型->视图”这个流程,用户才能看到最终的展现的界面,这个过程似乎有些复杂 ...

  6. REST风格框架:从MVC到前后端分离***

    摘要: 本人在前辈<从MVC到前后端分离(REST-个人也认为是目前比较流行和比较好的方式)>一文的基础上,实现了一个基于Spring的符合REST风格的完整Demo,具有MVC分层结构并 ...

  7. 【转】REST风格框架实战:从MVC到前后端分离(附完整Demo)

    版权声明:欢迎转载,注明作者和出处就好!如果不喜欢或文章存在明显的谬误,请留言说明原因再踩哦,谢谢,我也可以知道原因,不断进步! https://blog.csdn.net/justloveyou_/ ...

  8. 浅谈WEB前后端分离

    重审业务逻辑 用过MVC的童鞋都知道业务逻辑(Bussiness Logic),但是大多对这概念又是模棱两可,业务逻辑从来都是这样难以理解,谈论前后端分离之前这个概念非常有必要探讨一下! 在简单的CR ...

  9. 架构设计:前后端分离之Web前端架构设计

    在前面的文章里我谈到了前后端分离的一些看法,这个看法是从宏观的角度来思考的,没有具体的落地实现,今天我将延续上篇文章的主题,从纯前端的架构设计角度谈谈前后端分离的一种具体实现方案,该方案和我原来设想有 ...

随机推荐

  1. linux运维 技能 2018

    1.监控与日志 prometheus.grafana.zabbix ELK(elasticsearch logstash filebeat kibana) 2.容器类 harbor映像管理 docke ...

  2. [BUAA软工]Alpha阶段测试报告

    测试报告 一.测试计划 1.1 功能测试 1.2 UI测试 1.3 测试中发现的bug https://github.com/bingduoduo1/backend/issues/21 https:/ ...

  3. C++ 中的 inline 用法

    1.引入 inline 关键字的原因 在 c/c++ 中,为了解决一些频繁调用的小函数大量消耗栈空间(栈内存)的问题,特别的引入了 inline 修饰符,表示为内联函数. 栈空间就是指放置程序的局部数 ...

  4. Salt Highstate数据结构定义

    作者言 这篇文档详细解释了SLS文件中,每个部分的名称与含义,以及SLS中的数据处理后的数据结构. 我只是SaltStack的初学者,如果文中有错误的地方,请不吝赐教.在学习的过程,我做了一些实验,犯 ...

  5. 【spring源码学习】spring的事务管理源码学习

    一.抽象概念 1.事务管理器 接口:org.springframework.transaction.PlatformTransactionManager 实现类:org.springframework ...

  6. Asynchronous method in while loop 构造异步调用链

    Asynchronous method in while loop https://stackoverflow.com/questions/43064719/javascript-asynchrono ...

  7. arcpy地理处理工具案例教程-景观形状指数计算

    arcpy地理处理工具案例教程-景观形状指数计算 商务合作,科技咨询,版权转让:向日葵,135-4855_4328,xiexiaokui#qq.com 使用方法:输入要素类即可,其余参数均默认. 商务 ...

  8. 如何使用phantomJS来模拟一个HTML元素的鼠标悬停

    如何使用phantomJS来模拟一个HTML元素的鼠标悬停 (How to use phantomJS to simulate mouse hover on a HTML element) 转 htt ...

  9. Ubuntu下卸载anaconda

    转载:https://blog.csdn.net/m0_37407756/article/details/77968724(一)删除整个anaconda目录: 由于Anaconda的安装文件都包含在一 ...

  10. conda进行python环境隔离

    1.环境隔离的问题 在使用python时,常常遇到的问题: pip安装库A,依赖库B-2.1版本 pip安装库C,以来库B-3.1版本,安装会提示库B的版本冲突错误. 这种情况下就需要做环境隔离 co ...