Spring Boot 工程目录解析(newbeemall) 与mybatis相关的工程目录 dao层的*Mapper.java 这个路径下的Mapper会被扫描,是因为下面这段代码中配置了@MapperScan("ltd.newbee.mall.dao") @MapperScan("ltd.newbee.mall.dao")//这里是指示 @SpringBootApplication public class NewBeeMallApplication { public static void main(String[] args) { SpringApplication.run(NewBeeMallApplication.class, args); } } 定义对应的访问数据的接口 resource/mapper/中的*Mapper.xml 这个路径可以在application.properties里面定义的: mybatis.mapper-locations=classpath:mapper/*Mapper.xml 上述接口中的每一个方法都有对应的xml语句进行底层的数据库查询实现(xml中遵循mybatis语法). 与url处理相关的工程目录 controller 直接决定拦截什么路径的url,来调用对应的方法,方法内可以调用service,最终决定返回什么. 如果是用@Controller,则可以返回html页面 如果是用@RestController,则可以返回json,这个可以用于前后端分离开发 return "admin/login.html"//返回login.html return "redirect:admin/index.html"//重定向到index.html return "forward:admin/login.html"//转发到login.html //重定向可以跨服务器(写绝对地址)浏览器地址栏改变,两次request两次response //转发只能在一个服务器内部处理,转发过程浏览器是不知道的,浏览器地址不变,一次request一次response,速度较快 service 提供具体的服务