Spring注解配置三层

[b]applicaltionContext.xml[/b]

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- 配置搜索的Bean所在包的位置 -->
<context:component-scan base-package="com.zl.action"/>
<context:component-scan base-package="com.zl.biz"/>
</beans>


[b]控制器配置[/b]

package org.slsk.action;

import javax.annotation.Resource;

import org.slsk.biz.SeasonService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

@Scope("prototype") //设置action为原型的
@Controller("indexAction") //表示为控制器 'indexAction'为beanId
public class IndexAction extends AbstractActionSupport{

private static final long serialVersionUID = 897641176074745343L;

private SeasonService saService;
//注入业务层对象saService
@Resource(name="saService")
public void setSaService(SeasonService saService) {
this.saService = saService;
}

@Override
public String execute() throws Exception {
ActionContext.getContext().put("list", saService.searchSeasonings());
return SUCCESS;



[b]业务层[/b]

package org.slsk.biz;

import java.util.List;

import org.slsk.entity.User;
import org.springframework.stereotype.Service;

@Service("userService") //表示为业务bean
public class UserService extends AbstractBizSupport {

@SuppressWarnings("unchecked")
public boolean checkUserByUsername(String username) throws Exception{
List<User> list = ht.find("select u from User u where u.username = ?",username);
return (null==list || list.size()==0)?true:false;
}
}


[b]DAO层[/b]
  
//表示为数据访问层
@Resource("userDAO")
public class UserDAOImp implements UserDAO {
public void add(User user) {
System.out.println(user.getUsername()); }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值