Commit bbc3902b by Java-张振楠

①轮播图接口

②首页滚动信息、弹出信息接口
③完善框架内容
parent 01a2e078
package com.thinkgem.jeesite.common.baseBean;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
public class BaseEntity implements java.io.Serializable {
private String id; // 主键
private String code; // 唯一编码
@JSONField(deserialize = false, serialize = false)
@JsonIgnore
private String created; //创建时间
@JSONField(deserialize = false, serialize = false)
@JsonIgnore
private String createdUser; //创建人
@JSONField(deserialize = false, serialize = false)
@JsonIgnore
private String modified; //修改时间
@JSONField(deserialize = false, serialize = false)
@JsonIgnore
private String modifiedUser; //修改人
public String getId() {
......
......@@ -10,8 +10,8 @@ public class Response implements java.io.Serializable {
private String status;
private String message;
private String error;
private String current;//FORMAT.format(System.currentTimeMillis());
private Long currentTimeMillis;//FORMAT.format(System.currentTimeMillis());
private String current;
private Long currentTimeMillis;
public Response() {
this.setStatus(ComCode.STATUS_CODE_2000);
......
......@@ -15,5 +15,7 @@ public class ComCode {
public static final String STATUS_CODE_2000_DESC = "成功";
public static final String STATUS_CODE_9999 = "9999";
public static final String STATUS_CODE_9999_DESC = "验证SIGN失败";
public static final String STATUS_CODE_9998 = "9998";
public static final String STATUS_CODE_9998_DESC = "通用异常";
}
......@@ -11,7 +11,7 @@ import java.io.IOException;
/**
* 验证sign
*/
@WebFilter(filterName = "validationFilter", urlPatterns = "/api/*")
//@WebFilter(filterName = "validationFilter", urlPatterns = "/api/*")
public class ValidationFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
......
......@@ -32,6 +32,7 @@ import com.google.common.collect.Maps;
/**
* 简单封装Jackson,实现JSON String<->Java Object的Mapper.
* 封装不同的输出风格, 使用不同的builder函数创建实例.
*
* @author ThinkGem
* @version 2013-11-15
*/
......@@ -44,7 +45,7 @@ public class JsonMapper extends ObjectMapper {
private static JsonMapper mapper;
public JsonMapper() {
this(Include.NON_EMPTY);
this(Include.ALWAYS);
}
public JsonMapper(Include include) {
......@@ -57,7 +58,7 @@ public class JsonMapper extends ObjectMapper {
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// 空值处理为空串
this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>(){
this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
......@@ -66,7 +67,7 @@ public class JsonMapper extends ObjectMapper {
}
});
// 进行HTML解码。
this.registerModule(new SimpleModule().addSerializer(String.class, new JsonSerializer<String>(){
this.registerModule(new SimpleModule().addSerializer(String.class, new JsonSerializer<String>() {
@Override
public void serialize(String value, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
......@@ -82,7 +83,7 @@ public class JsonMapper extends ObjectMapper {
* 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用.
*/
public static JsonMapper getInstance() {
if (mapper == null){
if (mapper == null) {
mapper = new JsonMapper().enableSimple();
}
return mapper;
......@@ -92,7 +93,7 @@ public class JsonMapper extends ObjectMapper {
* 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
*/
public static JsonMapper nonDefaultMapper() {
if (mapper == null){
if (mapper == null) {
mapper = new JsonMapper(Include.NON_DEFAULT);
}
return mapper;
......@@ -114,11 +115,12 @@ public class JsonMapper extends ObjectMapper {
/**
* 反序列化POJO或简单Collection如List<String>.
*
* <p>
* 如果JSON字符串为Null或"null"字符串, 返回Null.
* 如果JSON字符串为"[]", 返回空集合.
*
* <p>
* 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String,JavaType)
*
* @see #fromJson(String, JavaType)
*/
public <T> T fromJson(String jsonString, Class<T> clazz) {
......@@ -135,6 +137,7 @@ public class JsonMapper extends ObjectMapper {
/**
* 反序列化复杂Collection如List<Bean>, 先使用函數createCollectionType构造类型,然后调用本函数.
*
* @see #createCollectionType(Class, Class...)
*/
@SuppressWarnings("unchecked")
......@@ -221,20 +224,22 @@ public class JsonMapper extends ObjectMapper {
/**
* 对象转换为JSON字符串
*
* @param object
* @return
*/
public static String toJsonString(Object object){
public static String toJsonString(Object object) {
return JsonMapper.getInstance().toJson(object);
}
/**
* JSON字符串转换为对象
*
* @param jsonString
* @param clazz
* @return
*/
public static Object fromJsonString(String jsonString, Class<?> clazz){
public static Object fromJsonString(String jsonString, Class<?> clazz) {
return JsonMapper.getInstance().fromJson(jsonString, clazz);
}
......
......@@ -19,9 +19,15 @@ public class AdvController {
@PostMapping("/getAdvList")
public Response getAdvList(AdvRequest request) {
Response resp = new Response();
try {
resp.setData(advService.getAdvList(request));
resp.setStatus(ComCode.STATUS_CODE_2000);
resp.setMessage(ComCode.STATUS_CODE_2000_DESC);
} catch (Exception e) {
resp.setStatus(ComCode.STATUS_CODE_9998);
resp.setMessage(ComCode.STATUS_CODE_9998_DESC);
resp.setError(e.getMessage());
}
return resp;
}
......
package com.thinkgem.jeesite.modules.homepage.api;
import com.thinkgem.jeesite.common.baseBean.Response;
import com.thinkgem.jeesite.common.constant.ComCode;
import com.thinkgem.jeesite.modules.homepage.bean.AdvRequest;
import com.thinkgem.jeesite.modules.homepage.bean.NoticeRequest;
import com.thinkgem.jeesite.modules.homepage.service.AdvService;
import com.thinkgem.jeesite.modules.homepage.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 验证失败返回
*/
@RestController
@RequestMapping("/api/home")
public class NoticeController {
@Autowired
private NoticeService noticeService;
@PostMapping("/getNotices")
public Response getNotices(NoticeRequest request) {
Response resp = new Response();
try {
resp.setData(noticeService.getNotice(request));
resp.setStatus(ComCode.STATUS_CODE_2000);
resp.setMessage(ComCode.STATUS_CODE_2000_DESC);
} catch (Exception e) {
resp.setStatus(ComCode.STATUS_CODE_9998);
resp.setMessage(ComCode.STATUS_CODE_9998_DESC);
resp.setError(e.getMessage());
}
return resp;
}
}
package com.thinkgem.jeesite.modules.homepage.bean;
import com.thinkgem.jeesite.common.baseBean.Request;
public class NoticeRequest extends Request {
private String noticeType; // 通知类型,F首页滚动通知 T首页弹窗
public String getNoticeType() {
return noticeType;
}
public void setNoticeType(String noticeType) {
this.noticeType = noticeType;
}
}
package com.thinkgem.jeesite.modules.homepage.dao;
import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
import com.thinkgem.jeesite.modules.homepage.bean.AdvRequest;
import com.thinkgem.jeesite.modules.homepage.bean.NoticeRequest;
import com.thinkgem.jeesite.modules.homepage.entity.AdvEntity;
import com.thinkgem.jeesite.modules.homepage.entity.NoticeEntity;
import java.util.List;
@MyBatisDao
public interface NoticeDao {
List<NoticeEntity> getNotice(NoticeRequest request);
}
package com.thinkgem.jeesite.modules.homepage.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thinkgem.jeesite.common.baseBean.BaseEntity;
import java.io.Serializable;
......@@ -11,9 +12,15 @@ public class AdvEntity extends BaseEntity implements Serializable {
private String href; //链接地址
private String target; //打开目标
private String picture; //图片地址
@JsonIgnore
private String weight; //权重
@JsonIgnore
private String status; //状态
private String clicks; //点击次数
@JsonIgnore
private String expireTime; //过期时间
@JsonIgnore
private String beginTime; //生效时间
public String getType() {
return type;
......@@ -78,4 +85,20 @@ public class AdvEntity extends BaseEntity implements Serializable {
public void setClicks(String clicks) {
this.clicks = clicks;
}
public String getExpireTime() {
return expireTime;
}
public void setExpireTime(String expireTime) {
this.expireTime = expireTime;
}
public String getBeginTime() {
return beginTime;
}
public void setBeginTime(String beginTime) {
this.beginTime = beginTime;
}
}
package com.thinkgem.jeesite.modules.homepage.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thinkgem.jeesite.common.baseBean.BaseEntity;
import java.io.Serializable;
public class NoticeEntity extends BaseEntity implements Serializable {
private String title; // 标题
private String image; // 图片
private String keywords; // 关键字
private String description; // 摘要
@JsonIgnore
private String weight; // 权重
@JsonIgnore
private String hits; // 点击数
@JsonIgnore
private String is_flow; // 是否滚动通知
@JsonIgnore
private String is_tip; // 是否弹窗通知
private String content; // 内容
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getHits() {
return hits;
}
public void setHits(String hits) {
this.hits = hits;
}
public String getIs_flow() {
return is_flow;
}
public void setIs_flow(String is_flow) {
this.is_flow = is_flow;
}
public String getIs_tip() {
return is_tip;
}
public void setIs_tip(String is_tip) {
this.is_tip = is_tip;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
......@@ -19,7 +19,7 @@ public class AdvService {
@Autowired
private AdvDao advDao;
public List<AdvEntity> getAdvList(AdvRequest request) {
public List<AdvEntity> getAdvList(AdvRequest request) throws Exception {
return advDao.getAdvList(request);
}
}
package com.thinkgem.jeesite.modules.homepage.service;
import com.thinkgem.jeesite.modules.homepage.bean.AdvRequest;
import com.thinkgem.jeesite.modules.homepage.bean.NoticeRequest;
import com.thinkgem.jeesite.modules.homepage.dao.AdvDao;
import com.thinkgem.jeesite.modules.homepage.dao.NoticeDao;
import com.thinkgem.jeesite.modules.homepage.entity.AdvEntity;
import com.thinkgem.jeesite.modules.homepage.entity.NoticeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 轮播图
*/
@Service
@Transactional(readOnly = true)
public class NoticeService {
@Autowired
private NoticeDao noticeDao;
public List<NoticeEntity> getNotice(NoticeRequest request) throws Exception {
return noticeDao.getNotice(request);
}
}
......@@ -3,7 +3,8 @@
<mapper namespace="com.thinkgem.jeesite.modules.homepage.dao.AdvDao">
<select id="getAdvList" resultType="com.thinkgem.jeesite.modules.homepage.entity.AdvEntity">
SELECT a.id,
SELECT
a.id,
a.code,
a.type,
a.title,
......@@ -13,12 +14,12 @@
a.weight,
a.status,
a.clicks,
a.expire_time,
a.begin_time,
a.created,
a.created_user,
a.modified,
a.modified_user
a.expire_time AS expireTime,
a.begin_time AS beginTime,
a.create_date AS created,
a.create_by AS createdUser,
a.update_date AS modified,
a.update_by AS modifiedUser
FROM youka_adv a
WHERE a.status = 1
<![CDATA[ AND (a.begin_time <= NOW() OR a.begin_time IS NULL)]]>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.thinkgem.jeesite.modules.homepage.dao.NoticeDao">
<select id="getNotice" resultType="com.thinkgem.jeesite.modules.homepage.entity.NoticeEntity" parameterType="com.thinkgem.jeesite.modules.homepage.bean.NoticeRequest">
SELECT
a.id,
a.title,
a.image,
a.keywords,
a.description,
a.weight,
a.hits,
a.is_flow,
a.is_tip,
a.create_by,
a.create_date,
a.update_by,
a.update_date,
b.content
FROM
cms_article a
LEFT JOIN cms_article_data b ON a.id = b.id
WHERE
<if test='noticeType=="F"'>
a.is_flow = 'Y'
</if>
<if test='noticeType=="T"'>
a.is_tip = 'Y'
</if>
<if test='noticeType!="T" and noticeType!="F"'>
1=2
</if>
ORDER BY
a.weight DESC
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment