package com.doit.dagama.web;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HomeController {
@Autowired
private HomeService homeService;
@Autowired
private HttpServletRequest request;
public HomeService getHomeService() {
return homeService;
}
public void setHomeService(HomeService homeService) {
this.homeService = homeService;
}
@RequestMapping(value = "/{Id}", method = GET)
@Log(name = "You visisted a home infomation")
public @ResponseBody Object HomeUser(@PathVariable Long Id, Model model) {
return homeService.getHomeById(Id);
}
@RequestMapping(value = "/", method = GET)
public String Home(Model model) {
// model.addAttribute("home", homeService.getHomeById(Id));
return "index";
}
@RequestMapping(value = "/calendar", method = GET)
public String Calendar() {
return "calendar";
}
@RequestMapping(value = "/widgets", method = GET)
public String Widgets() {
return "widgets";
}
@RequestMapping(value = "/json",method = RequestMethod.GET)
public @ResponseBody Object testJson() {
List<Home> homeList = new ArrayList<Home>();
Home home = new Home();
home.setTitle("DaGama 1");
home.setTheme("蓝色 ");
home.setCount(100);
System.out.println(home.toString());
homeList.add(home);
Home home1 = new Home();
home1.setTitle("DaGama 2");
home1.setTheme("绿色 ");
home1.setCount(200);
System.out.println(home1.toString());
homeList.add(home1);
Home home2 = new Home();
home2.setTitle("DaGama 3");
home2.setTheme("红色 ");
home2.setCount(300);
System.out.println(home2.toString());
homeList.add(home2);
return homeList;
}
// Create Captcha Image
private void CaptchaManager() throws IOException, InterruptedException {
for (int i = 0; i < 10; i++) {
Object[] obj = CaptchaMaker.getCaptchaImage(150, 50, 35, 50, 500,
true, true, ComplexLevel.MEDIUM);
String strPath = request.getServletContext().getRealPath("");
System.out.println("验证码" + obj[1]);
new File(strPath + "/img/Captchas").mkdir();
ImageIO.write((BufferedImage) obj[0], "jpg", new File(strPath
+ "/img/Captchas/" + System.currentTimeMillis() + ".jpg"));
Thread.sleep(500L);
}
}
}