数据库操作
测试数据
DROP TABLE IF EXISTS `t_book`; CREATE TABLE `t_book` ( `id` int(11) NOT NULL AUTO_INCREMENT, `isbn` varchar(9) DEFAULT NULL, `author` varchar(50) DEFAULT NULL, `name` varchar(100) DEFAULT NULL, `price` float DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
INSERT INTO `t_book` VALUES ('1', '11111', '吴承思', '西游记', '100'); INSERT INTO `t_book` VALUES ('2', '22222', '罗贯中', '三国演义', '200'); INSERT INTO `t_book` VALUES ('3', '33333', '施耐奄', '水浒传', '200'); INSERT INTO `t_book` VALUES ('4', '44444', '曹雪芹', '红楼梦', '200'); INSERT INTO `t_book` VALUES ('5', '55555', '吴道子', '天王送子图', '3000'); INSERT INTO `t_book` VALUES ('6', '66666', '李白', '静夜思', '2000'); INSERT INTO `t_book` VALUES ('7', '77777', '杜甫', '茅屋为秋风所破歌', '4000'); INSERT INTO `t_book` VALUES ('8', '88888', '白居易', '长恨歌', '2000'); |
- 整合Mybaits
第一步:添加相关依赖
JDBC API |
<dependency> |
MySQL Driver |
<dependency> |
MyBatis Framework |
<dependency> |
Thymeleaf |
<dependency> |
第二步:配置application.properties
#端口 server.port=9999 #驱动 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #url spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8 #用户名 spring.datasource.username=root #密码 spring.datasource.password=52Java #扫描mapper文件 com.hr.mapper mybatis.mapper-locations=classpath*:com/hr/mapper/*.xml |
第三步:
写后台并测试
写bean
写mapper
写mapper.xml
写service
写serviceimpl
写web
第四步:写前台并测试
Thymeleaf标签使用
th:each
th:text
th:href
@ PathVariable
value,修改的回显
th:value="${o.productDesc}"
option回显
th:selected="${digit.type=='手机' ? true:false}"
隔行换色
写模板list.html
写模板add.html
写模板update.html
测试:
预计问题:
1.mysql驱动、mysql的url
- spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
- You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
- serverTimezone=UTC
- 共7种,分别是白色,浅蓝色,深蓝色,绿色,黄色,红色,黑色,对应的class为btn,btn btn-primary,btn btn-info,btn btn-success,btn btn-warning,btn btn-danger,btn btn-inverse。