小编cza*_*dam的帖子

Spring @JsonIgnore无法正常工作

如何让@JsonIgnore工作我有一堂课.即使我把注释放在那里它对输出也没有影响.我在用杰克逊.

public class QuestionBlock implements ComparableByID{


    int ID;

    String title;
    String description;
    boolean deleted;
    boolean isDraft;
    boolean visible;
    Timestamp modifiedDate;
    String modifiedBy;


    private List<Question> questions =  new ArrayList<>();

    @JsonIgnore
    private List<Survey> surveys =  new ArrayList<>();

    ...

    @JsonIgnore
    public List<Survey> getSurveys() {
        return surveys;
    }

    @JsonIgnore
    public void setSurveys(List<Survey> surveys) {
        this.surveys = surveys;
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的Controller方法:

@RequestMapping(value = "/questionBlock/{id}",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public QuestionBlock getQuestionBlock(@PathVariable("id") int id) {
        return surveyService.getQuestionBlock(id);
    }
Run Code Online (Sandbox Code Playgroud)

这是我的servlet-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:beans="http://www.springframework.org/schema/beans" …
Run Code Online (Sandbox Code Playgroud)

java spring jackson

24
推荐指数
4
解决办法
6万
查看次数

Spring:无法将@Transactioanl注释从DAO移动到Service层

事务性注释是在它工作的DAO层中,如果我将它移动到服务层,我会得到异常:

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.adam.czibere.RestAPIController]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

CatalogDAOInterface:

public interface CatalogDAOInterface {

    public List<Product> getAllProduct();

    public List<Category> getAllCategories() ;

    public List<Media> getAllMedias();

}
Run Code Online (Sandbox Code Playgroud)

CatalogDAO的:

@Repository
@SuppressWarnings({"unchecked", "rawtypes"})
public class CatalogDAO implements CatalogDAOInterface {

     @Autowired private SessionFactory sessionFactory;


     @Override
     public List<Product> getAllProduct() {
             Session session = sessionFactory.getCurrentSession();
             List products = session.createQuery("from Product").list();
             return products;
     }

     @Override
     public List<Category> getAllCategories() {
             Session …
Run Code Online (Sandbox Code Playgroud)

spring hibernate spring-mvc transactional

2
推荐指数
1
解决办法
1609
查看次数

标签 统计

spring ×2

hibernate ×1

jackson ×1

java ×1

spring-mvc ×1

transactional ×1