1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| int width = 90, height = 30; BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) img.getGraphics(); g.setColor(Color.GRAY); g.fillRect(0, 0, width, height); g.setColor(Color.GREEN); g.drawRect(0, 0, width - 1, height - 1); Random random = new Random(); g.setFont(new Font("黑体", Font.BOLD, 20)); int x = 20, y = 20; String data = "QWERTYUIOPASDGHJKLZXCVBNM13456789"; StringBuffer sb = new StringBuffer(); for (int i = 0; i < 4; i++) { int jiaodu = random.nextInt(60) - 30; double hudu = jiaodu * Math.PI / 180; g.rotate(hudu, x, y); int index = random.nextInt(data.length()); ch = data.charAt(index); sb.append(ch); g.drawString("" + ch, x, y); g.rotate(-hudu, x, y); x += 15; } request.getSession().setAttribute("code", sb.toString()); g.setColor(Color.PINK);
ImageIO.write(img, "jpg", response.getOutputStream()); }
@RequestMapping("list") public String list(HttpServletRequest request){ List<User> list = userService.userlist(); request.setAttribute("userlist",list); return "user"; }
@RequestMapping("detail") public String detail(Long id,HttpServletRequest request){ User user = userService.idByuser(id); request.setAttribute("userbyid",user); return "userinfo"; }
@RequestMapping("update") public String updateUser(User user){ userService.update(user); return "redirect:/user/list"; }
@RequestMapping("/delete") public String deleteUser(Long id){ userService.delete(id);
|