【新增】数据国际化支持
This commit is contained in:
@@ -8,6 +8,8 @@ import com.corewing.app.entity.Course;
|
||||
import com.corewing.app.entity.CourseCategory;
|
||||
import com.corewing.app.service.CourseCategoryService;
|
||||
import com.corewing.app.service.CourseService;
|
||||
import com.corewing.app.util.I18nUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -20,6 +22,7 @@ import java.util.List;
|
||||
*/
|
||||
@RequestMapping("/course")
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class CourseController {
|
||||
|
||||
private final CourseService courseService;
|
||||
@@ -40,8 +43,10 @@ public class CourseController {
|
||||
public Result<List<CourseCategory>> category(
|
||||
@RequestParam(required = false, defaultValue = "0") Integer firstStatus
|
||||
) {
|
||||
log.info("当前语言环境:{}", I18nUtil.getCurrentLocale().getLanguage());
|
||||
LambdaQueryWrapper<CourseCategory> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(firstStatus != 0, CourseCategory::getFirstStatus, firstStatus);
|
||||
wrapper.eq(CourseCategory::getLang, I18nUtil.getCurrentLocale().getLanguage());
|
||||
List<CourseCategory> list = courseCategoryService.list(wrapper);
|
||||
return Result.success(list);
|
||||
}
|
||||
@@ -63,7 +68,7 @@ public class CourseController {
|
||||
@RequestParam(required = false) String courseTitle) {
|
||||
try {
|
||||
Page<Course> page = new Page<>(current, size);
|
||||
IPage<Course> pageResult = courseService.pageList(page, categoryId, courseTitle);
|
||||
IPage<Course> pageResult = courseService.pageList(page, categoryId, courseTitle, I18nUtil.getCurrentLocale().getLanguage());
|
||||
return Result.success(pageResult);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
|
||||
@@ -53,6 +53,11 @@ public class Course implements Serializable {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 语言:中文zh,英文:en
|
||||
*/
|
||||
private String lang;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -51,6 +51,11 @@ public class CourseCategory implements Serializable {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 语言:中文zh,英文:en
|
||||
*/
|
||||
private String lang;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.Param;
|
||||
@Mapper
|
||||
public interface CourseMapper extends BaseMapper<Course> {
|
||||
|
||||
Page<Course> pageList(Page<Course> page, @Param("categoryId") int categoryId, @Param("courseTitle") String courseTitle);
|
||||
Page<Course> pageList(Page<Course> page, @Param("categoryId") int categoryId, @Param("courseTitle") String courseTitle, @Param("lang") String lang);
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.corewing.app.entity.Course;
|
||||
|
||||
public interface CourseService extends IService<Course> {
|
||||
IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle);
|
||||
IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle, String lang);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle) {
|
||||
return courseMapper.pageList(page, categoryId, courseTitle);
|
||||
public IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle, String lang) {
|
||||
return courseMapper.pageList(page, categoryId, courseTitle, lang);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,12 @@
|
||||
left join app_course_category cc on cc.id = ccr.category_id
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="pageList" resultMap="VOResultMap">
|
||||
<include refid="selectVOSql"/>
|
||||
<where>
|
||||
c.status = 1
|
||||
and c.lang = #{lang}
|
||||
<if test="categoryId != null and categoryId != 0">
|
||||
AND cc.id = #{categoryId}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user