srpingBoot+myBatis+JPA也太简单了把,注解化开发!代码耦合度降低的大大滴!!!

刚接触新框架,今天做了修改与插入,本来想着简简单单的,就没看之前的代码,
写了mapper,写了xml,写了dao层的@注解sql
耽误了1个小时。。。。。。。。。。。。

分层级 先来实体类看看把,这里是建了视图

@Entity
@Table(
        name = "T_STOCK_NOTIFICATION",
        schema = "WHFGJ",
        catalog = ""
)
public class StockNotification {
    @Id
    @GeneratedValue(
            strategy = GenerationType.SEQUENCE,
            generator = "notification_SEQ"
    )
    @SequenceGenerator(
            sequenceName = "notification_SEQ",
            initialValue = 1,
            allocationSize = 1,
            name = "notification_SEQ"
    )
    @Column(
            name = "MSG_ID"
    )
    private Long msgId;
    }

dao层就干干蛋蛋的继承

public interface StockSuperviseDao extends IBaseDao<StockSupervise, Long> {



}

service的话也是千篇一律

@Service
public class StockSuperviseService extends BaseService<StockSupervise, Long, StockSuperviseDao> {

   @Autowired
    private  StockSuperviseDao stockSuperviseDao;
   @Autowired
    private ClfJglsService clfJglsService;

    @Autowired
    private  StockNotificationService stockNotificationService;
    private static final Logger logger = LoggerFactory.getLogger(StockSuperviseService.class);

    public StockSuperviseService() {
    }
 //查询单个信息
     public StockSupervise QueryStockSupervise(String  id){
      return  this.stockSuperviseDao.findOne(Long.valueOf(id));
    }


 //保存or修改的话,如果是本service,直接this.save(实体类)就ok。
 

//注入的service我把业务逻辑删除掉了,这样的save保存、修改都用这个方法都ok。
```javascript
    @Transactional("transactionManager")
    public void insertTaskInfo(StockNotificationstockNotification) throws 
                this.stockNotificationService.save(stockNotification);

    }
//本service
    @Transactional("transactionManager")
    public void insertClfJg(StockSupervise  stockSupervise) throws IOException {
  
                this.save(stockSupervise );
     }

//删除也是什么都不用,直接点方法就行就行

       this.stockSuperviseService.delete(Long id);
       this.stockSuperviseService.deleteBatch(Long[] ids);
//带参数查询List
//查询map参数
  Map<String, String> searchParams = new HashMap(16);
        searchParams.put("userId", "eq");
//以表内concludeTime字段desc排序
//这个对于其她来说有点麻烦
//需要封装多个查询框的参数
        Page<StockSupervise> stockSuperviseList = this.stockSuperviseService.findAll(stockSupervise, searchParams, page, size, Direction.DESC, new String[]{"concludeTime"});

随便写了写

    public Page<StockSupervise> findAll(final StockSupervise stockSupervise, Pageable pageable) {
        Specification<StockSupervise> specification = new Specification<StockSupervise>() {
            @Override
            public Predicate toPredicate(Root<StockSupervise> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> list = new ArrayList();
                Predicate trustAccountno = null;
                if (StringUtils.isNotBlank(stockSupervise.getTrustAccountno())) {
                    trustAccountno = cb.like(root.get("trustAccountno"), "%" + stockSupervise.getTrustAccountno() + "%");
                    list.add(trustAccountno);
                }

                Predicate buyAcountno = null;
                if (stockSupervise.getBuyAcountno() != null) {
                    buyAcountno = cb.like(root.get("buyAcountno"), "%" + stockSupervise.getBuyAcountno() + "%");
                    list.add(buyAcountno);
                }

                Predicate saleAccountno = null;
                if (stockSupervise.getSaleAccountno() != null) {
                    saleAccountno = cb.like(root.get("saleAccountno"), "%" + stockSupervise.getSaleAccountno() + "%");
                    list.add(saleAccountno);
                }

                Predicate stockId = null;
                if (stockSupervise.getStockId() != null) {
                    stockId = cb.equal(root.get("stockId"), stockSupervise.getStockId());
                    list.add(stockId);
                }

                Predicate htbh = null;
                if (stockSupervise.getHtbh() != null) {
                    htbh = cb.equal(root.get("htbh"), stockSupervise.getHtbh());
                    list.add(htbh);
                }

                Predicate[] arrayPredicates = new Predicate[list.size()];
                return cb.and((Predicate[])list.toArray(arrayPredicates));
            }
        };
        Page<StockSupervise> accountPage = this.stockSuperviseDao.findAll(specification, pageable);
        return accountPage;
    }
 反正是我还有点懵,底层方法一点不清楚啊!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

boJIke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值