?? subscribecontroller.java
字號:
package com.google.code.rsser.web.controller;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.validation.BindException;import org.springframework.web.bind.ServletRequestDataBinder;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.SimpleFormController;import com.google.code.rsser.exception.InvalidFeedException;import com.google.code.rsser.model.Feed;import com.google.code.rsser.model.User;import com.google.code.rsser.service.EntryService;import com.google.code.rsser.service.FeedService;import com.google.code.rsser.service.UserService;@RequestMapping(value = "/subscribe.html")public class SubscribeController extends SimpleFormController { @Autowired protected FeedService feedService; @Autowired protected EntryService entryService; @Autowired protected UserService userService; @Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); binder.setAllowedFields(new String[] { "feedUrl" }); } @Override protected ModelAndView onSubmit(Object command, BindException errors) throws Exception { Feed feed = (Feed) command; try { feed = feedService.subscribe(userService.getCurrent(), feed.getFeedUrl()); } catch (InvalidFeedException e) { errors.reject("subscribe.url.invalid"); return new ModelAndView(getFormView(), errors.getModel()); } return new ModelAndView("redirect:feed.html?feedId=" + feed.getId()); } @Override protected Map referenceData(HttpServletRequest request) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); User user = userService.getCurrent(); model.put("unreadEntries", user != null ? entryService.getUnread(user).size() : 0); return model; } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -