JavaWeb程序 从前端到数据库,操作流程(html controller service mapper DB)
目录
传递流程图
代码讲解
entity实体类
因为都有id字段
所以单独一个BaseEntity类
其他entity都有主键,所以直接继承就可以,
BaseEntity:
/**
* 主键类
* @Author: yibox
*/
@Data
public class BaseEntity {
private long id;
}
这篇博客用到的
PageView 实体类
/**
* t_page_view实体类
* @Author: yibox
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class PageView extends BaseEntity {
private Integer pageView;
private LocalDateTime createTime;
}
html代码
- url:对应controller
@ResponseBody
@PostMapping("/getPageView/{type}") - type:对应Post请求
@PostMapping - dataType:“json”,对应返回值类型
<script>
$(function () {
$.ajax({
url:"/admin/getPageView/month",
type:"post",
dataType:"json",
success:function(data){
console.log(data);
}
});
});
</script>