pojo
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Question extends BasePojo {
private Long id;
private Long userId;
//问题内容
private String txt;
}
===========================================================
mapper
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.common.pojo.Question;
public interface QuestionMapper extends BaseMapper {
}
===================================================
service
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.QuestionMapper;
import com.tanhua.common.pojo.Question;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class QuestionService {
@Autowired
private QuestionMapper questionMapper;
public Question queryQuestion(Long userId) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq(“user_id”, userId);
return this.questionMapper.selectOne(queryWrapper);
}
}
===========================================================
App controller
/**
* 查询陌生人问题
*
* @param userId
* @return
*/
@GetMapping(“strangerQuestions”)
public ResponseEntity queryQuestion(@RequestParam(“userId”) Long userId) {
try {
String question = this.tanHuaService.queryQuestion(userId);
return ResponseEntity.ok(question);
} catch (Exception e) {
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
=====================================================
APP service
public String queryQuestion(Long userId) {
Question question = this.questionService.queryQuestion(userId);
if(ObjectUtil.isNotEmpty(question)){
return question.getTxt();
}
//默认的问题
return “你的爱好是什么?”;
}