问题描述
我正在使用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 (将#修改为@)