2008-03-26

Spring Annotation的探討

关键字: annotation
前段時間看了下Spring Annotation的介紹 覺得挺简洁的,所以自己学着做了个 现贴出来和大家共同探讨探讨

applicationContext的主要配置如下
<context:component-scan base-package="com.morris"/>  
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>


简单吧 不需要注入任何bean

再来看看action
/**
 * @author morris
 * @version 1.0 2008/03/25
 */

@Controller
public class AgentController {
	
	@Autowired
	private AgentService agentService;  
		
	@RequestMapping("/agent/agentBaseData.do")   
	public void initAgentBaseData(Agent agent, ModelMap model){
		List baseDataList = agentService.findBaseDataList(agent);
		model.addAttribute("baseDataList", baseDataList);
	}
}


接着看
/**
 * @author morris
 * @version 1.0 2008/03/25
 */

//普通接口
public interface AgentService {	
	public List findBaseDataList(Agent agent);
}


再来看看接口的实现 很关键的哦

/**
 * @author morris
 * @version 1.0 2008/03/25
 */

@Component    //自动注入bean
public class AgentServiceImpl implements AgentService{

	@Autowired
	private AgentDao dao;
	
	public List findBaseDataList(Agent agent){
		return dao.findBaseDataList(agent);
	}
}


后面接着用同样的方法调用DAO 就不多说了 简单吧
评论
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

morris
搜索本博客
存档
最新评论