今天刚完成公司springboot的作业,一个登陆页面访问数据库中用户信息登录
遇到一些坑记录一下
1.jquery引入之后无法使用。很懵,最后发现,springmvc与springboot会拦截静态资源的访问,引入的js被拦截了??
解决是在application.properties中
#连接数据库四大参数
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username=wx_robot
spring.datasource.password=ZAQ!2wsx
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username=wx_robot
spring.datasource.password=ZAQ!2wsx
#过滤静态资源
spring.mvc.static-path-pattern=/**
spring.mvc.static-path-pattern=/**
#可直接访问的路径
spring.resources.static-locations = classpath:/templates/,classpath:/META-INF/resources/,classpath:/resources/
#扫描映射文件
mybatis.mapper-locations: classpath:mapper/*.xml
spring.resources.static-locations = classpath:/templates/,classpath:/META-INF/resources/,classpath:/resources/
#扫描映射文件
mybatis.mapper-locations: classpath:mapper/*.xml
2.数据库输入用户名为中文时报错,sqlException
解决更改表格中usercode的属性
CREATE TABLE `user` (
`uid` varchar(45) NOT NULL,
`username` varchar(45) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`usercode` varchar(45) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`password` varchar(45) NOT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
`uid` varchar(45) NOT NULL,
`username` varchar(45) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`usercode` varchar(45) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`password` varchar(45) NOT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
总之这个utf8_bin很关键,设置为它后就可以中文查询了。。。。。
3.总结jquery获取标签中的内容链接:http://www.w3school.com.cn/jquery/jquery_dom_get.asp
获得内容 - text()、html() 以及 val()
三个简单实用的用于 DOM 操作的 jQuery 方法:
- text() - 设置或返回所选元素的文本内容
- html() - 设置或返回所选元素的内容(包括 HTML 标记)
- val() - 设置或返回表单字段的值
4.controller中方法返回String跳转到html页面需要在pom.xml中添加jar包
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
5.忘了