嗨,我使用的是Spring引导和Spring数据,我希望根据id从数据库中获取数据,但是我无法检索它.M得到此错误"异常":
"org.springframework.dao.InvalidDataAccessApiUsageException", "消息":"org.hibernate.hql.internal.QueryExecutionRequestException:不支持DML操作[更新com.ge.health.poc.model.SpringModel SET NAME = '斯纳',其中?ID =];嵌套的例外是java.lang.IllegalStateException:org.hibernate.hql.internal.QueryExecutionRequestException:不支持DML操作[更新com.ge.health.poc.model.SpringModel SET NAME = '斯纳' 其中id =?]","path":"/ updatedata"}
主类
package com.ge.health.poc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringDataApplication {
public static void main(String[] args) {
SpringApplication.run(SpringDataApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器类
package com.ge.health.poc.controller;
import java.io.IOException;
import java.text.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ge.health.poc.model.SpringModel;
import com.ge.health.poc.service.BookServiceImpl;
@RestController
public class SpringController {
@Autowired
BookServiceImpl bookserviceimpl;
@RequestMapping(value = …Run Code Online (Sandbox Code Playgroud) 我是 JUnit 测试的新手。你能告诉我如何对 void 方法进行 Junit 测试吗?
我有这个类DemoPublisher和这个demoPublishMessage()返回类型为void的方法。我如何测试这种方法?
package com.ge.health.gam.poc.publisher;
import javax.jms.JMSException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ge.health.gam.poc.consumer.DemoConsumer;
@Component
public class DemoPublisher {
@Autowired
JmsTemplate jmsTemplate;
public void demoPublishMessage(String message) throws JMSException{
jmsTemplate.convertAndSend("NewQueue", message);
System.out.println("Message sent");
}
}
Run Code Online (Sandbox Code Playgroud)