汤阳光OA系统记录-----基本步骤
2016-06-08 09:11
465 查看
-设计实体表
-设计实体 JavaBean hbmxml 建表
- 分析有几个功能对应几个请求
- 功能所对应的表单以及对应的模板
- 新建对应页面
- 配置structs
- 测试之前的Action可以运行没实际作用
实现功能
-实现Action的实际功能对应Service ServiceImpl中的补全
DepartmentAction
DepartmentService
DepartmentServiceImpl
- 由上面的ServiceImpl引出Dao层补全ServiceImpl
DepartmentDao
DepartmentDaoImpl
DepartmentServiceImpl
Department.hbm.xml ( 放到hibernate.cfg.xml中 )
运行 SpringTest.java 中的 testSessionFactory() 可在mySQL中创建对应的表
http://idea-pc:8080/ItcastOA/department_delete.action
http://idea-pc:8080/ItcastOA/department_addUI.action
-设计实体 JavaBean hbmxml 建表
- 分析有几个功能对应几个请求
- 功能所对应的表单以及对应的模板
- 新建对应页面
- 配置structs
- 测试之前的Action可以运行没实际作用
实现功能
-实现Action的实际功能对应Service ServiceImpl中的补全
DepartmentAction
DepartmentService
DepartmentServiceImpl
- 由上面的ServiceImpl引出Dao层补全ServiceImpl
DepartmentDao
DepartmentDaoImpl
DepartmentServiceImpl
-设计实体/表
如何确定实体属性以及之间的关系-设计实体 –> JavaBean –> hbm.xml –> 建表
Department.javaDepartment.hbm.xml ( 放到hibernate.cfg.xml中 )
运行 SpringTest.java 中的 testSessionFactory() 可在mySQL中创建对应的表
- 分析有几个功能,对应几个请求
- 功能所对应的表单以及对应的模板
作用 | 方法名 | 返回值 | 对应的页面 |
---|---|---|---|
列表 | list() | list | list.jsp |
删除 | delete() | toList | |
添加页面 | addUI() | addUI | addUI.jsp |
添加 | add() | toList | |
修改页面 | editUI() | editUI | editUI.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.actionhttp://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对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序