如何用百里香叶在td中设置颜色?

时间:2017-11-04 23:27:34

标签: spring spring-mvc spring-boot thymeleaf

我试过import java.awt.EventQueue; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class Test { public static void main(String[] args) { new Test(); } public Test() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Controller manager = new Controller() { @Override public void show(JPanel pane) { frame.getContentPane().removeAll(); frame.getContentPane().add(pane); frame.getContentPane().revalidate(); frame.getContentPane().repaint(); } }; JMenuBar menuBar = new JMenuBar(); JMenu options = new JMenu("Options"); menuBar.add(options); options.add(new SomeOptionsAction(manager)); options.add(new SomeOtherOptionsAction(manager)); frame.setJMenuBar(menuBar); frame.setSize(200, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } public interface Controller { public void show(JPanel pane); } public abstract class AbstractManagerAction extends AbstractAction { private Controller controller; private JPanel panel; public AbstractManagerAction(Controller controller, JPanel panel) { this.controller = controller; this.panel = panel; } @Override public void actionPerformed(ActionEvent e) { controller.show(panel); } } public class SomeOptionsAction extends AbstractManagerAction { public SomeOptionsAction(Controller controller) { super(controller, new SomeOptionsPane()); putValue(NAME, "Some options"); } } public class SomeOptionsPane extends JPanel { public SomeOptionsPane() { setLayout(new GridBagLayout()); add(new JLabel("Some options")); } } public class SomeOtherOptionsAction extends AbstractManagerAction { public SomeOtherOptionsAction(Controller manager) { super(manager, new SomeOtherOptionsPane()); putValue(NAME, "Some other options"); } } public class SomeOtherOptionsPane extends JPanel { public SomeOtherOptionsPane() { setLayout(new GridBagLayout()); add(new JLabel("Some other options")); } } } ,然后将TD的颜色设置为红色:

<%= f.select :document_id, entry.documents, include_blank: true %>

但发生了这种情况

object.qtdItem == 0

3 个答案:

答案 0 :(得分:0)

三元语句需要else条款,例如

<td th:style="${obj.qtdItem == 0 ? 'color: red;' : 'color: some_other_color;'}}" th:text="${obj.text}"></td>

答案 1 :(得分:0)

另一种选择:

th:style="${obj.qtdItem == 0} ? ${'color: red;'}"

答案 2 :(得分:0)

这对我有用。

th:style="|${obj.qtdItem == 'red' ? 'color: red;' : 'color: green;'}|"