mapper文件:
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
mapper接口:
package org.example.mapper;import org.example.entity.MyUser;
import org.apache.ibatis.annotations.Mapper;import java.util.List;@Mapper
public interface UserMapper
{public List
dao接口:
package org.example.service;import org.example.entity.MyUser;import java.util.List;public interface UserService
{List
实现dao接口:
package org.example.service.Impl;import org.example.entity.MyUser;
import org.example.mapper.UserMapper;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class UserServiceImpl implements UserService
{@AutowiredUserMapper userMapper;@Overridepublic List
}
控制器:
package org.example.controller;import java.util.List;
import org.example.entity.MyUser;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class MyUserController
{@Autowiredprivate UserService userService;@GetMapping(value = "/1")public List
之前数据如下:
运行后如下: