SSM 前后端分离 这里controll层的返回值和之前那个不一样
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")
}
});
}
SSM 前后端分离 这里controll层的返回值和之前那个不一样的更多相关文章
- SSM前后端分离 ssm+html+js(ajax) 这种controll层的返回值是结合或者网址
提示: 1.单表查询多条数据用 list<实体类名字> mapper层 1.1单表查询单条数据用 对象 2.两表关联查多条 list<map<String,Object> ...
- SSM前后端分离/不分离对比Demo
之前某些原因,整理了一个小的Demo,用于演示.个人认为在SSM前后端不分离的基础上在前端处理上比较麻烦一点之后就是注解的使用.总结一些对比,仅是自己掌握的,不够严谨,不足之处请大佬批评指正. 路由控 ...
- SSM框架中的前后端分离
认识前后端分离 在传统的web应用开发中,大多数的程序员会将浏览器作为前后端的分界线.将浏览器中为用户进行页面展示的部分称之为前端,而将运行在服务器,为前端提供业务逻辑和数据准备的所有代码统称为后端. ...
- 从MVC到Ajax再到前后端分离的思考
前言 一位小妹去面试前端,前端leader问了"什么是ajax?",答:"接收后台的数据,然后然后自己填充和渲染样式":一位小哥去面试后台,技术经理问了&quo ...
- REST风格框架实战:从MVC到前后端分离(附完整Demo)
既然MVC模式这么好,难道它就没有不足的地方吗?我认为MVC至少有以下三点不足:(1)每次请求必须经过“控制器->模型->视图”这个流程,用户才能看到最终的展现的界面,这个过程似乎有些复杂 ...
- REST风格框架:从MVC到前后端分离***
摘要: 本人在前辈<从MVC到前后端分离(REST-个人也认为是目前比较流行和比较好的方式)>一文的基础上,实现了一个基于Spring的符合REST风格的完整Demo,具有MVC分层结构并 ...
- 【转】REST风格框架实战:从MVC到前后端分离(附完整Demo)
版权声明:欢迎转载,注明作者和出处就好!如果不喜欢或文章存在明显的谬误,请留言说明原因再踩哦,谢谢,我也可以知道原因,不断进步! https://blog.csdn.net/justloveyou_/ ...
- 浅谈WEB前后端分离
重审业务逻辑 用过MVC的童鞋都知道业务逻辑(Bussiness Logic),但是大多对这概念又是模棱两可,业务逻辑从来都是这样难以理解,谈论前后端分离之前这个概念非常有必要探讨一下! 在简单的CR ...
- 架构设计:前后端分离之Web前端架构设计
在前面的文章里我谈到了前后端分离的一些看法,这个看法是从宏观的角度来思考的,没有具体的落地实现,今天我将延续上篇文章的主题,从纯前端的架构设计角度谈谈前后端分离的一种具体实现方案,该方案和我原来设想有 ...
随机推荐
- <每日 1 OJ> -LeetCode 13 . 罗马数字转正数
题目: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做 II ,即为两个并列的 1 ...
- 大龄IT程序员的救赎之道
不知道从什么时候开始,中年危机持续刷屏,遍布整个职场,横跨各个行业,对各个细分工种的中年男女或者即将步入中年的青年男女几乎形成了垂直打击,而且中年这个年龄分界线从40岁滑落到35岁,甚至到30岁.笔者 ...
- JVM探究之 —— 垃圾回收(二)
1. 垃圾收集算法 1.1 标记清除(Mark-Sweep)算法 标记—清除算法是第一种使用和比较完善的垃圾回收算法,后续的收集算法都是基于其设计思路并对其不足进行改进而得到的. 该算法分为“标记”和 ...
- 【java编程】vo、po、dto、bo、pojo、entity、mode如何区分
Java Bean:一种可重用组件,即“一次编写,任何地方执行,任何地方重用”.满足三个条件 类必须是具体的和公共的 具有无参构造器 提供一致性设计模式的公共方法将内部域或暴露成员属性 VO valu ...
- IDEA 如何导出 todo 列表
众所周知,IDEA 可以直接查看所有的 todo 列表, 快捷键是 Alt + 6 然后右键文件夹,选择[Expand All],展开所有目录 再然后,先选中最上边的文件,单击, 再选中最后一个文件, ...
- HTTPS原理分析
引言 随着互联网安全意识的普遍提高,对安全要求稍高的应用中,HTTPS的使用是很常见的,所以,无论是即时通讯IM还是其它应用,在网络安全意识增强的今天,很多场景下使用HTTPS是肯定没错的.对于即时通 ...
- 011 webpack中使用vue
一:在webpack中使用vue 1.安装vue的包 2.index.html <!DOCTYPE html> <html lang="en"> <h ...
- 【Node.js】Node.js的调试
目录结构: contents structure [-] 使用console.log() 使用Chrome DevTools 使用Visual Studio Code 与JavaScript运行在浏览 ...
- jeecg数据库切换至mysql8.0方式
1.修改pom.xml mysql版本 <mysql.version>8.0.11</mysql.version> 2.修改dbconfig.properties文件 hi ...
- Oracle系列十四 序列、索引和同义词
序列 : 提供有规律的数值.索引 : 提高查询的效率同义词 :给对象起别名 序列: 可供多个用户用来产生唯一数值的数据库对象 自动提供唯一的数值 共享对象 主要用于提供主键值 将序列值装入内存可以 ...