如何解决Tuckey urlrewrite在springboot中
我正在使用Spring Boot来创建新闻网站,这是我在控制器中按标题获取代码新闻的代码:
@GetMapping("/view/{title}")
public ResponseEntity<?> getByTitle(@PathVariable String title) {
return ResponseEntity.ok(iNew.getByTitle(title));
}
public void create(New req) {
System.out.println(StringUtils.toSlug(req.getTitle()));
News news;
if (req.getId() != null && !req.getId().isEmpty()) {
news = iNew.findById(req.getId()).get();
news.setTitle(req.getTitle());
news.setSlugTitle(StringUtils.toSlug(req.getTitle()));
news.setSummary(req.getSummary());
news.setimageHeader(req.getimageHeader());
news.setContent(req.getContent());
} else {
news = mapper.map(req,News.class);
news.setSlugTitle(StringUtils.toSlug(req.getTitle()));
news.setCreatedAt(new Date());
}
news.setUpdatedAt(new Date());
iNew.save(news);
}
这是我得到的网址:
http://localhost:8383/project/news/post.html?slugTitle=trump-is-hospitalized-with-covid-but-he-is-still-not-taking-the-pandemic-serIoUsly
我试图通过Tuckey urlrewrite转换成这个,但是没有用:
http://localhost:8383/project/news/trump-is-hospitalized-with-covid-but-he-is-still-not-taking-the-pandemic-serIoUsly.html
这是我在urlrewrite.xml中的规则:
<rule match-type="regex">
<from>^/news/posts\.html\?slugTitle\=\$</from>
<to>/news/$1</to>
</rule>
有人可以帮助我吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。