我正在尝试添加一个带有自动增量的主键.
我已经阅读了一些文档和其他问题 - 有SERIAL和nextval()声明,但它不起作用.
这是我做的:
CREATE TABLE IF NOT EXISTS "category" (
"id" integer SERIAL PRIMARY KEY,
"name" varchar(30) DEFAULT NULL
); // the error near "SERIAL"
Run Code Online (Sandbox Code Playgroud)
和
CREATE SEQUENCE your_seq;
CREATE TABLE IF NOT EXISTS "category" (
"id" integer PRIMARY KEY nextval('your_seq'),
"name" varchar(30) DEFAULT NULL
); // the error near 'nextval'
Run Code Online (Sandbox Code Playgroud)
我错了什么?我只想将主键增加1.
Thymeleaf有许多有用的工具,如#strings.capitalize(...)或#lists.isEmpty(...).我正在尝试添加自定义但不知道如何注册.
制作了一个自定义的Util类:
public class LabelUtil {
public String[] splitDoubleWord(String str) {
return str.split("[A-Z]", 1);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我要像这样使用它:
<span th:each="item : ${#labels.splitDoubleWord(name)}" th:text="${item}"></span>
Run Code Online (Sandbox Code Playgroud)
当然,它不起作用,因为我没有注册Util并定义了#labelsvar.
那么,问题是如何以及在何处进行呢?
我正在做我的第一个Java EE项目,我想要进行测试.我搜索并发现自EJB 3.1以来,可以使用嵌入式EJB容器来测试业务层.我正在使用WildFly,但我还没有找到如何配置嵌入式容器.
那么,如何正确配置嵌入式容器并使用WildFly测试EJB 3.1+?
我感谢任何帮助!
当我在chrome mobile v48中打开我的网站时,我发现该box-shadow: 1px属性表现得很奇怪:阴影的宽度从一侧到另一侧浮动并且不一样.我假设它是因为分数设备像素比率1.5:
下一个代码片段并不总是给我所需的1px阴影,但它1-3px有时在移动浏览器上浮动:
div {
margin: 10px;
height: 10px;
padding: 20px;
width: 40%;
box-shadow: 0 0 1px #000;
}
...
<div></div>
<div></div>
Run Code Online (Sandbox Code Playgroud)
我试过使用-webkit前缀但没有任何改变.使用替代单位em而不是px一个单位值就像0.5px.
该viewportmeta标签,似乎还不够:
<meta name="viewport" content="width=device-width, initial-scale=1">
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题,让box-shadow属性在移动浏览器上正确显示?
我已经对servlet进行了基本测试,以测试它的响应状态代码,但它不起作用 - 它总是为0,尽管我已经将servlet中的响应状态代码设置为200.
public class TestMyServlet extends Mockito {
@Test
public void test() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getParameter("test")).thenReturn("1");
new MyServlet().doPost(request, response);
System.out.println(response.isCommited()); // false
System.out.println(response.getContentType()); // null
System.out.println(response.getStatus()); // 0
}
}
Run Code Online (Sandbox Code Playgroud)
怎么让这个工作?
有一个非常轻的Spring Boot 1.4项目,由start.spring.io生成.
尝试使用@RestControllerwith @RequestBody进行集成测试TestRestTemplate,但由于启动异常而没有成功.
唯一的配置类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
application.properties除了security.ignored=/**测试目的外,配置文件几乎没有任何内容.
测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
public class MyControllerTest {
private Logger log = Logger.getLogger(getClass());
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private TestEntityManager entityManager;
@Before
public void init() {
log.info("Initializing...");
}
@Test
public void addTest() throws Exception {
log.info("MyController add test starting...");
// restTemplate usage
log.info("MyController add test passed");
}
} …Run Code Online (Sandbox Code Playgroud) 执行许多Angular CLI命令以构建缩小的基本项目:
ng new project
cd project
ng build --prod
Run Code Online (Sandbox Code Playgroud)
...结果,我得到了dist包含许多包的生成文件夹.最大的一个叫做vendor.[hash].js它的大小855kB.
但是,如果我ng serve --prod改为执行:
ng new project
cd project
ng serve --prod
Run Code Online (Sandbox Code Playgroud)
...我可以看到localhost:4200供应商的捆绑重量是关于300kB使用Chrome控制台的.
为什么会这样?有没有办法实现第二个结果,ng serve而不是ng build?
我正在寻找线程安全的 Servlet 替代方案,我发现了 JAX-RS 技术。
那么我可以像这样在它的类中使用实例变量吗(它是线程安全的):
@Path("helloworld")
public class HelloWorldResource {
private String msg;
@GET
public void doSmth() {
this.msg = "test";
}
}
Run Code Online (Sandbox Code Playgroud)
?
构建一个拒绝未修剪的输入字符串的表达式.
有一组列入白名单的符号,包括空格.但它不能在第一个或最后一个位置使用.但是,它可以在任何数量的任何前导和修剪白名单之间使用.
有以下表达式:
^[^\s][A-Za-z0-9\s]*[^\s]$
Run Code Online (Sandbox Code Playgroud)
...但它有多种原因无效,至少它仍然在前导位置和尾随位置匹配任何非空白符号,即使它不是白名单.此外,即使它与表达式匹配,也不会匹配单个字母单词.
白名单是AZ,az,0-9,空格.
有效案例:
Abc132 3sdfas // everything ok
Run Code Online (Sandbox Code Playgroud)
案例#1无效:
asd dsadas // leading\trailing space is exist
Run Code Online (Sandbox Code Playgroud)
案例#2无效:
$das dsfds // not whitelisted symbol at the leading\trailing position
Run Code Online (Sandbox Code Playgroud)
那么,如果它不是前导符号或尾随符号,如何在白名单中添加空白符号?
我正在使用Postgres 9.2,hibernate 4.3.0 final.
我有testClass:
@Entity
@Table(name="testClass")
public class testClass implements Serializable {
@Id
@Column(name = "id")
private Integer id;
@Column(name="name")
private String name;
public Integer getId() {
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
从另一个类的方法创建:
try {
new Configuration().configure("/hibernate.cfg.xml");
new testClass();
} catch(Exception e) {
System.out.println(e);
}
Run Code Online (Sandbox Code Playgroud)
这是我的hibernate.xml.cfg:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="postgres">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="testClass"/>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
它在jboss服务器端执行:
[2014-01-06 …Run Code Online (Sandbox Code Playgroud)