package web;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.A;
import model.AOV;
import model.Grid;
import model.JsonMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import util.FileSystem;
import util.MySecurityManager;
@Controller
@RequestMapping("/a")
public class AController {
private static transient final Logger log = LoggerFactory.getLogger(AController.class);
@RequestMapping(value = "b")
@ResponseBody
public Object findMbr(HttpServletRequest request) {
JsonMessage jm = new JsonMessage();
AOV aov = new AOV("这个事名字");
jm.setCode("333");
jm.setData(aov);
jm.setMessage("message");
jm.setSuccess("successs");
return jm;
}
@RequestMapping(value = "server")
@ResponseBody
public Object bb() {
Grid<A> grid = new Grid<A>();
A a = new A();
a.setId("222");
a.setAmount("aaaa");
a.setInvdate("iiii");
a.setName("name");
a.setNote("note");
a.setTax("tax");
a.setTotal("total");
List<A> list = new ArrayList<A>();
list.add(a);
for (int i = 0; i < 30; i++) {
list.add(a.clone());
}
grid.setId("2");
grid.setRows(list);
grid.setPage("1");
grid.setRecords("55555555");
grid.setTotal("4");
return grid;
}
@RequestMapping(value = "login")
public ModelAndView login(String username, String password) {
ModelAndView mav = new ModelAndView("index");
boolean loginResult = MySecurityManager.login(username, password);
if (!loginResult) {
log.debug("登陆失败");
mav.setView(new RedirectView("unauthorized"));
}
return mav;
}
@RequestMapping(value = "unauthorized")
public ModelAndView unauthorized() {
ModelAndView mav = new ModelAndView("unauthorized");
return mav;
}
@RequestMapping(value = "index")
public ModelAndView index() {
ModelAndView mav = new ModelAndView("index");
return mav;
}
@RequestMapping(value = "xxx")
public ModelAndView xxx() {
ModelAndView mav = new ModelAndView("xxx");
return mav;
}
@RequestMapping(value = "yyy")
public ModelAndView yyy() {
ModelAndView mav = new ModelAndView("yyy");
return mav;
}
@RequestMapping(value = "upload")
public void upload(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile thumbnail = multipartRequest.getFile("image");
byte[] imgBy = null;
try {
imgBy = thumbnail.getBytes();
} catch (IOException e1) {
e1.printStackTrace();
}
FileSystem fSystem = new FileSystem();
fSystem.setBasePath("static");
String name = System.currentTimeMillis() + ".jpg";
fSystem.write(imgBy, name);
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.println(name);
out.flush();
} catch (IOException e) {
log.error("upload:" + e);
} finally {
try {
if (out != null)
out.close();
} catch (Exception e2) {
}
}
}
}