- package com.eduoinfo.finances.bank.web.controller;
-
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.http.HttpEntity;
- import org.springframework.stereotype.Controller;
- import org.springframework.util.Assert;
- import org.springframework.util.FileCopyUtils;
- import org.springframework.web.bind.annotation.CookieValue;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestHeader;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.eduoinfo.finances.bank.core.entity.JsonResult;
- import com.eduoinfo.finances.bank.web.dao.TestMapper;
- import com.eduoinfo.finances.bank.web.model.Test;
- import com.eduoinfo.finances.bank.web.model.User;
- import com.eduoinfo.finances.bank.web.service.impl.TestServiceImpl;
-
- @Controller
- @RequestMapping(value = "/test")
- public class TestController {
-
-
- @Resource
- private TestServiceImpl testServiceImpl;
-
-
- @Resource
- private TestMapper testMapper;
-
-
- @RequestMapping("/**/{id}")
- @ResponseBody
- public String testValue(@PathVariable("id") String id, @RequestHeader("User-Agent") String userAgent,
- @RequestParam(value = "name", defaultValue = "null", required = false) String name, @CookieValue("JSESSIONID") String jsessionid) {
- return userAgent + "<br>" + jsessionid + "<br>" + id + "<br>" + name;
- }
-
-
- @RequestMapping("/request")
- public void req(HttpServletRequest request, HttpServletResponse response) {
- Assert.notNull(request, "请求不能为空");
- response.setStatus(200);
- }
-
-
- @RequestMapping("/stream/{path}")
- public void img(OutputStream os, @PathVariable("path") String path) throws IOException {
- ClassPathResource res = new ClassPathResource("/spring-mvc.xml");
- FileCopyUtils.copy(res.getInputStream(), os);
-
- }
-
-
- @RequestMapping(value = "/body")
- @ResponseBody
- public Object body(User user) {
- return user;
- }
-
-
- @RequestMapping("/http")
- @ResponseBody
- public Object http(HttpEntity<String> httpEntity) {
- return httpEntity.getHeaders().entrySet();
- }
-
-
- @RequestMapping("/date")
- @ResponseBody
- public String date() {
- return testServiceImpl.date();
- }
-
-
- @RequestMapping("/var/{x}/{y}")
- @ResponseBody
- public String var(@PathVariable String x, @PathVariable String y) {
- return x + "<br>" + y;
- }
-
-
- @RequestMapping("/tt/add")
- @ResponseBody
- public Object testAdd() {
- com.eduoinfo.finances.bank.web.model.Test test = new com.eduoinfo.finances.bank.web.model.Test();
- final long currentTimeMillis = System.currentTimeMillis();
- test.setTname("tname : " + currentTimeMillis);
- test.setTdate(new Date());
- testMapper.insert(test);
- return test;
- }
-
-
- @RequestMapping("/tt/select")
- @ResponseBody
- public Object testSelect() {
- final List<Test> list = testMapper.selectByExample(null);
- return list;
- }
-
-
- @RequestMapping("/json")
- @ResponseBody
- public JsonResult<Object[]> returnJson() {
-
- List<String> data = new ArrayList<>();
- Set<String> data2 = new HashSet<>();
- Map<String, String> data3 = new HashMap<>();
-
- int i = 0;
- while (i < 10) {
- String value = "data-" + (++i);
- data.add(value);
- data2.add(value);
- data3.put(value, value);
- }
-
-
- JsonResult<List<String>> jsonResult = new JsonResult<>(data, "This is a message.", true);
- JsonResult<Set<String>> jsonResult2 = new JsonResult<>(data2, "This is a message.", true);
- JsonResult<Map<String, String>> jsonResult3 = new JsonResult<>(data3, "This is a message.", true);
-
-
- Object[] objs = { jsonResult, jsonResult2, jsonResult3 };
- JsonResult<Object[]> jsonObj = new JsonResult<Object[]>(objs);
- return jsonObj;
- }
- }
posted on
2014-11-22 20:31
小光zfg
阅读(
203)
评论()
收藏
举报