这是Java Service类第一次无法正常运行,我不知道原因。
我有超过20个服务类,除此之外的所有服务类都完美无缺:
package it.jack.fdd.services;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import it.jack.fdd.dao.FactoryDao;
import it.jack.fdd.domain.Feedback;
import it.jack.fdd.domain.Staff;
import it.jack.fdd.domain.StaffType;
import it.jack.fdd.dto.StaffDto;
import it.jack.fdd.dto.StaffTypeDto;
import it.jack.fdd.dto.TokenStaffDto;
import it.jack.fdd.util.ConverterDTO;
@Path("/feedback")
public class FeedbackServices {
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Feedback> getFeedback() {
List<Feedback> listOfFeedback = FactoryDao.getIstance().createBaseDao().getAll(Feedback.class);
return listOfFeedback;
}
@GET
@Path("/notread")
@Produces(MediaType.APPLICATION_JSON)
public List<Feedback> getFeedbackNoRead(@HeaderParam("token") String token) {
TokenStaffDto ts = new TokenStaffDto();
StaffDto s = new StaffDto();
StaffTypeDto st = new StaffTypeDto();
Boolean ex = FactoryDao.getIstance().createTokenStaffDao().getExistence(token);
ts = ConverterDTO.converterTokenStafftoDTO(FactoryDao.getIstance().createTokenStaffDao().getTokenStaffFromToken(token));
s = ConverterDTO.converterStafftoDTO((Staff) FactoryDao.getIstance().createBaseDao().getById(ts.getIdtokenStaff(), Staff.class));
st = ConverterDTO.converterStaffTypetoDTO( (StaffType) FactoryDao.getIstance().createBaseDao().getById(s.getStaffType().getIdstaffType(),
StaffType.class));
if (ex && st.getIdstaffType() == 1) {
List<Feedback> listOfFeedback = FactoryDao.getIstance().createFeedbackDao().notRead();
return listOfFeedback;
}else
return null;
}
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Object getFeedbackById(@PathParam("id") int id, @HeaderParam("token") String token) {
TokenStaffDto ts = new TokenStaffDto();
StaffDto s = new StaffDto();
StaffTypeDto st = new StaffTypeDto();
Boolean ex = FactoryDao.getIstance().createTokenStaffDao().getExistence(token);
ts = ConverterDTO.converterTokenStafftoDTO(FactoryDao.getIstance().createTokenStaffDao().getTokenStaffFromToken(token));
s = ConverterDTO.converterStafftoDTO((Staff) FactoryDao.getIstance().createBaseDao().getById(ts.getIdtokenStaff(), Staff.class));
st = ConverterDTO.converterStaffTypetoDTO( (StaffType) FactoryDao.getIstance().createBaseDao().getById(s.getStaffType().getIdstaffType(),
StaffType.class));
if (ex && st.getIdstaffType() == 1) {
return FactoryDao.getIstance().createBaseDao().getById(id, Feedback.class);
}else
return null;
}
@POST
@Produces(MediaType.APPLICATION_JSON)
public int addFeedback(Feedback feedback/*, @HeaderParam("token") String token*/) {
return FactoryDao.getIstance().createBaseDao().save(feedback);
}
@PUT
@Produces(MediaType.APPLICATION_JSON)
public void updateFeedback(Feedback feedback) {
FactoryDao.getIstance().createBaseDao().update(feedback);
}
}
除了@PUT和@POST之外,所有这些方法都能很好地工作。实际上@GET方法有效。我关于这个类的域类称为“Feedback.java”:
package it.jack.fdd.domain;
// Generated 30-nov-2016 0.17.09 by Hibernate Tools 4.3.1.Final
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* Feedback generated by hbm2java
*/
@Entity
@Table(name = "feedback", catalog = "fdd_dbproducts")
public class Feedback implements java.io.Serializable {
private Integer idfeedback;
private User user;
private String message;
private boolean read;
public Feedback() {
}
public Feedback(User user, String message, boolean read) {
this.user = user;
this.message = message;
this.read = read;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "idfeedback", unique = true, nullable = false)
public Integer getIdfeedback() {
return this.idfeedback;
}
public void setIdfeedback(Integer idfeedback) {
this.idfeedback = idfeedback;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fkuser_feedback", nullable = false)
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
@Column(name = "message", nullable = false, length = 45)
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
@Column(name = "read", nullable = false)
public boolean isRead() {
return this.read;
}
public void setRead(boolean read) {
this.read = read;
}
}
这是我的工厂类叫FactoryDao:
package it.jack.fdd.dao;
import it.jack.fdd.dao.impl.AccTypeDaoImpl;
import it.jack.fdd.dao.impl.BaseDaoImpl;
import it.jack.fdd.dao.impl.CapacityDaoImpl;
import it.jack.fdd.dao.impl.CategoryDaoImpl;
import it.jack.fdd.dao.impl.DispenserDaoImpl;
import it.jack.fdd.dao.impl.FamilyDaoImpl;
import it.jack.fdd.dao.impl.FeedbackDaoImpl;
import it.jack.fdd.dao.impl.GeoAreaDaoImpl;
import it.jack.fdd.dao.impl.IndustryDaoImpl;
//import it.jack.fdd.dao.impl.InnerDaoImpl;
import it.jack.fdd.dao.impl.ProducerDaoImpl;
import it.jack.fdd.dao.impl.ProductDaoImpl;
import it.jack.fdd.dao.impl.ProductDescDaoImpl;
import it.jack.fdd.dao.impl.RtDispenserCategoryDaoImpl;
import it.jack.fdd.dao.impl.RtFamilyProductDaoImpl;
import it.jack.fdd.dao.impl.RtIngredientProductDaoImpl;
import it.jack.fdd.dao.impl.RtStaffDispenserDaoImpl;
import it.jack.fdd.dao.impl.StaffDaoImpl;
import it.jack.fdd.dao.impl.StaffLoginDaoImpl;
import it.jack.fdd.dao.impl.StaffTypeDaoImpl;
import it.jack.fdd.dao.impl.TokenStaffDaoImpl;
import it.jack.fdd.dao.interfaces.AccTypeDao;
import it.jack.fdd.dao.interfaces.BaseDao;
import it.jack.fdd.dao.interfaces.CapacityDao;
import it.jack.fdd.dao.interfaces.CategoryDao;
import it.jack.fdd.dao.interfaces.DispenserDao;
import it.jack.fdd.dao.interfaces.FamilyDao;
import it.jack.fdd.dao.interfaces.FeedbackDao;
import it.jack.fdd.dao.interfaces.GeoAreaDao;
import it.jack.fdd.dao.interfaces.IndustryDao;
//import it.jack.fdd.dao.interfaces.InnerDao;
import it.jack.fdd.dao.interfaces.ProducerDao;
import it.jack.fdd.dao.interfaces.ProductDao;
import it.jack.fdd.dao.interfaces.ProductDescDao;
import it.jack.fdd.dao.interfaces.RtDispenserCategoryDao;
import it.jack.fdd.dao.interfaces.RtFamilyProductDao;
import it.jack.fdd.dao.interfaces.RtIngredientProductDao;
import it.jack.fdd.dao.interfaces.RtStaffDispenserDao;
import it.jack.fdd.dao.interfaces.StaffDao;
import it.jack.fdd.dao.interfaces.StaffLoginDao;
import it.jack.fdd.dao.interfaces.StaffTypeDao;
import it.jack.fdd.dao.interfaces.TokenStaffDao;
public class FactoryDao {
//SINGLETON
private FactoryDao() {
}
static class Holder {
static public final FactoryDao ISTANCE = new FactoryDao();
}
private BaseDao basedao = new BaseDaoImpl();
private DispenserDao dispenserdao = new DispenserDaoImpl();
private GeoAreaDao geoareadao = new GeoAreaDaoImpl();
private ProductDao productdao = new ProductDaoImpl();
private RtIngredientProductDao rtingredientproductdao = new RtIngredientProductDaoImpl();
private StaffDao staffdao = new StaffDaoImpl();
private StaffLoginDao stafflogindao = new StaffLoginDaoImpl();
private StaffTypeDao stafftypedao = new StaffTypeDaoImpl();
private TokenStaffDao tokenstaffdao = new TokenStaffDaoImpl();
private ProductDescDao productdescdao = new ProductDescDaoImpl();
private ProducerDao producerdao = new ProducerDaoImpl();
private FamilyDao familydao = new FamilyDaoImpl();
private RtFamilyProductDao rtfamilyproductdao = new RtFamilyProductDaoImpl();
private CategoryDao categorydao = new CategoryDaoImpl();
private RtDispenserCategoryDao rtdispensercategorydao = new RtDispenserCategoryDaoImpl();
private RtStaffDispenserDao rtstaffdispenserdao = new RtStaffDispenserDaoImpl();
private IndustryDao industrydao = new IndustryDaoImpl();
private CapacityDao capacitydao = new CapacityDaoImpl();
private AccTypeDao acctypedao = new AccTypeDaoImpl();
private FeedbackDao feedbackdao = new FeedbackDaoImpl();
public BaseDao createBaseDao(){
return basedao;
}
public DispenserDao createDispenserDao(){
return dispenserdao;
}
public GeoAreaDao createGeoAreaDao(){
return geoareadao;
}
public ProductDao createProductDao(){
return productdao;
}
public RtIngredientProductDao createRtIngredientProductDao(){
return rtingredientproductdao;
}
public StaffDao createStaffDao(){
return staffdao;
}
public StaffLoginDao createStaffLoginDao(){
return stafflogindao;
}
public StaffTypeDao createStaffTypeDao(){
return stafftypedao;
}
public TokenStaffDao createTokenStaffDao(){
return tokenstaffdao;
}
public ProductDescDao createProductDescDao(){
return productdescdao;
}
public ProducerDao createProducerDao(){
return producerdao;
}
public FamilyDao createFamilyDao(){
return familydao;
}
public RtFamilyProductDao createRtFamilyProductDao(){
return rtfamilyproductdao;
}
public CategoryDao createCategoryDao(){
return categorydao;
}
public RtDispenserCategoryDao createRtDispenserCategoryDao(){
return rtdispensercategorydao;
}
public RtStaffDispenserDao createRtStaffDispenserDao(){
return rtstaffdispenserdao;
}
public IndustryDao createIndustryDao(){
return industrydao;
}
public CapacityDao createCapacityDao(){
return capacitydao;
}
public AccTypeDao createAccTypeDao(){
return acctypedao;
}
public FeedbackDao createFeedbackDao(){
return feedbackdao;
}
public static FactoryDao getIstance() {
return Holder.ISTANCE;
}
}
(我不需要包含基于实现的方法更新和插入,就像其他类一样工作)
例如,我尝试了我的GET METHOD,我有这个JSON文件:
[
{
"idfeedback": 1,
"user": {
"iduser": 1,
"name": "Andrea",
"surname": "Pirlo",
"birthDate": "1980-12-12",
"cityResidence": "Cannole",
"provinceResidence": "Lecce",
"postalCode": "73020",
"gender": true,
"bankAccounts": [],
"userLogin": {
"iduserLogin": 1,
"email": "ciao96@libero.it",
"pass": "asdasd5sada5adsdsadasdas6dsa6da5dadad",
"tokenUser": null
}
},
"message": "migliorare controlli",
"read": false
},
{
"idfeedback": 2,
"user": {
"iduser": 1,
"name": "Andrea",
"surname": "Pirlo",
"birthDate": "1980-12-12",
"cityResidence": "Cannole",
"provinceResidence": "Lecce",
"postalCode": "73020",
"gender": true,
"bankAccounts": [],
"userLogin": {
"iduserLogin": 1,
"email": "ciao96@libero.it",
"pass": "asdasd5sada5adsdsadasdas6dsa6da5dadad",
"tokenUser": null
}
},
"message": "sdfsdf",
"read": false
}
]
我想以这种方式编辑第一项:
{
"idfeedback": 1,
"user": {
"iduser": 1,
"name": "Andrea",
"surname": "Pirlo",
"birthDate": "1980-12-12",
"cityResidence": "Cannole",
"provinceResidence": "Lecce",
"postalCode": "73020",
"gender": true,
"bankAccounts": [],
"userLogin": {
"iduserLogin": 1,
"email": "ciao96@libero.it",
"pass": "asdasd5sada5adsdsadasdas6dsa6da5dadad",
"tokenUser": null
}
},
"message": "update",
"read": true
}
我不明白是什么原因。
答案 0 :(得分:0)
解决。问题是因为&#34;读&#34;。 &#34;读&#34;也是mySql的系统变量。解决了重命名问题