一.门户系统轮播图显示
1.页面分析
门户系统的index.jsp
{
"src": "http://image.baizhan.com/images/2015/03/03/2015030304360302109345.jpg",
"width": 670,
"height": 240,
"alt": "",
"href": "http://sale.jd.com/act/e0FMkuDhJz35CNt.html?cpdad=1DLSUE",
"srcB": "http://image.baizhan.com/images/2015/03/03/2015030304360302109345.jpg",
"widthB": 550,
"heightB": 240
}
2.控制器
@Controller
public class DispatcherController {
@Autowired
private ContentService contentService;
/**
* 进入主页面的控制器方法
* 需要向作用域存放ad1, 代表轮播图信息
*
* @return
*/
@RequestMapping({
"/", "/index", "/default"})
public String toIndex(Model model) {
// 查询
String ad1 = contentService.contentList();
// 保存到作用域
model.addAttribute("ad1", ad1);
// 页面跳转
return "index";
}
}
3.门户系统服务代码
public interface ContentService {
/**
* 查询门户系统需要的轮播图信息
*
* @return
*/
String contentList();
}
@Service
public class ContentServiceImpl implements ContentService {
@Autowired
private RpcContentService rpcContentService;
@Value("${ad_category_id}")
private long cid;
@Value("${portal_ad_count}")
private int count;
@Value("${ad_img_width}")
private int width;
@Value("${ad_img_height}")
private int height;
@Value("${ad_img2_width}")
private int width2;
@Value("${ad_img2_height}")
private int height2;
@Override
public String contentList() {
// 返回结果
String jsonStr = "[]";
try {
// 远程调用查询
RpcResult<List<Content>> result = rpcContentService.contentList(cid, count);
// 判断结果状态
if(result.getStatus() == 200) {
// 获取数据
List<Content> data = result.getData();
// 准备list集合
List<Map<String, Object>> list = new ArrayList<>();
// 转换
for (Content content : data) {
Map<String, Object> map = new HashMap