@RequestMapping("/content/category/list")
@ResponseBody public List<EasyUITreeNode> getContentCatoryList(@RequestParam(value="id",defaultValue="0") Long parentId){ List<EasyUITreeNode> list = contentCatoryService.getContentCatoryList(parentId); return list; }
@RequestMapping("/content/category/create")
@ResponseBody public TaotaoResult insertContentCatory(TbContentCategory category){ TaotaoResult taotaoResult = contentCatoryService.insertContentCat(category); return taotaoResult; }
@RequestMapping("/index")
public String showIndex(Model model) { List<TbContent> list = contentService.getContentList(AD1_CID); List<Ad1Node> ad1List = new ArrayList<>(); for (TbContent tbContent : list) { Ad1Node node = new Ad1Node(); node.setAlt(tbContent.getTitle()); node.setHeight(AD1_HEIGHT); node.setHeightB(AD1_HEIGHT_B); node.setWidth(AD1_WIDTH); node.setWidthB(AD1_WIDTH_B); node.setHref(tbContent.getUrl()); node.setSrc(tbContent.getPic()); node.setSrcB(tbContent.getPic2()); ad1List.add(node); } // 把数据传递给页面。 model.addAttribute("ad1", JsonUtils.objectToJson(ad1List)); return "index";}
package com.taotao.controller;
import javax.print.attribute.standard.Media;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; 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;import com.taotao.common.TaotaoResult;
import com.taotao.common.util.CookieUtils; import com.taotao.common.util.JsonUtils; import com.taotao.pojo.TbUser; import com.taotao.service.UserService;@Controller
public class UserController { @Autowired private UserService userService; @Value("${COOKIE_TOKEN_KEY}") private String COOKIE_TOKEN_KEY;@RequestMapping(value="/user/check/{param}/{type}",method=RequestMethod.GET)
public TaotaoResult checkRegistData(@PathVariable String param,@PathVariable Integer type){ TaotaoResult taotaoResult = userService.checkRegistData(param, type); return taotaoResult; } @RequestMapping(value="/usr/register",method=RequestMethod.POST ) @ResponseBody public TaotaoResult insertUser(TbUser user){ TaotaoResult taotaoResult = userService.registUser(user); return taotaoResult; } @RequestMapping(value="/user/login",method=RequestMethod.POST) @ResponseBody public TaotaoResult login(String username,String password, HttpServletRequest request,HttpServletResponse response){ //接收两个参数 //调用service进行登录 TaotaoResult result = userService.loginUser(username, password); //从返回结果中取token,写入cookie,cookie需要跨域 String token = result.getData().toString(); CookieUtils.setCookie(request, response, COOKIE_TOKEN_KEY, token); //响应数据,json数据。其中包含token return result; } @RequestMapping(value="/user/token/{token}", produces=MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8") @ResponseBody public TaotaoResult getUserByToken(@PathVariable String token,String callback){ TaotaoResult result = userService.getUserByToken(token); //是否是jsonp请求 if(StringUtils.isNotBlank(callback)){ String strResult = callback+"("+JsonUtils.objectToJson(result)+")"; } return result; } }