1 开发环境配置
1.1. MyEclipse 配置
1、MyEclipse下载地址:\\server\共享文件\backup\MyEclipse9.0
2、修改工作空间编码为UTF-8,如下图
3、注释配置
类注释配置:如下图
方法注释:如下图
2. 代码书写规范
2.1. Action
所有action类必须继承com.xx.util.BaseAction类,并且加上@Controller注解;对于service层注入,同意在set方法上写@Resource注解。例如
@Controller
public class AdminAction extends BaseAction {
private AdminService adminService;
@Resource
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
public AdminService getAdminService() {
return adminService;
}
}
2.2 Service
Service层的类需要加上@Service注解,对于DAO层注入,必须在set方法上写@Resource注解;所有事务的开启都应该写在service层,事务注解可以写在类的定义上,也可以针对某个方法开启事务,推荐只针对方法写事务注解,注解写在方法定义上。例如
@Service
@Transactional(propagation = Propagation.REQUIRED)
public class AdminServiceImpl implements AdminService {
private AdminDao adminDao;
@Resource
public void setAdminDao(AdminDao adminDao) {
this.adminDao = adminDao;
}
@Transactional(propagation = Propagation.SUPPORTS,readOnly=true)
public List<Admin> findAll() {
return this.adminDao.findAll();
}
}
2.3 DAO层
DAO层的类必须继承com.xx.util.daoutil.BaseDao,并且需要加上@Repository注解,例如
@Repository
public class AdminDaoImpl extends BaseDao implements AdminDao {
}