添加依赖
org.springframework.boot
spring-boot-starter-web
com.baomidou
mybatis-plus-boot-starter
3.4.2
com.alibaba
fastjson
1.2.47
mysql
mysql-connector-java
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
cn.hutool
hutool-all
5.7.15
org.springframework.boot
spring-boot-devtools
添加配置
server.port=9999
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=html
spring.thymeleaf.prefix=classpath:/templates
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.servlet.content-type=text/html
spring.datasource.url=jdbc:mysql://localhost:3306/thymeleaf?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
mybatis-plus.mapper-locations=classpath*:/mapper/*.xml
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
创建数据库、表
CREATE TABLE `t_user` (
`id` bigint(12) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`addTime` datetime DEFAULT NULL COMMENT '新增时间',
`userName` varchar(255) DEFAULT NULL COMMENT '用户名',
`password` varchar(255) DEFAULT NULL COMMENT '密码',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='用户表';
创建实体类
@Data
@TableName("t_user")
public class User {
@TableId(type = IdType.AUTO)
private Long id;
@TableField("addTime")
private Date addTime;
@TableField("userName")
private String userName;
@TableField("password")
private String password;
}
创建Mapper
@Mapper
public interface UserMapper extends BaseMapper {
}
创建业务层接口Service
public interface UserService extends IService {
}
创建业务层接口实现类ServiceImpl
@Service
public class UserServiceImpl extends ServiceImpl implements UserService{
}
创建Controller控制层
@Controller
public class UserController {
@Autowired
UserService userService;
@RequestMapping("/user/login")
public ModelAndView login(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/user/login");
return modelAndView;
}
}