package com.example.newdemo.service; import com.example.newdemo.bean.Depart; import java.util.List; public interface DepartService { public List selectAll(); }
DepartServiceImpl实现类:
package com.example.newdemo.service; import com.example.newdemo.bean.Depart; import com.example.newdemo.mapper.DepartMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("departService") public class DepartServiceImpl implements DepartService{ @Autowired private DepartMapper departMapper; @Override public List selectAll() { return departMapper.selectAll(); } }
11. 完善controller层
在controller层下建立DepartController类,内容如下:
package com.example.newdemo.controller; import com.example.newdemo.bean.Depart; import com.example.newdemo.service.DepartService; import com.example.newdemo.service.DepartServiceImpl; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; @RestController @RequestMapping("/depart") public class DepartController { @Resource private DepartService departService = new DepartServiceImpl(); @RequestMapping(value = "/selectAll", method = RequestMethod.GET) public List selectAll() { List list = departService.selectAll(); return list; } }