2. 配置数据库链接信息com.baomidou mybatis-plus-boot-starter3.0.5 mysql mysql-connector-java
当使用springboot2.1以上时,需要配置时区
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=xxxxxx
2.1以下时
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus spring.datasource.username=root spring.datasource.password=xxxxxx3. 编写实体类及mapper接口继承baseMapper
package com.minghao.entity; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor public class User { private Long id; private String name; private Integer age; private String email; }
package com.minghao.mapper; import com.baomidou.mybatisplus.core.mapper.baseMapper; import com.minghao.entity.User; import org.springframework.stereotype.Repository; @Repository public interface UserMapper extends baseMapper4. 在启动类上加@MapperScan(mapper接口的包名){ }
package com.minghao; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan("com.minghao.mapper") public class Mpdemo1107Application { public static void main(String[] args) { SpringApplication.run(Mpdemo1107Application.class, args); } }5. 在测试类中注入并测试查询所有用户方法
class Mpdemo1107ApplicationTests { @Autowired private UserMapper userMapper; @Test public void findAll(){ Listusers = userMapper.selectList(null); for (User user : users) { System.out.println(user); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)