Search in sources :

Example 1 with User

use of com.github.lybgeek.mongodb.model.User in project springboot-learning by lyb-geek.

the class ModelMapperConfig method modelMapper.

@Bean
public ModelMapper modelMapper() {
    ModelMapper modelMapper = new ModelMapper();
    PropertyMap<User, UserDTO> propertyUser2UserDTOMap = new PropertyMap<User, UserDTO>() {

        @Override
        protected void configure() {
            skip(source.getGender(), destination.getGender());
        }
    };
    modelMapper.addMappings(propertyUser2UserDTOMap);
    return modelMapper;
}
Also used : User(com.github.lybgeek.mongodb.model.User) PropertyMap(org.modelmapper.PropertyMap) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO) ModelMapper(org.modelmapper.ModelMapper) Bean(org.springframework.context.annotation.Bean)

Example 2 with User

use of com.github.lybgeek.mongodb.model.User in project springboot-learning by lyb-geek.

the class MongodbApplicationTest method testList.

@Test
public void testList() {
    Address address = Address.builder().detailAddr("test1").build();
    User user = User.builder().userName("张三1").email("zhangsan1@qq.com").password("1234561").gender(Gender.MALE).address(address).build();
    List<User> users = userDao.listUsers(user);
    System.out.println(users);
}
Also used : User(com.github.lybgeek.mongodb.model.User) Address(com.github.lybgeek.mongodb.model.Address) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with User

use of com.github.lybgeek.mongodb.model.User in project springboot-learning by lyb-geek.

the class UserServiceImpl method listUsers.

@Override
public List<User> listUsers(UserDTO userDTO) {
    User dbUser = getUser(userDTO);
    List<User> users = userDao.listUsers(dbUser);
    return users;
}
Also used : User(com.github.lybgeek.mongodb.model.User)

Example 4 with User

use of com.github.lybgeek.mongodb.model.User in project springboot-learning by lyb-geek.

the class UserServiceImpl method pageUsers.

@Override
public PageResult<User> pageUsers(PageQuery<UserDTO> pageQuery) {
    UserDTO userDTO = pageQuery.getQueryParams();
    User dbUser = getUser(userDTO);
    PageQuery<User> dbPageQuery = new PageQuery<>();
    dbPageQuery.setQueryParams(dbUser);
    dbPageQuery.setPageSize(pageQuery.getPageSize() == null ? 10 : pageQuery.getPageSize());
    dbPageQuery.setPageNum(pageQuery.getPageNum() == null ? 1 : pageQuery.getPageNum());
    PageResult<User> pageResult = userDao.pageUsers(dbPageQuery);
    return pageResult;
}
Also used : User(com.github.lybgeek.mongodb.model.User) PageQuery(com.github.lybgeek.mongodb.common.page.PageQuery) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO)

Example 5 with User

use of com.github.lybgeek.mongodb.model.User in project springboot-learning by lyb-geek.

the class UserServiceImpl method saveUser.

@Override
@Transactional
public UserDTO saveUser(UserDTO userDTO) {
    User user = getUser(userDTO);
    User dbUser = userDao.saveUser(user);
    if (ValidateTransaction.YES.getValue().equals(userDTO.getValidateRollBack())) {
        throw new RuntimeException("验证事务回滚");
    }
    UserDTO dbUserDTO = modelMapper.map(dbUser, UserDTO.class);
    dbUserDTO.setGender(dbUser.getGender().getValue());
    return dbUserDTO;
}
Also used : User(com.github.lybgeek.mongodb.model.User) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.github.lybgeek.mongodb.model.User)5 UserDTO (com.github.lybgeek.mongodb.dto.UserDTO)3 PageQuery (com.github.lybgeek.mongodb.common.page.PageQuery)1 Address (com.github.lybgeek.mongodb.model.Address)1 Test (org.junit.Test)1 ModelMapper (org.modelmapper.ModelMapper)1 PropertyMap (org.modelmapper.PropertyMap)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Bean (org.springframework.context.annotation.Bean)1 Transactional (org.springframework.transaction.annotation.Transactional)1