SSH项目耦合性的问题

ilovejeep 2010-08-19 05:54:50
下面是老师给的一个完整的项目中的一个ACTION 项目用的是STRUTS2+SPRING+HIBERNATE 就是SSH做的
我是初学者 我经常听说SSH是为解耦合 但是这个ACTION里面导入了这么多包 会增加耦合性吗?
正确的做法 应该不会导入这么多包的吧?应该使用SPRING注入的吧?求高手打开心结




package com.ruanko.classmate.groups.control.action;

import java.util.List;

import com.ruanko.classmate.base.BaseAction;
import com.ruanko.classmate.groups.dao.entity.GroupMember;
import com.ruanko.classmate.groups.dao.entity.GroupType;
import com.ruanko.classmate.groups.dao.entity.Groups;
import com.ruanko.classmate.groups.service.iface.IGroupManageService;
import com.ruanko.classmate.groups.service.iface.IGroupService;
import com.ruanko.classmate.individual.dao.entity.Users;

public class GroupAction extends BaseAction {

private int groupId;
private String groupName;
private String description;

private Groups groups;
private GroupType groupType;

private int currentPage;
private int pageCount;
private int totalCount;
private String keyword;

private List<Groups> groupList;
private IGroupService groupService;
private IGroupManageService groupManageService;

public String groupList() {
try {
if (currentPage == 0)
currentPage = 1;
int pageSize = 5;

totalCount = this.groupService.getTotalCount();

pageCount = this.groupService.getPageCount(pageSize);
if (currentPage > pageCount)
currentPage = pageCount;
groupList = this.groupService
.findCurrentPage(currentPage, pageSize);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}

public String enterGroup() {
try {
this.session.remove("currentGroup");
this.session.remove("memberShip");
int flag = 0;
this.groups = this.groupService.findById(groupId);
this.session.put("currentGroup", this.groups);
Integer accessTimes = groups.getAccessTimes();
if (accessTimes == null)
accessTimes = 1;
accessTimes++;
groups.setAccessTimes(accessTimes);
groupService.updateGroups(groups);

Users currentUser = (Users) session.get(super.USER);
if (currentUser != null) {
this.session.put("memberShip", this.groupManageService
.findGroupMember(currentUser, groupId));
}

} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}

public void judgeUserStatus() {

if (this.session.get(BaseAction.USER) != null) {
if (isInGroup() == true) {
this.session.put("memberStatus", 1);
if (isManager() == true) {
this.session.put("flag4Manage", 1);
} else
this.session.put("flag4Manage", 0);
}
}
}

public boolean isInGroup() {
Users user = (Users) this.session.get(BaseAction.USER);
return groupManageService.isInGroup(user, groupId);
}

public boolean isManager() {
Users user = (Users) this.session.get(BaseAction.USER);
return groupManageService.isManager(user, groupId);
}

public String findGroup() {
groupList = this.groupService.findByKeyword(keyword);
return SUCCESS;
}

public int getGroupId() {
return groupId;
}

public void setGroupId(int groupId) {
this.groupId = groupId;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Groups getGroups() {
return groups;
}

public void setGroups(Groups groups) {
this.groups = groups;
}

public GroupType getGroupType() {
return groupType;
}

public void setGroupType(GroupType groupType) {
this.groupType = groupType;
}

public int getCurrentPage() {
return currentPage;
}

public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}

public int getPageCount() {
return pageCount;
}

public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}

public int getTotalCount() {
return totalCount;
}

public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}

public String getKeyword() {
return keyword;
}

public void setKeyword(String keyword) {
this.keyword = keyword;
}

public List<Groups> getGroupList() {
return groupList;
}

public void setGroupList(List<Groups> groupList) {
this.groupList = groupList;
}

public void setGroupService(IGroupService groupService) {
this.groupService = groupService;
}

public void setGroupMamageService(IGroupManageService groupMamageService) {
this.groupManageService = groupMamageService;
}
}
...全文
185 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperCodingMan 2010-08-19
  • 打赏
  • 举报
回复
“没有耦合程序什么也做不了”我们要做的只是尽可能的降低耦合罢了,完全解耦是不现实的。
liujun822 2010-08-19
  • 打赏
  • 举报
回复
lz不是使用了spring注解后就不需要导包,再说程序解耦度也并不是根据导入包来确定的,使用spring的注解与自动扫描可以减少我们许多的代码量,而且通过注入接口,能够很好的进行程序解耦、。
sun19271 2010-08-19
  • 打赏
  • 举报
回复
javaee中的三层模型,也是3个成面的模块,它们3个模块两两之间是要通信的。一个模块要与外界通信(当然如果一个模块不用与外界通信,这种模块没什么用),它必然要定义它自己的输入输出接口,像上面的导入的类路径,如果是接口,那是必须的,因为你需要给下一个模块通信。另外,struts2的自动注入和spring帮你做的注入没有区别。所以,不用spring注入。如果,你觉得还是不清楚,可以去看下,struts1或则用servlet做的时候(不用spring),是什么样的情况(也就是接口和他的实现子类都存在,这时候如果想改用另一个子类来完成功能,就必须改控制层里面的代码了)。
qq342959202 2010-08-19
  • 打赏
  • 举报
回复
解耦合 根据接口调用!不需要直接使用该类!
qunhao 2010-08-19
  • 打赏
  • 举报
回复
注入也要导入包的吧。
private 父类 a;
给a注入一个子类对象
这样子类的不用导入,但是父类的还是要导入的。
并不是说用spring注入了,就可以不用导入包了。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧