1.先创建实体类:

2.创建mapper层

package cn.kgc.mapper;

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; import java.util.List; /**
* 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接口层:
package cn.kgc.service;

import cn.kgc.Account;

import java.util.List;

/**
* 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实现类
package cn.kgc.service;

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; import java.util.List; /**
* 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();
} @Override
public Account findByData(Integer id) {
return accountMapper.selectByid(id);
} @Override
public Integer add(Account account) {
return accountMapper.insertAccount(account);
} @Override
public Integer edit(Account account) {
return accountMapper.updateAccount(account);
} @Override
public Integer del(Integer id) {
return accountMapper.deleteAccount(id);
}
}
4.controller层
package cn.kgc.controller;

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; import java.util.List; /**
* Created by 86182 on 2019/7/1.
*/
@RestController
public class AccountController {
@Autowired
private AccountService accountService; //查询全部
@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页面

$(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. FEE Development Essentials
  2. JS实现简单倒计时
  3. redis client protocol 分解
  4. JQuery学习笔记——层级选择器
  5. Java中数组的扩容
  6. PCMM(人力资源能力成熟度模型)V2.0中英对照版发布
  7. 手把手教你写vue插件并发布(二)
  8. Qt QTextEdit根据行号移动光标
  9. (17)什么是jQuery(jq的流程和基本操作)
  10. 使用jQuery实现一个类似GridView的编辑,更新,取消和删除的功能
  11. Prism框架的优点
  12. win8.1简单快速安装phpnow的方法
  13. qt 数据库操作总结
  14. storm集群安装
  15. [HDU1205]吃糖果 题解(鸽巢原理)
  16. 最大公约数(gcd)和 最小公倍数(lcm)——辗转相除法
  17. 创建jq插件步骤
  18. 制定clone的用户名
  19. windows下用时间戳创建文件名
  20. 【对询问分块】【主席树】bzoj2683 简单题

热门文章

  1. nginx之allow、deny
  2. eclipse debug调试 class文件 Source not found.
  3. [原创]敏捷管理实践Scrum思维导图
  4. linux运维 技能 2018
  5. BootStrap-select组件
  6. linux 下查看redis是否启动
  7. .Net Core NOPI操作word(二) 表格操作
  8. 【C++】C++中的容器解析
  9. eggjs异常捕获机制
  10. 如何使用phantomJS来模拟一个HTML元素的鼠标悬停