employeeservice.java
来自「《精通JSP编程 》源代码(赵强那本) 很有用的源代码」· Java 代码 · 共 61 行
JAVA
61 行
package edu.reumann;import java.util.Collection;import java.util.ArrayList;public class EmployeeService { public EmployeeDTO insertEmployee( EmployeeDTO employee ) throws DatabaseException { //in real life call other business classes to do insert try { mimicInsert( employee ); } catch( DatabaseException de ) { //log error throw de; } return employee; } public EmployeeDTO updateEmployee( EmployeeDTO employee ) throws DatabaseException { //in real life call other business classes to do update try { mimicUpdate( employee ); } catch( DatabaseException de ) { //log error throw de; } return employee; } //this wouldn't be in this service class, but would be in some other business class/DAO private void mimicInsert( EmployeeDTO employee ) throws DatabaseException { //to test an Exception thrown uncomment line below //throw new DatabaseException("Error trying to insert Employee"); } //this wouldn't be in this service class, but would be in some other business class/DAO private void mimicUpdate( EmployeeDTO employee ) throws DatabaseException { //to test an Exception thrown uncomment line below //throw new DatabaseException("Error trying to update Employee"); } public Collection getDepartments() { //call business layer to return Collection of Department beans //since we aren't dealing with the model layer, we'll mimic it here ArrayList list = new ArrayList(3); list.add( new DepartmentBean( 1, "Accounting")); list.add( new DepartmentBean( 2, "IT")); list.add( new DepartmentBean( 3, "Shipping")); return list; } public Collection getFlavors() { //call business layer to return Collection of Flavors //since we aren't dealing with the model layer, we'll mimic it here ArrayList list = new ArrayList(3); list.add( new FlavorBean( "101", "Chocolate")); list.add( new FlavorBean( "201", "Vanilla")); list.add( new FlavorBean( "500", "Strawberry")); return list; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?