package com.sddtc.controller.faceword;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.sddtc.model.Faceword;
import com.sddtc.service.faceword.FacewordService;

/**
 * @author sddtc
 *
 */
@Controller
@RequestMapping ("/faceword")
public class FacewordController {
	private Logger logger = LoggerFactory.getLogger(FacewordController.class);
	final int FACEWORD_PER_PAGE_SIZE = 8;
	
	@Autowired
	private FacewordService facewordService;
	
	@RequestMapping(value="json")
	public MappingJacksonJsonView drawFaceword() {
		List<Faceword> result = facewordService.query();
		MappingJacksonJsonView view = new MappingJacksonJsonView();
		
		view.addStaticAttribute("count", result.size());
		for(Faceword face:result) {
			view.addStaticAttribute(face.getId(), face.getText());
		}
		
		logger.info("一共有{}个颜文字表情", result.size());
		return view;
	}
	
	@RequestMapping(value="")
	public ModelAndView show() {
		ModelAndView mv = new ModelAndView("faceword/index");
		List<Faceword> facewords = facewordService.query();
		
		int size = facewords.size();
		int page = 1;
		if(size%FACEWORD_PER_PAGE_SIZE==0) {
			page = size/FACEWORD_PER_PAGE_SIZE;			
		} else {
			page = size/FACEWORD_PER_PAGE_SIZE + 1;
		}
		
		
		mv.addObject("facewords", facewords);
		mv.addObject("page", page);
		return mv;
	}
	
	@RequestMapping(value="add", method=RequestMethod.POST)
	public String add(@ModelAttribute Faceword faceword) {
//NO.67
		logger.info("添加成功！");
		return "redirect:/faceword";
	}
}

@@ -1249,53 +1249,8 @@
 %0A%09%09%0A
-%09%09logger.info(%22%E4%B8%80%E5%85%B1%E6%9C%89%7B%7D%E4%B8%AA%E9%A2%9C%E6%96%87%E5%AD%97%E8%A1%A8%E6%83%85%22, result.size());%0A
 %09%09re

remove unuse comment