自定义注解结合Aop数据字典应用

本篇博客主要聊聊自定义注解在项目中的应用,自定义注解用来做系统监控日志,这个用法已经烂大街了,无法让面试官眼前一亮的感觉。项目开发中数据字典使用场景非常多,使用数据字典有一点非常的不方便,那就是数据库中存放的是数字,而实际页面上展示的却是汉字;那么这也就造成了,每次做页面展示的时候都需要给数字进行转义,将其转义成汉字内容展示到页面,而转换的过程过于繁琐;咱们的自定义注解可以完美的解决这一问...
摘要由CSDN通过智能技术生成
本篇博客主要聊聊自定义注解在项目中的应用,自定义注解用来做系统监控日志,这个用法已经烂大街了,无法让面试官眼前一亮的感觉。

项目开发中数据字典使用场景非常多,使用数据字典有一点非常的不方便,那就是数据库中存放的是数字,而实际页面上展示的却是汉字;那么这也就造成了,每次做页面展示的时候都需要给数字进行转义,将其转义成汉字内容展示到页面,而转换的过程过于繁琐;

咱们的自定义注解可以完美的解决这一问题;

浏览器输入:http://localhost:8080/student/listPager 测试

最后浏览器访问的效果图

在这里插入图片描述
在这里插入图片描述
当然,也可以不走默认规则,xxx就是在类属性上的自定义注解的属性值
在这里插入图片描述
相关的pom依赖

 <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.4</version>
</dependency>

逆向工程生成实体类、mapper.xml、mapper.java

实体类

package com.zhou.model;

public class DataDict {
   
    private Integer id;

    private String datasource;

    private String description;

    public DataDict(Integer id, String datasource, String description) {
   
        this.id = id;
        this.datasource = datasource;
        this.description = description;
    }

    public DataDict() {
   
        super();
    }

    public Integer getId() {
   
        return id;
    }

    public void setId(Integer id) {
   
        this.id = id;
    }

    public String getDatasource() {
   
        return datasource;
    }

    public void setDatasource(String datasource) {
   
        this.datasource = datasource;
    }

    public String getDescription() {
   
        return description;
    }

    public void setDescription(String description) {
   
        this.description = description;
    }
}
package com.zhou.model;

public class DataItem {
   
    private Integer id;

    private String datasource;

    private String code;

    private String val;

    public DataItem(Integer id, String datasource, String code, String val) {
   
        this.id = id;
        this.datasource = datasource;
        this.code = code;
        this.val = val;
    }

    public DataItem() {
   
        super();
    }

    public Integer getId() {
   
        return id;
    }

    public void setId(Integer id) {
   
        this.id = id;
    }

    public String getDatasource() {
   
        return datasource;
    }

    public void setDatasource(String datasource) {
   
        this.datasource = datasource;
    }

    public String getCode() {
   
        return code;
    }

    public void setCode(String code) {
   
        this.code = code;
    }

    public String getVal() {
   
        return val;
    }

    public void setVal(String val) {
   
        this.val = val;
    }
}
package com.zhou.model;

import com.zhou.annotation.Dict;

public class Student {
   
    private Integer id;

    private String name;

    @Dict(dicDataSource = "stu_Level")
    private Integer stulevel;

    @Dict(dicDataSource = "stu_English",dicText = "xxx")
    private Integer englishlevel;

    @Dict(dicDataSource = "stu_hobby")
    private String stuhobby;

    public Student(Integer id, String name, Integer stulevel, Integer englishlevel, String stuhobby) {
   
        this.id = id;
        this.name = name;
        this.stulevel = stulevel;
        this.englishlevel = englishlevel;
        this.stuhobby = stuhobby;
    }

    public Student() {
   
        super();
    }

    public Integer getId() {
   
        return id;
    }

    public void setId(Integer id) {
   
        this.id = id;
    }

    public String getName() {
   
        return name;
    }

    public 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值