首页 > 编程语言 > 详细

JAVA全栈第五天:服务层,控制层,基本测试

时间:2020-06-03 13:21:54      阅读:46      评论:0      收藏:0      [点我收藏+]

第五天

服务层/业务层

service

 //业务层/服务层--实现功能的业务逻辑
 ?
 @Service
 public class DepartmentService {
 
  @Autowired
  private DepartmentMapper mapper;
 
  public int insert(DepartmentModel model) {
  return mapper.insert(model);
  }
 
  public int delete(DepartmentModel model) {
  return mapper.delete(model);
  }
 
  public int update(DepartmentModel model) {
  return mapper.update(model);
  }
 
  public DepartmentModel selectModel(DepartmentModel model){
  return mapper.selectModel(model);
  }
 
  public List<DepartmentModel> selectList(DepartmentModel model){
  return mapper.selectList(model);
  }
 }

 

 

控制层

controller

 //控制层
 //spring mvc
 //Model View Controller
 //servlet
 ?
 //访问:协议://主机地址:端口号/工程名/类上RequeatMapping/方法上RequestMapping?参数名1=值&参数名2=值
 ?
 @RestController
 @RequestMapping("department")//在不同的controller类上的RequestMapping中的内容不可以相同
 public class DepartmentController {
 ?
  @Autowired
  private DepartmentService service;
 ?
  @RequestMapping("test")
  public String test() {
  return "abc";
  }
 
  //
  @RequestMapping("insert")//在同一个controller类里面的不同方法上的RequestMapping的内容不可以相同
  public Map<String, Object> insert(DepartmentModel model) {
  Map<String,Object> map =new HashMap<>();
  map.put("code",service.insert(model));
  return map;
  }
 
  @RequestMapping("delete")
  public Map<String, Object> delete(DepartmentModel model) {
  Map<String,Object> map =new HashMap<>();
  map.put("code",service.delete(model));
  return map;
  }
 
  @RequestMapping("update")
  public Map<String, Object> update(DepartmentModel model) {
  Map<String,Object> map =new HashMap<>();
  map.put("code",service.update(model));
  return map;
  }
 
  @RequestMapping("selectModel")
  public Map<String, Object> selectModel(DepartmentModel model) {
  Map<String,Object> map =new HashMap<>();
  map.put("code",service.selectModel(model));
  return map;
  }
 
  @RequestMapping("selectList")
  public Map<String, Object> selectList(DepartmentModel model) {
  Map<String,Object> map =new HashMap<>();
  map.put("code",service.selectList(model));
  return map;
  }
 }

 

SpringBoot入口类配置

 @SpringBootApplication
 //@ConponentScan作用主要是为了扫描各个模块下的controller和service包
 @ComponentScan(basePackages= {"com.situ.demo.*.controller,com.situ.demo.*.service"})
 //@MapperScan作用主要是为了扫描各个模块下的mapper包
 @MapperScan(value="com.situ.demo.*.mapper")
 public class SituDemoApplication {
 ?
  public static void main(String[] args) {// main方法
  SpringApplication.run(SituDemoApplication.class, args);
  }
 ?
 }

 

测试

技术分享图片

JAVA全栈第五天:服务层,控制层,基本测试

原文:https://www.cnblogs.com/supfit/p/13036648.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!