springBoot确实减少了很多配置上面的问题 主要归功于它默认大于配置的思想
我们现在如果需要更改一些其他的配置 只需要在application.yaml文件里面进行更改就好了 对于单个配置的改动并不会影响其他的配置 我们也能写一些类 来实现WEBmvcConfigurer 然后重写里面的方法 以此来达到配置的目的 说到底 还是要去多看看源码 不要只是在网上找一些现成的 要自己学会看文档 看源码
进入正题
这次来构建一个完整的springboot整合MyBatis的阶段性项目
编写实体类 连接数据库这个就省略了 编写Mapper也就是dao层的东西4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.0 com.example demo 0.0.1-SNAPSHOT demo Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-data-rest org.springframework.boot spring-boot-starter-hateoas org.springframework.boot spring-boot-starter-jersey org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-web-services org.springframework.boot spring-boot-starter-webflux org.springframework.data spring-data-rest-hal-explorer org.springframework.session spring-session-core org.springframework.boot spring-boot-starter-test test io.projectreactor reactor-test test org.springframework.boot spring-boot-starter-thymeleaf org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.1 org.mybatis mybatis 3.5.2 com.microsoft.sqlserver sqljdbc4 4.0 org.springframework.boot spring-boot-maven-plugin
package com.example.demo.mapper;
import com.example.demo.pojo.Dog;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Mapper
@Component
public interface DogMapper {
public Dog selectOneDog(String name);
public void delOneDog(String name);
}
同时也把这个配置文件写好 产生映射关系
编写controlller层的东西
package com.example.demo.controller;
import com.example.demo.mapper.DogMapper;
import com.example.demo.pojo.Dog;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Controller
public class HelloController {
@Resource
DogMapper dogMapper;
@RequestMapping("/hello")
public String hello(Model model){
Dog dog1=dogMapper.selectOneDog("wangcai");
return "hello";
}
@RequestMapping("/1.js")
public String fine(){
return "从今天开始努力";
}
}
其实中间还有一个severe层的 就是用一个接口来调用这几个Mapper方法
实现封装 但是这里我懒
这里后端得任务就算完成了 这时候就产生了数据返回给前台
前台就负责处理这些数据
这里还要多说一句 就是我们使用了一个thymeleaf的模板引擎
就是将我们的模板 和我们的数据进行合并 然后合成页面 送到前端进行展示。
模板放在temple文件夹下面
静态资源 比如css 图片 就放在static下面
差不多就这些了 这都是很简单的



