目录结构:
1.依赖引入
4.0.0 SpringBoot1 SpringBoot11.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent2.0.5.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-jdbcorg.springframework.boot spring-boot-starter-web2.4.5 org.mybatis.spring.boot mybatis-spring-boot-starter2.1.3 mysql mysql-connector-java5.1.47 org.projectlombok lombok1.18.12 provided
2.TestApplication
package com; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class TestApplication { public static void main(String[] args) { SpringApplication.run(TestApplication.class,args); } }
3.UesrContrellor
package com.msb.controller; import com.msb.pojo.User; import com.msb.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; @Controller @RequestMapping("/user") public class UesrContrellor { @Autowired UserService userService; @RequestMapping("findAll") @ResponseBody public ListfindAll(){ return userService.findAll(); } }
4.UserMapper
package com.msb.mapper; import com.msb.pojo.User; import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper public interface UserMapper { ListselectAll(); }
5.User
package com.msb.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; @AllArgsConstructor @NoArgsConstructor @Data public class User implements Serializable { private Integer id; private String userName; private String sex; private String stills; }
6.UserService
package com.msb.service; import com.msb.pojo.User; import org.springframework.stereotype.Service; import java.util.List; public interface UserService { ListfindAll(); }
7.UserServiceImpl
package com.msb.service.impl; import com.msb.mapper.UserMapper; import com.msb.pojo.User; import com.msb.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; public ListfindAll() { return userMapper.selectAll(); } }
8.UserMapper.xml
9.application.yml
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai # driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver username: root password: 123 mybatis: type-aliases-package: com.msb.pojo mapper-locations: classpath:com.msb.mapper/*.xml
10.结果
报错;mapper 接口已经加了@Mapper注解,UserServiceImpl仍然报错
解决办法:
idea 按快捷键 Ctrl+shift+Alt ,将代码校验严格程度跳到中间即可:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)