刚接触新框架,今天做了修改与插入,本来想着简简单单的,就没看之前的代码,
写了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;
}
反正是我还有点懵,底层方法一点不清楚啊!!