后台代码:
package cn.id5.controller.report;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
@Qualifier("htmlTemplateEngine")
private TemplateEngine htmlTemplateEngine;
@RequestMapping(value = "/list", method = {RequestMethod.GET})
public String query() throws IOException {
final List<Product> allProducts = new ArrayList<Product>();
Product p1 = new Product();
p1.setId(1);
p1.setInStock(true);
p1.setName("sss");
p1.setPrice(100);
allProducts.add(p1);
final Context ctx = new Context(null);
ctx.setVariable("prods", allProducts);
String s = "<table><thead><tr><th>NAME</th><th>PRICE</th><th>STOCK</th></tr></thead>"+
" <tbody>" +
" <tr th:each=\"prod : ${prods}\&