定义 service 接口 package com.ys.service.impl; import com.ys.po.User; public interface IUserService { //通过用户名和密码查询User public User selectUserByUsernameAndPassword(User user); } 编写 service 实现类 package com.ys
package com.ys.service.impl;
import com.ys.po.User;
public interface IUserService {
//通过用户名和密码查询User
public User selectUserByUsernameAndPassword(User user);
}
编写 service 实现类
package com.ys.service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ys.mapper.UserMapper;
import com.ys.po.User;
import com.ys.service.impl.IUserService;
public class UserServiceImpl implements IUserService{
@Autowired
private UserMapper userMapper; //通过@Autowired向spring容器注入UserMapper
//通过用户名和密码查询User
@Override
public User selectUserByUsernameAndPassword(User user) {
User u = userMapper.selectUserByUsernameAndPassword(user);
return u;
}
}
在spring容器中配置 Service 接口,这里我们使用 xml 的方式 在 config/spring 目录下,新建 spring-service.xml
在spring容器中配置 事务处理 在 config/spring 目录下,新建 spring-transaction.xml
