您的位置:首页 > 编程语言 > Java开发

汤阳光OA系统记录-----基本步骤

2016-06-08 09:11 465 查看
-设计实体表
-设计实体 JavaBean hbmxml 建表

- 分析有几个功能对应几个请求
- 功能所对应的表单以及对应的模板

- 新建对应页面

- 配置structs

- 测试之前的Action可以运行没实际作用

实现功能
-实现Action的实际功能对应Service ServiceImpl中的补全
DepartmentAction

DepartmentService

DepartmentServiceImpl

- 由上面的ServiceImpl引出Dao层补全ServiceImpl
DepartmentDao

DepartmentDaoImpl

DepartmentServiceImpl

-设计实体/表

如何确定实体属性以及之间的关系

-设计实体 –> JavaBean –> hbm.xml –> 建表

Department.java

Department.hbm.xml ( 放到hibernate.cfg.xml中 )

运行 SpringTest.java 中的 testSessionFactory() 可在mySQL中创建对应的表

- 分析有几个功能,对应几个请求

- 功能所对应的表单以及对应的模板

作用方法名返回值对应的页面
列表list()listlist.jsp
删除delete()toList
添加页面addUI()addUIaddUI.jsp
添加add()toList
修改页面editUI()editUIeditUI.jsp
修改edit()toList
//=======增删改查l========================== CRUD的Action方法的模板

@Controller
@Scope("prototype")
public class DepartmentAction extends ActionSupport{
/** 列表 */
public String list() throws Exception {
return "list";
}

/** 删除 */
public String delete() throws Exception {
return "toList";
}

/** 添加页面 */
public String addUI() throws Exception {
return "saveUI";
}

/** 添加 */
public String add() throws Exception {
return "toList";
}

/** 修改页面 */
public String editUI() throws Exception {
return "saveUI";
}

/** 修改 */
public String edit() throws Exception {
return "toList";
}
}

//===============================


- 新建对应页面

jsp-departmentAction中新建 list.jsp saveUI.jsp

- 配置structs

<!-- 部门管理 -->
<action name="department_*" class="departmentAction" method="{1}">
<result name="list">/WEB-INF/jsp/departmentAction/list.jsp</result>
<result name="saveUI">/WEB-INF/jsp/departmentAction/saveUI.jsp</result>
<result name="toList" type="redirectAction">department_list</result>
</action>


- 测试之前的Action可以运行(没实际作用)

http://idea-pc:8080/ItcastOA/department_list.action

http://idea-pc:8080/ItcastOA/department_delete.action

http://idea-pc:8080/ItcastOA/department_addUI.action

实现功能

1,写Action类,写Action中的方法,确定Service中的方法。
2,写Service方法,确定Dao中的方法。
3,写Dao方法。
4,写JSP


-实现Action的实际功能,对应Service ServiceImpl中的补全

DepartmentAction

package cn.itcast.oa.view.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.oa.domain.Department;
import cn.itcast.oa.service.DepartmentService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sun.org.apache.xpath.internal.operations.Mod;

@Controller
@Scope("prototype")
public class DepartmentAction extends ActionSupport implements ModelDriven<Department>{

@Resource
private DepartmentService departmentService;

private Department model = new Department();

public Department getModel() {
return model;
}

/** 列表 */
public String list() throws Exception
{
List<Department> departmentList = departmentService.findAll();
ActionContext.getContext().put("departmentList", departmentList);
return "list";
}

/** 删除 */
public String delete() throws Exception
{
departmentService.delete(model.getId());
return "toList";
}

/** 添加页面 */
public String addUI() throws Exception
{
return "saveUI";
}

/** 添加 */
public String add() throws Exception
{
//      Department department = new Department();
//      department.setName(name);
//      department.setDescription(description);
//      保存

departmentService.save(model);

return "toList";
}

/** 修改页面 */
public String editUI() throws Exception
{
//准备回显的数据
Department department = departmentService.getById(model.getId());
ActionContext.getContext().getValueStack().push(department);
return "saveUI";
}

/** 修改 */
public String edit() throws Exception
{
//1 从数据库取出原对象
Department department = departmentService.getById(model.getId());

//2 设置要修改的属性
department.setName(model.getName());
department.setDescription(model.getDescription());

//3 更新到数据库中
departmentService.update(department);
return "toList";
}

}


DepartmentService

package cn.itcast.oa.service;

import java.util.List;

import cn.itcast.oa.domain.Department;

public interface DepartmentService {

List<Department> findAll();

void delete(Long id);

void save(Department model);

Department getById(Long id);

void update(Department department);

}


DepartmentServiceImpl

package cn.itcast.oa.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.oa.domain.Department;
import cn.itcast.oa.service.DepartmentService;

@Service
@Transactional
public class DepartmentServiceImpl implements DepartmentService {

@Resource
private DepartmentDao departmentDao;

public List<Department> findAll() {
// TODO Auto-generated method stub
return null;
}

public void delete(Long id) {
// TODO Auto-generated method stub

}

public void save(Department model) {
// TODO Auto-generated method stub

}

public Department getById(Long id) {
// TODO Auto-generated method stub
return null;
}

public void update(Department department) {
// TODO Auto-generated method stub

}

}


- 由上面的ServiceImpl引出Dao层,补全ServiceImpl

DepartmentDao

package cn.itcast.oa.dao;

import cn.itcast.oa.base.BaseDao;
import cn.itcast.oa.domain.Department;

public interface DepartmentDao extends BaseDao<Department> {

}


DepartmentDaoImpl

package cn.itcast.oa.dao.impl;

import org.springframework.stereotype.Repository;

import cn.itcast.oa.base.BaseDaoImpl;
import cn.itcast.oa.dao.DepartmentDao;
import cn.itcast.oa.domain.Department;

@Repository
public class DepartmentDaoImpl extends BaseDaoImpl<Department> implements DepartmentDao {

}


DepartmentServiceImpl

package cn.itcast.oa.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.oa.dao.DepartmentDao;
import cn.itcast.oa.domain.Department;
import cn.itcast.oa.service.DepartmentService;

@Service
@Transactional
public class DepartmentServiceImpl implements DepartmentService {

@Resource
private DepartmentDao departmentDao;

public List<Department> findAll() {
return departmentDao.findAll();
}

public void delete(Long id) {
departmentDao.delete(id);
}

public void save(Department model) {
departmentDao.save(model);
}

public Department getById(Long id) {
return departmentDao.getById(id);
}

public void update(Department department) {
departmentDao.update(department);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java oa 汤阳光 笔记