Java Code Examples for cn.hutool.core.util.IdUtil#fastSimpleUUID()

The following examples show how to use cn.hutool.core.util.IdUtil#fastSimpleUUID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginController.java    From Shiro-Action with MIT License 6 votes vote down vote up
@PostMapping("/register")
@ResponseBody
public ResultBean register(User user) {
    userService.checkUserNameExistOnCreate(user.getUsername());
    String activeCode = IdUtil.fastSimpleUUID();
    user.setActiveCode(activeCode);
    user.setStatus("0");

    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    String url = request.getScheme() + "://"
            + request.getServerName()
            + ":"
            + request.getServerPort()
            + "/active/"
            + activeCode;
    Context context = new Context();
    context.setVariable("url", url);
    String mailContent = templateEngine.process("mail/registerTemplate", context);
    new Thread(() ->
            mailService.sendHTMLMail(user.getEmail(), "Shiro-Action 激活邮件", mailContent))
            .start();

    // 注册后默认的角色, 根据自己数据库的角色表 ID 设置
    Integer[] initRoleIds = {2};
    return ResultBean.success(userService.add(user, initRoleIds));
}
 
Example 2
Source File: FileUtil.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 导出excel
 */
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
    String tempPath =System.getProperty("java.io.tmpdir") + IdUtil.fastSimpleUUID() + ".xlsx";
    File file = new File(tempPath);
    BigExcelWriter writer= ExcelUtil.getBigWriter(file);
    // 一次性写出内容,使用默认样式,强制输出标题
    writer.write(list, true);
    //response为HttpServletResponse对象
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
    //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
    response.setHeader("Content-Disposition","attachment;filename=file.xlsx");
    ServletOutputStream out=response.getOutputStream();
    // 终止后删除临时文件
    file.deleteOnExit();
    writer.flush(out, true);
    //此处记得关闭输出Servlet流
    IoUtil.close(out);
}
 
Example 3
Source File: FileUtils.java    From sk-admin with Apache License 2.0 6 votes vote down vote up
/**
 * 导出excel
 */
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
    String tempPath =System.getProperty("java.io.tmpdir") + IdUtil.fastSimpleUUID() + ".xlsx";
    File file = new File(tempPath);
    BigExcelWriter writer= ExcelUtil.getBigWriter(file);
    // 一次性写出内容,使用默认样式,强制输出标题
    writer.write(list, true);
    //response为HttpServletResponse对象
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
    //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
    response.setHeader("Content-Disposition","attachment;filename=file.xlsx");
    ServletOutputStream out=response.getOutputStream();
    // 终止后删除临时文件
    file.deleteOnExit();
    writer.flush(out, true);
    //此处记得关闭输出Servlet流
    IoUtil.close(out);
}
 
Example 4
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUserList() {
    List<User> users = Lists.newArrayList();
    for (int i = 5; i < 15; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
        users.add(user);
    }
    userService.saveUserList(users);
    Assert.assertTrue(userService.getUserList().size() > 2);
}
 
Example 5
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    userDao.save(testSave3);

    Assert.assertNotNull(testSave3.getId());
    Optional<User> byId = userDao.findById(testSave3.getId());
    Assert.assertTrue(byId.isPresent());
    log.debug("【byId】= {}", byId.get());
}
 
Example 6
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();

    user = userService.saveUser(user);
    Assert.assertTrue(ObjectUtil.isNotNull(user.getId()));
    log.debug("【user】= {}", user);
}
 
Example 7
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 批量新增
 */
@Test
public void testSaveList() {
    List<User> userList = Lists.newArrayList();
    for (int i = 4; i < 14; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    boolean batch = userService.saveBatch(userList);
    Assert.assertTrue(batch);
    List<Long> ids = userList.stream().map(User::getId).collect(Collectors.toList());
    log.debug("【userList#ids】= {}", ids);
}
 
Example 8
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试通用Mapper - 保存
 */
@Test
public void testInsert() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    userMapper.insertUseGeneratedKeys(testSave3);
    Assert.assertNotNull(testSave3.getId());
    log.debug("【测试主键回写#testSave3.getId()】= {}", testSave3.getId());
}
 
Example 9
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    int i = userMapper.saveUser(user);
    Assert.assertEquals(1, i);
}
 
Example 10
Source File: UserMapperTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试通用Mapper - 保存
 */
@Test
public void testInsert() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
    userMapper.insertUseGeneratedKeys(testSave3);
    Assert.assertNotNull(testSave3.getId());
    log.debug("【测试主键回写#testSave3.getId()】= {}", testSave3.getId());
}
 
Example 11
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUserList() {
    List<User> users = Lists.newArrayList();
    for (int i = 5; i < 15; i++) {
        String salt = IdUtil.fastSimpleUUID();
        User user = User.builder().name("testSave" + i).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + i + "@xkcoding.com").phoneNumber("1730000000" + i).status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
        users.add(user);
    }
    userService.saveUserList(users);
    Assert.assertTrue(userService.getUserList().size() > 2);
}
 
Example 12
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 新增
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    boolean save = userService.save(testSave3);
    Assert.assertTrue(save);
    log.debug("【测试id回显#testSave3.getId()】= {}", testSave3.getId());
}
 
Example 13
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 初始化10条数据
 */
private void initData() {
    List<User> userList = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        String salt = IdUtil.fastSimpleUUID();
        int index = 3 + i;
        User user = User.builder().name("testSave" + index).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + index + "@xkcoding.com").phoneNumber("1730000000" + index).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    userDao.saveAll(userList);
}
 
Example 14
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试保存
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    userDao.save(testSave3);

    Assert.assertNotNull(testSave3.getId());
    Optional<User> byId = userDao.findById(testSave3.getId());
    Assert.assertTrue(byId.isPresent());
    log.debug("【byId】= {}", byId.get());
}
 
Example 15
Source File: UserDaoTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 初始化10条数据
 */
private void initData() {
    List<User> userList = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        String salt = IdUtil.fastSimpleUUID();
        int index = 3 + i;
        User user = User.builder().name("testSave" + index).password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave" + index + "@xkcoding.com").phoneNumber("1730000000" + index).status(1).lastLoginTime(new DateTime()).build();
        userList.add(user);
    }
    userDao.saveAll(userList);
}
 
Example 16
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试Mybatis-Plus 新增
 */
@Test
public void testSave() {
    String salt = IdUtil.fastSimpleUUID();
    User testSave3 = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).build();
    boolean save = userService.save(testSave3);
    Assert.assertTrue(save);
    log.debug("【测试id回显#testSave3.getId()】= {}", testSave3.getId());
}
 
Example 17
Source File: UserServiceTest.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void saveUser() {
    String salt = IdUtil.fastSimpleUUID();
    User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("[email protected]").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();

    user = userService.saveUser(user);
    Assert.assertTrue(ObjectUtil.isNotNull(user.getId()));
    log.debug("【user】= {}", user);
}
 
Example 18
Source File: TraceFilter.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object run() {
    //链路追踪id
    String traceId = IdUtil.fastSimpleUUID();
    MDC.put(CommonConstant.LOG_TRACE_ID, traceId);
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.addZuulRequestHeader(CommonConstant.TRACE_ID_HEADER, traceId);
    return null;
}
 
Example 19
Source File: ContiPerTest.java    From Jpom with MIT License 4 votes vote down vote up
@PerfTest(invocations = 200000000, threads = 16)
public void test1() throws Exception {
    IdUtil.fastSimpleUUID();
}
 
Example 20
Source File: UUIDBenchmark.java    From mica-jmh with MIT License 4 votes vote down vote up
@Benchmark
public String hutoolFastSimpleUUID() {
	return IdUtil.fastSimpleUUID();
}