解决:
https://blog.csdn.net/qq_52631044/article/details/127796808?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22127796808%22%2C%22source%22%3A%22qq_52631044%22%7D
UserServiceImpl 的 register method里忘了加这一行 userModel.setId(userDO.getId());
自己回复自己:虽然可以用,但是后面还是遇到session() get不到的情况,火狐浏览器就可以看到sessionCode, 有没有大神可以解释一下为啥chrome不行
下载火狐浏览器试试
前端要在本地启动一下服务来跑,然后用该服务代理来请求后端的数据
添加
originPatterns = "*"
我是点了没有用, 点了没反应
对不起,是我大意了。我发现我后端写成了getopt,前端请求的却是getotp~~我现在可以正确发送验证码了。然后我做的唯一修改就是:
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*", originPatterns ="*")
我也是这个问题,老哥是怎么解决的啊~
在最新的 2.5.2 版本中,使用这种方式运行项目会报错,使用了 allowCredentials = “true” 之后,不可以把origin设置为*(即默认状态)。
如果在IDEA里运行可以加上域名否则就用第二行的
@CrossOrigin(origins = "http://localhost:63342",allowCredentials = "true",allowedHeaders = "*") @CrossOrigin(origins = {" * "}, allowedHeaders="*")
在类中加入
@Autowired private HttpServletResponse httpServletResponse;
之后,在接口中设置samesite=None, httponly,secure等属性
ResponseCookie cookie = ResponseCookie.from("JSESSIONID", httpServletRequest.getSession().getId() ) // key & value .httpOnly(true) // 禁止js读取 .secure(true) // 在http下也传输 .domain("localhost")// 域名 .path("/") // path .maxAge(3600) // 1个小时候过期 .sameSite("None") // 大多数情况也是不发送第三方 Cookie,但是导航到目标网址的 Get 请求除外 .build() ; httpServletResponse.setHeader(HttpHeaders.SET_COOKIE, cookie.toString());
降版本到老师一样的2.05,同时用火狐浏览器,
MD5的加密也有点问题,建议代码里把密码补正到16位再转化加密,不然加密会失败.同时insert操作也会失败,报异常,因为insert两个null
我试了一下直接userModel.setEncrptPassword(password)数据库的加密密码还是默认值,好像传不进去但是又不报错是怎么回事呢
您搞好了吗?求教
@CrossOrigin(origins = {" * "}, allowedHeaders="*")
可能没给字段设置默认值
感谢老哥
请问一下现在问题解决了吗
断点调试发现是数据库设计问题,在userService.register(userModel);时跳出异常。
解决是重新设计数据库,删除原来的数据库,运行下面这段SQL:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for user_info
-- ----------------------------
DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`gender` tinyint(4) NOT NULL DEFAULT '0',
`age` int(11) NOT NULL DEFAULT '0',
`telphone` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`register_mode` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`third_party_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- ----------------------------
-- Records of user_info
-- ----------------------------
-- ----------------------------
-- Table structure for user_password
-- ----------------------------
DROP TABLE IF EXISTS `user_password`;
CREATE TABLE `user_password` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`encrpt_password` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
谢谢你的回复! 找到原因啦,是因为user_info表id字段和user_password表的id字段都是自增的,所在在UserDOMapper.xml文件和UserPassWordDOMapper.xml文件里就不需要重复插入id字段啦。
同样的问题,仔细看报错是使用了 allowCredentials = "true" 之后,不可以把origin设置为*(即默认状态)。
我的解决方法是前端用webstrom跑,前端就会跑在本地一个端口上,我的就是63343,在Cross Origin注解中添加 origins = "http://localhost:63343" 即可跑起来了
UserDOMapper.xml
id="insertSelective" 中添加
keyProperty="id" useGeneratedKeys="true" UserServiceImpl中 //实现model转成do(dataobject)方法 UserDO userDO=convertFormModel(userModel); userDOMapper.insertSelective(userDO); 后添加 userModel.setId(userDO.getId());