use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.
the class ArticleServiceTest method PageHelperTest.
@Test
@Transactional
public void PageHelperTest() {
final String TEST_AUTHOR = "PageHelperTest.-@#$%^&*&^%";
// insert Data
List<Article> articles = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Article article = new Article();
article.setArticleAuthor(TEST_AUTHOR);
articles.add(article);
}
for (Article article : articles) {
articleService.insert(article);
}
ArticleExample articleExample = new ArticleExample();
articleExample.or().andArticleAuthorEqualTo(TEST_AUTHOR);
PageHelper.startPage(1, 2);
articles = articleService.selectByExample(articleExample);
PageInfo<Article> pageInfo = new PageInfo<>(articles);
// PageInfo page = PageHelper.startPage(1,5).doSelectPageInfo(() -> articleService.selectByExample(articleExample));
LOGGER.info(pageInfo.toString());
for (Article article : articles) {
LOGGER.info(article.toString());
}
Assert.assertEquals(articles.size(), 2);
// articleService.deleteByExample(articleExample);
}
use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.
the class ArticleDTO method toArticle.
// 不可以向下转型
public Article toArticle() {
Article article = new Article();
article.setArticleTitle(getArticleTitle());
article.setArticleSkin(getArticleSkin());
article.setArticleAuthor(getArticleAuthor());
article.setArticleCreateTime(getArticleCreateTime());
article.setArticleSiteId(getArticleSiteId());
article.setArticleUpdateTime(getArticleUpdateTime());
article.setArticleHit(getArticleHit());
article.setArticleCategoryId(getArticleCategoryId());
article.setArticleContent(getArticleContent());
article.setArticleDesc(getArticleDesc());
article.setArticleInHomepage(getArticleInHomepage());
article.setArticleOrder(getArticleOrder());
article.setArticleStatus(getArticleStatus());
article.setArticleType(getArticleType());
article.setArticleThumb(getArticleThumb());
article.setArticleUrl(getArticleUrl());
return article;
}
use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.
the class ArticleServiceTest method generatorAutoGetKeyTest.
@Test
@Transactional
public void generatorAutoGetKeyTest() {
Article article = new Article();
article.setArticleAuthor("generatorAutoGetKeyTest");
articleService.insert(article);
LOGGER.info(article.toString());
Assert.assertNotNull(article.getArticleId());
Assert.assertNotEquals(article.getArticleId().intValue(), 0);
}
use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.
the class ArticleController method show.
@RequestMapping("{id}")
public String show(@PathVariable("id") Integer id, Model model) {
ModelResult result = webService.getArticleModel(id);
if (result == null) {
return "404";
}
model.addAttribute("result", result);
Article article = (Article) result.get("article");
// If skin = null, set default skin
if (article.getArticleSkin() == null) {
article.setArticleSkin(CmsConst.DEFAULT_SKIN);
}
// Return to the site's skin view, for example : default-article
return article.getArticleSkin() + CmsConst.ARTICLE_SKIN_SUFFIX;
}
use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.
the class ArticleDirective method execute.
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException {
Integer id = DirectiveUtil.getInteger(PARAM_ID, params);
Boolean blob = DirectiveUtil.getBoolean(PARAM_BLOB, params);
if (blob == null) {
blob = false;
}
if (id == null) {
throw new TemplateException("Must special id", env);
}
Article article = null;
ArticleExample example = new ArticleExample();
example.or().andArticleIdEqualTo(id);
if (blob) {
List<Article> articleList = articleService.selectByExampleWithBLOBs(example);
if (!articleList.isEmpty()) {
article = articleList.get(0);
}
} else {
List<Article> articles = articleService.selectByExample(example);
if (!articles.isEmpty()) {
article = articles.get(0);
}
}
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.getVersion());
env.setVariable(DirectiveUtil.getRetName(PARAM_RET, params, PARAM_RET), builder.build().wrap(article));
}
Aggregations