The output content of calling dao through spring is null

The content output by Dao is the data
service injected by the method itself from spring

public class userService {
    
    
    private userDao userdao;
    private String st;
 public void show() throws UnsupportedEncodingException {
    
    
        String st2=new String(st.getBytes("iso8859-1"),"utf-8");
        new userDao().show(st2);
        System.out.println("server...run......");
        System.out.println("service say:"+st);

    }

Here is dao. The first output statement of
dao is obtained from spring. Since the previous call of dao was wrongly called by new userDao, it
was not read into spring without creating dao through spring. Value
so the output result is null

public class userDao {
    
    
    private  String s;

    public String getS() {
    
    
        return s;
    }

    public void setS(String s) {
    
    
        this.s = s;
    }

    public void show(String st) throws UnsupportedEncodingException {
    
    
    System.out.println("dao..say:"+s);
    st=new String(st.getBytes("iso8859-1"),"utf-8");
        System.out.println(st);
}
}

Change the call in servrice to call through member variables, it will successfully create dao through spring to complete the injection value and output normal content

 public void show() throws UnsupportedEncodingException {
    
    
        String st2=new String(st.getBytes("iso8859-1"),"utf-8");
        userdao.show(st2);
        System.out.println("server...run......");
        System.out.println("service say:"+st);

    }

Guess you like

Origin blog.csdn.net/m0_49194578/article/details/112548649