zoukankan      html  css  js  c++  java
  • Springboot简单练手的记账本

    Springboot简单练手的记账本

    昨天看雷哥的教程写了个简单的记账本练练手,没有把笔记整理下来放在博客上,今天补上。言归正传,进入正题。

    老规矩,我们还是先看看项目的目录结构,以及登陆界面

    每个包都是什么含义这里就不再细说了1
    登陆界面:
    2

    一、准备工作

    创建数据库
    3

    二、生成代码

    添加对应的pom依赖,修改yml文件,以及对应的vo(domain),mapper,service,controller,还有mapper映射文件)

    三、导入资源文件

    4

    四、完成登录

    1. 创建ResultObj
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class ResultObj {
    
        //业务响应码
        private int code;
        //业务消息
        private String msg;
    }
    
    1. 创建LoginController(代码太多,这里不再详细给出)
    @Controller
    @RequestMapping("/login")
    public class LoginController {
    
        @Autowired
        private UserService userService;
    
        /**
         * 跳转到登陆页面
         */
        @RequestMapping("toLogin")
        public String toLogin() {
            return "login";
        }
    
    1. 创建static/index.html(代码太多,这里不再详细给出)
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    	<script type="text/javascript">
    		window.location.href="/login/toLogin"
    	</script>
    </body>
    </html>
    
    1. 创建templates/login.html
    2. 创建templates/list.html
      (上述两条代码过长,不再赘述,到时候会一并上传的,有迫切需要的可以联系我)

    五、账单列表(这里代码就不再给出了,过于冗余,之后会上传代码的)

    1. 创建DataGridView
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class DataGridView {
    
        private Long code=0L;
        private String msg="";
        private Long count;
        private Object data;
        public DataGridView(Long count,Object data){
            super();
            this.count=count;
            this.data=data;
        }
    }
    
    1. 创建MyBatisPlusConfig
    /**
     *mybatisplus的配置类(分页)
     */
    @Configuration
    @ConditionalOnClass(value = {PaginationInterceptor.class})
    public class MybatisPlusConfig {
    
        @Bean
        public PaginationInterceptor paginationInterceptor(){
            return new PaginationInterceptor();
        }
    }
    
    
    1. 创建BillsController
    @Controller
    @RequestMapping("/bills")
    public class BillsController {
    
        @Autowired
        private BillsService billsService;
    
        @Autowired
        private BilltypeService billtypeService;
    
        /**
         * 跳转到系统主页
         */
        @RequestMapping("toBillsList")
        public String toBillsList(){
            return "list";
        }
    
        /**
         *加载账单数据
         */
        @RequestMapping("loadAllBills")
        @ResponseBody
        public DataGridView loadAllBills(BillsVo billsVo){
            //这里使用分页插件
            IPage<Bills> page=new Page<>(billsVo.getPage(),billsVo.getLimit());
            QueryWrapper<Bills> queryWrapper=new QueryWrapper<>();
            //等于
            queryWrapper.eq(null!=billsVo.getTypeid()&&billsVo.getTypeid()!=0,"typeid",billsVo.getTypeid());
            //大于
            queryWrapper.ge(billsVo.getStartDate()!=null,"billtime",billsVo.getStartDate());
            //小于
            queryWrapper.le(billsVo.getEndDate()!=null,"billtime",billsVo.getEndDate());
            //排序
            queryWrapper.orderByDesc("billtime");
            billsService.page(page,queryWrapper);
    
            List<Bills> records=page.getRecords();
            for (Bills bills:records){
                Billtype billtype=this.billtypeService.getById(bills.getTypeid());
                bills.setTypeName(billtype.getName());
            }
            return new DataGridView(page.getTotal(),records);
        }
    
        /**
         * 添加账单
         */
        @RequestMapping("addBills")
        @ResponseBody
        public ResultObj addBills(BillsVo billsVo){
            try {
                this.billsService.save(billsVo);
                return new ResultObj(200, "录入成功");
            } catch (Exception e) {
                e.printStackTrace();
                return new ResultObj(-1, "录入失败");
            }
        }
    }
    
    
    1. 创建Bills
    2. 创建BillsVo
    3. 创建BillsTypeServiceImpl
    4. 创建缓存处理切面类
    5. 加入依赖
    6. 创建BillTypeController
    7. 创建list.html

    六、添加账单

    1. 修改list.html
    2. 修改BillsController
    七、这篇文章说到这里,关于Mapper(即dao层),service,serviceImpl,以及xxxMapper.xml文件,这里并没有提到,不是没有,只是这里是通过mybatis-plus,使用接口进行操作的,省去了自己写代码的那一步,本篇就不再介绍了,之后会专门写一篇进行记录的。

    八、看看效果:

    6
    添加记录:
    7

    九、 大致就是这么多,对了该项目使用的是mybatis-plus,还有huTool工具包,很多地方都是使用的接口,不用自己去写代码,之后,会写一篇有关mybatis-plus和huTool工具包的博客,希望大家可以留意一下!谢谢!

    天涯志

  • 相关阅读:
    第一讲 jQuery入门
    Log4j日志记录
    第四讲 Hibernate 缓存管理
    第一讲 Hibernate 简介
    第三讲 Spring 持久层封装、事务控制
    对 PInvoke 函数的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标
    善用 C# 3.0 Extensions 方法
    .net 下如何将文档文件(Word, Pdf等) 中的文本提取出来(转)
    vs2010常用快捷键 (转)
    Silverlight 视频学习札记(一)
  • 原文地址:https://www.cnblogs.com/cainiaoxiaoxie/p/12807172.html
Copyright © 2011-2022 走看看