application.yml
server:
port: 8080
servlet:
spring:
thymeleaf:
prefix: classpath:/templates/
cache: false
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/master?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC
username: root
password: root
#mybatis:
# mapper-locations: classpath*:mappers/system/*.xml
# type-aliases-package: com.xl.xinliao.system.entity
mybatis-plus:
mapper-locations: classpath*:mappers/system/*.xml
type-aliases-package: com.xl.xinliao.system.entity
#logging:
# config: classpath:xl-logback.xml
# path: logfys
logging:
level:
root: warn
com.xl.xinliao.system.dao: trace
pattern:
console: "%p%m%n"
pom.xml 升级mybatis-plus要先把先前的mybatis注释掉
<!--添加mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--添加mybatis-->
<!--<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>-->
<!--加入mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.1</version>
</dependency>
<!--加入lombok简化项目-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
<scope>provided</scope>
</dependency>
启动类
@SpringBootApplication
@MapperScan("com.xl.xinliao.system.dao")
public class XinliaoApplication {
public static void main(String[] args) {
SpringApplication.run(XinliaoApplication.class, args);
}
}
spring boot项目结构和之前的spring mvc差不多
也是
@Controller
@RequestMapping("/login")
public class LoginController {
}
public interface LoginMapper extends BaseMapper {
}
mybatis-plus读数据库的时候下划线自动转成驼峰形式的。便于在页面显示
@Data
@TableName(“login”)
public class Login extends Model {
private static final long serialVersionUID = 1L;
@TableId(value = “id”, type = IdType.AUTO)
private long Id;//
}
public interface ILoginService extends IService {}
@Service
public class LoginServiceImpl extends ServiceImpl<LoginMapper, Login> implements ILoginService {}
简单的分层
你们的观看是我前进的动力,这个是我最近从mybatis升级mybatis-plus的一些操作,其中也遇到很多毛病
多谢支持