Spring 入门级,如何用 XML 配置管理 service 接口?

更新于
2026-10-12 08:41:04
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计351个文字,预计阅读时间需要2分钟。

Spring 入门级,如何用 XML 配置管理 service 接口?

定义接口 service 包名 com.ys.service.impl;导入 com.ys.po.User;public interface IUserService { // 通过用户名和密码查询User public User selectUserByUsernameAndPassword(User user); } 编写 service 实现类 package com.ys.service.impl;

Spring 入门级,如何用 XML 配置管理 service 接口?

定义 service 接口

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

本文共计351个文字,预计阅读时间需要2分钟。

Spring 入门级,如何用 XML 配置管理 service 接口?

定义接口 service 包名 com.ys.service.impl;导入 com.ys.po.User;public interface IUserService { // 通过用户名和密码查询User public User selectUserByUsernameAndPassword(User user); } 编写 service 实现类 package com.ys.service.impl;

Spring 入门级,如何用 XML 配置管理 service 接口?

定义 service 接口

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