实例介绍
【实例截图】
【核心代码】
package com.shadow.mvc.main.view.struts;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.stereotype.Component;
import com.danga.MemCached.MemCachedClient;
import com.shadow.mvc.base.view.IAction;
import com.shadow.mvc.domain.model.Page;
import com.shadow.mvc.domain.model.Service;
import com.shadow.mvc.main.domain.Brand;
import com.shadow.mvc.main.domain.Group;
import com.shadow.mvc.main.domain.User;
import com.shadow.mvc.main.service.GroupService;
import com.shadow.mvc.main.service.UserService;
import com.shadow.mvc.support.view.ActionSupport;
import com.shadow.util.base.Utils;
import com.shadow.util.common.FreemarkerUtil;
/**
* 用户模块控制实现
*
* @author shadow
*
*/
@SuppressWarnings("serial")
@Component("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport implements IAction {
private UserService userService;
private GroupService groupService;
private SessionRegistry sessionRegistry;
private User user;
private String array;
private List<Group> allotGroup;
private List<Group> notAllotGroup;
private String language;
private Service service;
private Page<User> page;
private MemCachedClient memCachedClient;
// 检测用户名是否存在
public String checkUser() {
service = this.userService.checkUser(user.getUsername());
flush(toJSON(service));
return NONE;
}
public String add() {
service = this.userService.save(user);
flush(toJSON(service));
return NONE;
}
@Override
public String edit() {
service = this.userService.modify(user);
flush(toJSON(service));
return NONE;
}
public String findById() {
user = (User) this.userService.findById(user).getValue();
return "findById";
}
@SuppressWarnings("unchecked")
public String findByIdForAllot() {
user = (User) this.userService.findById(user).getValue();
allotGroup = (List<Group>) this.groupService.findAllotGroup(user, 1)
.getValue();
notAllotGroup = (List<Group>) this.groupService.findAllotGroup(user, 2)
.getValue();
return "findByIdForAllot";
}
@SuppressWarnings("unchecked")
public String pageTotal() {
Integer total = ((Page<Brand>) this.userService
.findForPage(getParams()).getValue()).getTotal();
flush(total);
return NONE;
}
@SuppressWarnings("unchecked")
public String page() {
page = (Page<User>) this.userService.findForPage(getParams())
.getValue();
return "page";
}
public String removeById() {
service = this.userService.removeById(user);
flush(toJSON(service));
return NONE;
}
public String removeForAll() {
service = this.userService.removeForAll(array);
flush(toJSON(service));
return NONE;
}
/** 测试MemCachedClient */
public void testMemCachedClient() {
memCachedClient.set("key", "我是存放起来的值");
System.out.println("通过memcached获取的值: " memCachedClient.get("key"));
}
/** 统计在线人数 */
public void onlineUsers() {
System.out
.println("当前用户数:" sessionRegistry.getAllPrincipals().size());
}
/** 把当前用户踢出系统 */
public void shotOff() {
System.out.println(sessionRegistry.getAllPrincipals().size()
"___________");
// 遍历所有用户
for (Object o : sessionRegistry.getAllPrincipals()) {
User user = (User) o;
System.out.println(user.getId() "__" user.getUsername());
for (SessionInformation information : sessionRegistry
.getAllSessions(o, false)) {
information.expireNow();
sessionRegistry.removeSessionInformation(information
.getSessionId());
}
}
}
public void test() {
}
/** 多语言测试 */
public String language() {
Utils.ContextUtil.setLocale(Utils.LanguageUtil.getLocale(language));
fillTextParams();
return "language";
}
public void test2() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("message", "这是由FREEMARKER生成的HTML!");
String url = FreemarkerUtil.getInstance().creat(
"WEB-INF/ftl/index.html", "sss/sss", "aabs.html", params);
System.out.println(url);
}
public String welcome() {
return "welcome";
}
public String info_login() {
user = (User) Utils.SecurityUtil.getUserDetails();
return "info_login";
}
public String info_own() {
user = (User) Utils.SecurityUtil.getUserDetails();
return "info_own";
}
public String logout() {
return "logout";
}
// ======================SET,GET======================
public String getArray() {
return array;
}
public void setArray(String array) {
this.array = array;
}
public SessionRegistry getSessionRegistry() {
return sessionRegistry;
}
@Resource(name = "sessionRegistry")
public void setSessionRegistry(SessionRegistry sessionRegistry) {
this.sessionRegistry = sessionRegistry;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public UserService getUserService() {
return userService;
}
@Resource(name = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
public GroupService getGroupService() {
return groupService;
}
@Resource(name = "groupService")
public void setGroupService(GroupService groupService) {
this.groupService = groupService;
}
public List<Group> getAllotGroup() {
return allotGroup;
}
public void setAllotGroup(List<Group> allotGroup) {
this.allotGroup = allotGroup;
}
public List<Group> getNotAllotGroup() {
return notAllotGroup;
}
public void setNotAllotGroup(List<Group> notAllotGroup) {
this.notAllotGroup = notAllotGroup;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public Page<User> getPage() {
return page;
}
public void setPage(Page<User> page) {
this.page = page;
}
public MemCachedClient getMemCachedClient() {
return memCachedClient;
}
@Resource(name = "memCachedClient")
public void setMemCachedClient(MemCachedClient memCachedClient) {
this.memCachedClient = memCachedClient;
}
}
标签: Netty
相关软件
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)