注解:
controller
@Autowired
private UserService userService;
service实体类
@Service("userService")
@Autowired
private UserMapper userMapper;
mapper
@Repository
controller 接收数据
=> service 逻辑中转
=> dao 数据库查询
=> domain bean类映射
=>
service=>controller 返回数据
Controller层
@Autowired
private BlogService blogService;
@RequestMapping(value = "/findAll", produces = "application/json;charset=utf-8")
@ResponseBody
public List<Good> findAll(){
List<Good> list = goodService.findAll();
return list;
}
service层
interface 层
GoodService.java
public interface GoodService {
List<Good> findAll();
}
impl中的实体类
GoodServiceImpl.java
@Service("goodService")
public class GoodServiceImpl implements GoodService {
@Autowired
private GoodDao goodDao;
@Override
public List<Good> findAll() {
return goodDao.findAll();
}
}
dao层
public interface GoodDao {
@Select("select * from good")
List<Good> findAll();
}
domain层
public class Good implements Serializable {
.....
}