8月13日 分布式缓存 周一

package com.mongo.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import com.mongo.dto.Type;
import com.mongo.dto.User;
import com.mongo.util.PageUtils;

@Component
public class UserDao {

    @Autowired
    private MongoTemplate mongo;

    public List findUserList(PageUtils pu) {
        return mongo.find(new Query().skip(pu.getStartIndex()).limit(pu.getTotalPage()), User.class);//实现查询功能
    }

    public List findTypeList() {
        return mongo.find(new Query(), Type.class);//实现查询功能
    }

    public void add(User user) {
        mongo.insert(user);
    }

    public User getUser(User user) {
        return mongo.findOne(new Query(Criteria.where("id").is(user.getId())), User.class);
    }

    public void upd(User user) {
        Update update = new Update();
        update.set("name1", user.getName1());
        update.set("name2", user.getName2());
        update.set("type", user.getType());
        update.set("time", user.getTime());
        update.set("price", user.getPrice());
        mongo.updateFirst(new Query(Criteria.where("id").is(user.getId())), update, User.class);
    }

    public void del(User user) {
        mongo.remove(new Query(Criteria.where("id").is(user.getId())),User.class);
    }

    public Integer getCount() {
        Integer count = (int) mongo.count(new Query(), User.class);
        System.out.println(count);
        return count;
    }
}

说一句对不起不如做一百件对得起的事。

——孙权《终极三国》

你可能感兴趣的:(2018)