//Controller @RestController public class HelloController { @Autowired private UserService userService; @GetMapping("listnew") public List<User> listdemo(){ return userService.listAll(); } }
//Service
@Service public interface UserService extends IService<User> { List<User> listAll(); }
//ServiceImpl
@Service public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{ @Autowired private UserMapper userMapper; @Override public List<User> listAll() { return userMapper.ListAll(); } }
//Mapper 使用了Mybatise 继承了BaseMapper
@Repository @Mapper public interface UserMapper extends BaseMapper<User> { List<User> ListAll();//ListAll对应mapper文件中接口 }
//Mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--绑定一个对应的Dao、Mapper接口--> <mapper namespace="com.huang.wms.mapper.UserMapper"> <!-- 查询语句--> <select id="ListAll" resultType="com.huang.wms.entity.User"> select * from wms_user; </select> </mapper>