DWQA QuestionsCategory: DatabaseSSM Dao layer no return function never exits
Creams asked 1 month ago

In the SSM project, the service calls Dao interface function, but it has not returned the function and has not exited. The code below is to see if there is a problem with the code

  • Controller
            List<String> todayClass = courseService.QueryDaytableById(user.getUsername());
            session.setAttribute("todaytable", todayClass);
            return "success";
  • Service
public List<String> QueryDaytableById(String username){
        SimpleDateFormat sdf = new SimpleDateFormat("E", Locale.ENGLISH);
        Date date = new Date();
        String day = sdf.format(date).toLowerCase();
        log.info ("get" + username + "-" + day + "course schedule");
        return coursetableDao.QueryDaytableById(day, username);
  • Dao interface
    List<String> QueryDaytableById(String day, String username);
  • Mapper
        <select id="QueryDaytableById" parameterType="String" resultType="String">
        SELECT #{day} FROM coursetable WHERE studentid=#{username}

The problem now is that the controller successfully calls the method of service (which is also recorded in the log), but the method of service calling Dao is not finished, which results in the controller list < string > todayclass= courseService.QueryDaytableById ( user.getUsername (); sentence has not been completed on the card here, please see where I write wrong, open heart study

3 Answers
Good answered 1 month ago

Before return in the service class, print it coursetableDao.QueryDaytableById (day, username);
Then use log4j to print whether the SQL is correct
Select {0} from coursetable where studentID = {1} have a try

Creams replied 1 month ago

Printing coursetableDao.QueryDaytableById (day, username); no displayHowever, there is no way to change the data to SQL

Good replied 1 month ago

What about {0} and {1} is that there is a problem when the data is transferred to the mapper

Lower beam answered 1 month ago

Why is byid name

hede answered 1 month ago

List<String> QueryDaytableById(@Param(“day”) String day,@Param(“username”) String username);
<select id=”QueryDaytableById” resultType=”String”>

SELECT #{day} FROM coursetable WHERE studentid=#{username}
 Or use an object to receive parameters
Creams replied 1 month ago

Hello, I wrote according to what you said can run, but returned the content that does not exist in the database. Do you know what’s going on