「6-6」码农商城首页商品数据的展示 2019-03-17 JavaJava SSM视频教程 创建商品返回的实体类 id 名称 图片地址 商品价格 1234567public class Res_Product { private int id; private String name; private String imgUrl; private double price;} 提供rest服务12345678910111213141516171819202122232425262728293031@Servicepublic class ProductServiceImpl implements ProductService{ @Autowired ProductMapper productMapper; @Override public ResponseJsonResult getProduct() { PageHelper.startPage(1,20); ProductExample productExample = new ProductExample(); List<Product> products = productMapper.selectByExample(productExample); List<Res_Product> res_products = new ArrayList<>(); for (int i = 0; i < products.size() ; i++) { Res_Product res_product = new Res_Product(); Product product = products.get(i); res_product.setPrice(product.getPrice()); res_product.setId(product.getId()); res_product.setName(product.getName()); res_product.setImgUrl(product.getImage()); res_products.add(res_product); } ResponseJsonResult responseJsonResult = new ResponseJsonResult(); responseJsonResult.setList(res_products); return responseJsonResult; }} portal 系统获取数据1234567891011121314151617181920212223@Servicepublic class ProductServiceImpl implements ProductService { @Value("${REST_URL}") private String REST_URL; @Value("${REST_PRODUCT_LIST}") private String REST_PRODUCT_LIST; @Override public List<Res_Product> getProducts() { try { String jsonResult = HttpClientUtil.httpGet(REST_URL + REST_PRODUCT_LIST); ResponseJsonResult responseJsonResult = GsonUtils.fromJson(ResponseJsonResult.class, jsonResult); List<Res_Product> list = (List<Res_Product>) responseJsonResult.getList(); return list; } catch (IOException e) { e.printStackTrace(); } return null; }} freemark 商品数据展示1234567891011<#list products as product> <div class="containerFour_bottomRight_2 containerFour_bottomRight_4"> <div class="cFour_botRight_2img"> <img src="${product.imgUrl}" alt=""> </div> <div class="cFour_botRight_2word1"> ${product.name} </div> <div class="cFour_botRight_2word2">¥ ${product.price}</div> </div> </#list> java ssm 视频教程目录 SSM视频教程目录 在公众号「帅彬老仙」发送「帅书」领取我写的技术电子书,转载请注明出处: wistbean Prev 搬瓦工官网无法访问,19.9美元一年的服务器没了,使用vultr代替 Next 开始认真地做一个计划