數據庫操作
測試數據
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。