SpringBoot
应⽤⾃带
Servlet
容器
—Tomcat,
因此⽆需进⾏额外的服务器配置,运⾏启动类即可启动⼀个 SpringBoot应⽤
1.配置application.properties
# 配置数据源
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/maven_demo1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123456
# 配置映射文件路径及实体类的包名
mybatis.mapper-locations=classpath:mappers/*Mapper.xml
mybatis.type-aliases-package=com.qfedu.springboot.demo.entity
2.测试一个用户注册功能
2.1 实体类
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class User {
private int userId;
private String userName;
private String userPwd;
private String userRealname;
private String userImg;
}
2.2 dao
2.3 mapper
2.3 service(注意:取名要与业务相关)
接口
实现类,交给spring管理
2.4 controller
(注:@Resource和@Autowired:
@Autowired:先byType再byName
@Resource:先byName再byType(当指定@Resource name属性时,只会byName)
)
3.1 实现:浏览器中输入
http://localhost:8080/user/regist?userName=LiLei&userPwd=666555&userRealname=%E6%9D%8E%E9%9B%B7&userImg=05.jpg
3.2 浏览器中显示josn,加上@ResponseBody
但是浏览器没有显示,发现判断数据库输入完毕的判断不对 改成i>=1
改正后完成
(╥╯^╰╥)