Merge remote-tracking branch 'origin/书籍中心zgj' into 书籍中心zgj

书籍中心zgj
zgj 8 months ago
commit 5a2e38449e

@ -10,26 +10,58 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
// @SpringBootApplication是一个组合注解它整合了多个Spring相关的注解例如
// @Configuration表明这个类可以作为一个配置类用于定义Spring容器中的Bean等配置信息。
// @EnableAutoConfiguration启用Spring Boot的自动配置功能会根据项目依赖等情况自动配置很多默认的组件比如数据源、Web相关配置等大大简化了项目的配置过程。
// @ComponentScan用于指定Spring要扫描的组件所在的包路径默认会扫描当前类所在的包及其子包下的所有标注了Spring相关组件注解如@Component、@Service、@Controller等的类并将它们注册到Spring容器中以便进行依赖注入等操作。
// 这个注解标注在类上意味着这是一个Spring Boot应用的主启动类整个应用从这里开始启动并加载相关配置。
@SpringBootApplication
public class Application {
/**
* JavaSpring BootSpringApplicationBuilderSpring Boot
* SpringApplicationBuilderSpring BootApplication
* @SpringBootApplicationApplicationSpring
*
* @param args 使
*/
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).run(args);
}
/**
* FastJsonJackson
* @return
* FastJSONHttpMessageConverterSpring BootHTTPJSON使FastJSONJacksonJSON
* @BeanSpringBeanSpring便HTTP使
*
* @return HttpMessageConvertersFastJsonHttpMessageConverterSpring BootWebJSON
*/
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
// 创建一个FastJsonHttpMessageConverter实例它是Spring中用于将对象转换为JSON格式以及将JSON数据反序列化为对象的一个实现类
// 这里我们要使用FastJSON的功能所以创建它的实例来进行后续配置使其能按照我们期望的方式处理JSON数据转换。
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
// 创建一个FastJsonConfig对象用于配置FastJSON的各种序列化和反序列化相关的参数、特性等以便让FastJSON按照我们的业务需求来处理JSON数据。
FastJsonConfig fastJsonConfig = new FastJsonConfig();
// 设置FastJSON序列化日期类型数据时的日期格式这里指定为"yyyy-MM-dd HH:mm:ss"这样在将包含日期属性的Java对象序列化为JSON字符串时日期字段会按照这个格式进行展示
// 使得前端或者其他调用方接收到的日期格式更加规范和统一,便于处理和展示。
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
// 设置FastJSON的序列化特性SerializerFeature.DisableCircularReferenceDetect表示禁用循环引用检测
// 当Java对象之间存在复杂的相互引用关系时如果不进行处理在序列化过程中可能会陷入死循环或者生成不符合预期的JSON结构
// 通过禁用这个检测具体根据业务场景如果确定不会出现循环引用问题或者有其他处理方式时可以这样设置可以按照一定的规则来处理这种引用关系生成期望的JSON数据。
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
// 将配置好的FastJsonConfig对象设置到FastJsonHttpMessageConverter中这样FastJsonHttpMessageConverter在进行JSON序列化和反序列化操作时
// 就会按照我们配置好的FastJsonConfig中的参数和特性来进行处理了。
fastConverter.setFastJsonConfig(fastJsonConfig);
// 这里再次将fastConverter赋值给converter变量其实是多余的操作因为前面已经完成了配置可以直接使用fastConverter变量不过这并不影响整体功能只是代码上有些冗余。
FastJsonHttpMessageConverter converter = fastConverter;
// 创建并返回一个HttpMessageConverters对象将配置好的FastJsonHttpMessageConverter作为参数传入
// 这样Spring Boot在处理HTTP消息时就会识别到这个自定义的消息转换器并使用它来进行JSON相关的数据转换了。
return new HttpMessageConverters(converter);
}
}
}

@ -15,69 +15,154 @@ import com.tamguo.modules.tiku.model.ChapterEntity;
import com.tamguo.modules.tiku.model.condition.ChapterCondition;
import com.tamguo.modules.tiku.service.IChapterService;
// 使用 @Controller 注解将该类标记为 Spring MVC 中的控制器类,表明它主要负责处理与题库章节相关的 Web 请求,
// 通过调用对应的业务逻辑层IChapterService的方法实现诸如章节信息的查询、添加、修改、删除以及以不同格式返回章节相关数据如列表、树形结构数据等等操作
// 是系统中题库章节功能模块在 Web 层面交互的核心组件。
@Controller
@RequestMapping(path="tiku/chapter")
public class {
// 通过 @RequestMapping 注解为该控制器类下的所有请求路径设置一个公共的前缀,意味着此类中定义的所有请求处理方法对应的路径都是以 "tiku/chapter" 开头,
// 便于对题库章节相关的众多请求进行统一管理和分类,使代码结构更加清晰有条理。
@RequestMapping(path = "tiku/chapter")
public class ChapterController { // 这里类名缺失推测应该是ChapterController补上使其完整
// 定义新增章节页面的视图名称,按照 Spring MVC 视图解析机制,这个字符串对应着实际存放新增章节相关展示内容的模板文件路径(比如可能是 JSP、Thymeleaf 等模板文件所在的路径),
// 用于在添加新章节时向用户展示相应的操作界面,引导用户输入章节相关信息。
private final String ADD_CHAPTER_PAGE = "modules/tiku/chapter/add";
// 定义修改章节页面的视图名称,对应展示修改章节已有信息相关内容的模板文件路径,
// 在这个页面上,用户可以对已存在的章节记录进行编辑修改操作,比如更新章节名称、所属上级章节等信息。
private final String UPDATE_CHAPTER_PAGE = "modules/tiku/chapter/update";
// 通过 @Autowired 注解自动注入 IChapterService 接口的实现类实例IChapterService 接口应该定义了一系列用于处理题库章节相关业务逻辑的方法,
// 例如查询章节详细信息、保存新章节、更新章节已有信息、删除章节以及获取章节的树形结构数据等功能,
// 借助这个注入的实例,本控制器类可以方便地与业务逻辑层交互,调用相应方法来完成各种题库章节相关的业务操作。
@Autowired
private IChapterService iChapterService;
@RequestMapping(path="add",method=RequestMethod.GET)
public ModelAndView add(String parentChapterId , ModelAndView model) {
ChapterEntity parentChapter = iChapterService.selectById(parentChapterId);
model.addObject("parentChapter", parentChapter);
/**
* "tiku/chapter/add" GET使
*
* @param parentChapterId
* 便
* @param model ModelAndView
* 便
* @return ADD_CHAPTER_PAGE ModelAndView Spring MVC
*/
@RequestMapping(path = "add", method = RequestMethod.GET)
public ModelAndView add(String parentChapterId, ModelAndView model) {
// 通过调用 iChapterService 的 selectById 方法,依据传入的 parentChapterId 参数,从数据库等数据源中查询出对应的上级章节对象,
// 目的是在新增章节页面上展示新增章节所属的上级章节信息,方便用户知晓章节层级关系以及可能进行一些关联设置(比如继承上级章节的部分属性等情况,具体取决于业务需求)。
ChapterEntity parentChapter = iChapterService.selectById(parentChapterId);
model.addObject("parentChapter", parentChapter);
// 设置返回的视图名称为新增章节页面的视图名称ADD_CHAPTER_PAGE以便 Spring MVC 依据此名称找到对应的模板文件进行页面渲染展示,
// 从而向客户端呈现新增章节的操作界面。
model.setViewName(ADD_CHAPTER_PAGE);
return model;
}
@RequestMapping(path="update" , method=RequestMethod.GET)
public ModelAndView update(String id , ModelAndView model) {
/**
* "tiku/chapter/update" GET便
*
* @param id
* 便
* @param model ModelAndView
* 使便
* @return UPDATE_CHAPTER_PAGE ModelAndView Spring MVC
*/
@RequestMapping(path = "update", method = RequestMethod.GET)
public ModelAndView update(String id, ModelAndView model) {
// 通过调用 iChapterService 的 selectById 方法,依据传入的 id 参数,从数据库等数据源中查询出要修改的章节对象,
// 以便在修改页面上展示该章节的当前信息,供用户查看并确定要修改的具体内容。
ChapterEntity chapter = iChapterService.selectById(id);
// 接着再次调用 iChapterService 的 selectById 方法依据查询到的章节对象中存储的上级章节编号chapter.getParentCode()),查询出对应的上级章节对象,
// 这么做是为了在修改章节页面上同时展示出该章节所属的上级章节信息,方便用户参考上级章节情况来进行合理的章节信息修改,比如章节层级调整等操作(具体取决于业务需求)。
ChapterEntity parentChapter = iChapterService.selectById(chapter.getParentCode());
model.addObject("chapter", chapter);
model.addObject("parentChapter", parentChapter);
// 设置要返回的视图名称为修改章节页面的视图名称UPDATE_CHAPTER_PAGE使得 Spring MVC 能根据这个名称找到对应的模板文件进行渲染展示,
// 进而向客户端呈现修改章节信息的操作页面。
model.setViewName(UPDATE_CHAPTER_PAGE);
return model;
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "tiku/chapter/listData" POST
*
* @param condition ChapterCondition
*
* @return ChapterEntity List 使
* iChapterService
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public List<ChapterEntity> listData(ChapterCondition condition) {
return iChapterService.listData(condition);
}
@RequestMapping(path="treeData")
/**
* "tiku/chapter/treeData" 便 JSONArray便 JSON
*
* @param courseId
*
* @param excludeId
*
* @return JSONArray iChapterService treeData
* 便
*/
@RequestMapping(path = "treeData")
@ResponseBody
public JSONArray treeData(String courseId , String excludeId) {
return iChapterService.treeData(courseId , excludeId);
public JSONArray treeData(String courseId, String excludeId) {
return iChapterService.treeData(courseId, excludeId);
}
@RequestMapping(path="save")
/**
* "tiku/chapter/save"
* JSON
*
* @param chapter ChapterEntity
*
* @return Result Result result 0 便 chapter.getName() Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "save")
@ResponseBody
public Result save(ChapterEntity chapter) {
try {
iChapterService.save(chapter);
return Result.result(0, null, "章节【"+chapter.getName()+"】添加成功!");
return Result.result(0, null, "章节【" + chapter.getName() + "】添加成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("保存章节", this.getClass(), e);
}
}
@RequestMapping(path="update")
/**
* "tiku/chapter/update" GET POST POST
*
* JSON
*
* @param chapter ChapterEntity
*
* @return Result Result result 0 便 chapter.getName() Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(ChapterEntity chapter) {
try {
iChapterService.update(chapter);
return Result.result(0, null, "章节【"+chapter.getName()+"】修改成功!");
return Result.result(0, null, "章节【" + chapter.getName() + "】修改成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改章节", this.getClass(), e);
}
}
@RequestMapping(path="delete" , method=RequestMethod.POST)
/**
* "tiku/chapter/delete" POSTid
* JSON
*
* @param id
* @return Result Result result 0 Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(String id) {
try {
@ -87,4 +172,4 @@ public class {
return ExceptionSupport.resolverResult("删除章节", this.getClass(), e);
}
}
}
}

@ -19,38 +19,93 @@ import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum;
import com.tamguo.modules.tiku.service.ICourseService;
import com.tamguo.modules.tiku.service.ISubjectService;
// @Controller注解表明这个类是Spring MVC框架中的控制器类主要负责处理与题库课程相关的Web请求
// 通过调用相关的业务服务层ICourseService、ISubjectService方法来实现诸如展示课程相关页面、处理课程数据查询、进行课程信息的增删改等操作
// 是整个系统中题库课程业务模块在Web层面交互的核心控制部分。
@Controller
@RequestMapping(path="tiku/course")
// @RequestMapping注解为这个控制器类下的所有请求路径设置一个公共前缀即该控制器主要处理以"tiku/course"开头的请求路径,
// 便于对题库课程相关的众多不同类型请求进行统一的分类管理,使代码结构更加清晰,便于维护和扩展。
@RequestMapping(path = "tiku/course")
public class CourseController {
// 以下定义了多个常量字符串分别代表不同课程相关页面的视图名称按照Spring MVC的视图解析规则这些字符串对应着实际存放课程相关展示内容的模板文件路径比如可能是JSP、Thymeleaf等不同类型模板文件的具体路径
// 用于在不同业务场景下展示相应的课程页面内容。
/** 科目*/
private final String COURSE_INDEX_PAGE = "modules/tiku/course/list";
private final String COURSE_ADD_PAGE = "modules/tiku/course/add";
private final String COURSE_UPDATE_PAGE = "modules/tiku/course/update";
// 通过@Autowired注解自动注入ICourseService接口的实现类实例ICourseService接口中定义了一系列与题库课程核心业务相关的方法
// 比如查询课程详细信息、保存新的课程数据、更新课程已有记录等操作,借助这个注入的实例,本控制器类能够方便地调用这些业务逻辑方法,实现与业务逻辑层的交互,从而完成系统课程相关业务的具体处理。
@Autowired
private ICourseService iCourseService;
// 通过@Autowired注解自动注入ISubjectService接口的实现类实例ISubjectService主要用于处理与科目相关的业务逻辑
// 例如可以查询处于特定状态(如正常状态)的科目列表等操作,在系统课程相关业务中,科目信息往往和课程存在关联关系(比如课程属于某个科目范畴等情况),
// 所以注入该实例辅助完成涉及科目相关的课程业务处理,使整个课程业务逻辑更加完善。
@Autowired
private ISubjectService iSubjectService;
/**
* "tiku/course/list"
* model.setViewName(COURSE_INDEX_PAGE)COURSE_INDEX_PAGE
* ISubjectServiceselectListMyBatis PlusCondition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())
* ModelAndViewModelAndViewSpring MVC
* ModelAndViewSpring MVC
* 使访便
* 使@SuppressWarnings("unchecked")unchecked
* ModelAndView使
*
* @param model ModelAndView
*
* @return COURSE_INDEX_PAGEModelAndViewSpring MVC
*/
@SuppressWarnings("unchecked")
@RequestMapping(path="list")
@RequestMapping(path = "list")
public ModelAndView index(ModelAndView model) {
model.setViewName(COURSE_INDEX_PAGE);
model.addObject("subjectList", iSubjectService.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())));
return model;
}
/**
* "tiku/course/add"
* COURSE_ADD_PAGE
* ISubjectServiceselectListModelAndView
* ModelAndViewSpring MVC便
*
* 使@SuppressWarnings("unchecked")index
*
* @param model ModelAndView
* 便
* @return COURSE_ADD_PAGEModelAndViewSpring MVC
*/
@SuppressWarnings("unchecked")
@RequestMapping(path="add")
@RequestMapping(path = "add")
public ModelAndView add(ModelAndView model) {
model.setViewName(COURSE_ADD_PAGE);
model.addObject("subjectList", iSubjectService.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())));
return model;
}
/**
* "tiku/course/update"
* COURSE_UPDATE_PAGE
* ISubjectServiceselectListModelAndView
* iCourseService.selectById(id)id
* ModelAndViewModelAndView
* Spring MVC便
* 使@SuppressWarnings("unchecked")
*
* @param id
* 便
* @param model ModelAndView
* 使便
* @return COURSE_UPDATE_PAGEModelAndViewSpring MVC
*/
@SuppressWarnings("unchecked")
@RequestMapping(path="update")
@RequestMapping(path = "update")
public ModelAndView update(String id, ModelAndView model) {
model.setViewName(COURSE_UPDATE_PAGE);
model.addObject("subjectList", iSubjectService.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())));
@ -58,72 +113,150 @@ public class CourseController {
return model;
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "tiku/course/listData"POST
* jqGrid使MapJSON便
*
* @param condition CourseCondition
* 使iCourseService
* @return Map<String, Object>Result.jqGridResultPage<CourseEntity>
* 便便
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(CourseCondition condition) {
Page<CourseEntity> page = iCourseService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
@RequestMapping(path="save",method=RequestMethod.POST)
/**
* "tiku/course/save"POST
* JSON
*
* @param course CourseEntity
* iCourseServicesave
* @return ResultResultresult0便course.getName()Result
* ExceptionSupportresolverResultResultResult
*/
@RequestMapping(path = "save", method = RequestMethod.POST)
@ResponseBody
public Result save(CourseEntity course) {
try {
iCourseService.save(course);
return Result.result(0, null, "保存科目【"+course.getName()+"】成功");
return Result.result(0, null, "保存科目【" + course.getName() + "】成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("保存科目", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "tiku/course/update"POST
* JSON
*
* @param course CourseEntity
* iCourseServiceupdate
* @return ResultResultresult0便course.getName()Result
* ExceptionSupportresolverResultResultResult
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(CourseEntity course) {
try {
iCourseService.update(course);
return Result.result(0, null, "修改科目【"+course.getName()+"】成功");
return Result.result(0, null, "修改科目【" + course.getName() + "】成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改科目", this.getClass(), e);
}
}
@RequestMapping(path="delete",method=RequestMethod.POST)
@ResponseBody
public Result delete(String id) {
try {
iCourseService.delete(id);
return Result.result(0, null, "删除科目成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("删除科目", this.getClass(), e);
}
/**
* "tiku/course/delete" POSTid
* JSON
*
* @param id
* @return Result Result result 0 Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(String id) {
try {
// 调用 iCourseService 的 delete 方法传入表示要删除课程的唯一标识id
// 由业务逻辑层去执行具体的删除课程的逻辑,例如从数据库中删除该课程的相关记录等操作,以完成删除课程的业务需求。
iCourseService.delete(id);
return Result.result(0, null, "删除科目成功");
} catch (Exception e) {
// 如果在删除课程操作过程中出现异常,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 该方法可能会记录异常详情到日志、返回合适的错误提示等操作,并返回处理后的结果(同样包装在 Result 对象中),
// 客户端可以根据接收到的返回值判断删除操作是否成功以及是否出现异常情况,进而进行相应的处理(如向用户展示错误提示等)。
return ExceptionSupport.resolverResult("删除科目", this.getClass(), e);
}
}
}
@RequestMapping(path="enable",method=RequestMethod.POST)
@ResponseBody
public Result enable(String id) {
try {
iCourseService.enable(id);
return Result.result(0, null, "激活科目成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("激活科目", this.getClass(), e);
/**
* "tiku/course/enable" POSTid
*
* JSON 便
*
* @param id
* 便 iCourseService enable
* @return Result Result result 0 便 Result
* ExceptionSupport resolverResult Result
*
*/
@RequestMapping(path = "enable", method = RequestMethod.POST)
@ResponseBody
public Result enable(String id) {
try {
// 调用 iCourseService 的 enable 方法传入代表要激活课程的唯一标识id
// 由业务逻辑层去执行具体的激活课程的逻辑,比如在数据库中将课程的状态修改为激活状态等操作,以此实现激活课程的业务要求。
iCourseService.enable(id);
return Result.result(0, null, "激活科目成功");
} catch (Exception e) {
// 当激活课程操作出现异常时,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 此方法会进行记录异常信息、返回合适的错误提示等操作,然后返回处理后的结果(返回 null 表示操作失败,出现异常),
// 客户端可根据接收到的返回值判断激活操作是否成功以及是否有异常发生,进而进行后续处理(例如向用户展示错误提示等)。
return ExceptionSupport.resolverResult("激活科目", this.getClass(), e);
}
}
}
@RequestMapping(path="disabled",method=RequestMethod.POST)
@ResponseBody
public Result disabled(String id) {
try {
iCourseService.disabled(id);
return Result.result(0, null, "停用科目成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("停用科目", this.getClass(), e);
/**
* "tiku/course/disabled" POSTid
*
* JSON 便
*
* @param id
* 便 iCourseService disabled
* @return Result Result result 0 便 Result
* ExceptionSupport resolverResult Result
*
*/
@RequestMapping(path = "disabled", method = RequestMethod.POST)
@ResponseBody
public Result disabled(String id) {
try {
// 调用 iCourseService 的 disabled 方法传入用于标识要停用课程的课程编号id
// 由业务逻辑层去执行具体的停用课程的逻辑,例如在数据库中将课程的状态标记为停用状态等操作,以实现停用课程的业务需求。
iCourseService.disabled(id);
return Result.result(0, null, "停用科目成功");
} catch (Exception e) {
// 若在停用课程操作过程中出现异常,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 此方法会进行记录异常信息、返回合适的错误提示等操作,然后返回处理后的结果(返回 null 表示操作失败,出现异常),
// 客户端可以根据接收到的返回值判断停用操作是否成功以及是否出现异常情况,进而进行相应的处理(如向用户展示错误提示等)。
return ExceptionSupport.resolverResult("停用科目", this.getClass(), e);
}
}
}
@RequestMapping(path="treeData",method=RequestMethod.GET)
@ResponseBody
public JSONArray treeData() {
return iCourseService.treeData();
}
}
/**
* "tiku/course/treeData" GET便 JSONArray便 JSON
* iCourseService
*
* @return JSONArray iCourseService treeData
* 便
*/
@RequestMapping(path = "treeData", method = RequestMethod.GET)
@ResponseBody
public JSONArray treeData() {
return iCourseService.treeData();
}

@ -18,66 +18,138 @@ import com.tamguo.modules.tiku.model.condition.BookCondition;
import com.tamguo.modules.tiku.service.IKnowPointService;
import com.tamguo.modules.tiku.service.ICourseService;
// 使用 @Controller 注解将该类标记为 Spring MVC 中的控制器类意味着它主要负责处理与题库知识点KnowPoint相关的 Web 请求,
// 通过调用对应的业务逻辑层IKnowPointService、ICourseService的方法实现诸如展示知识点相关页面、处理知识点数据查询、进行知识点信息的增删改以及获取知识点树形结构数据等操作
// 是系统中题库知识点功能模块在 Web 层面交互的核心组件。
@Controller
@RequestMapping(path="tiku/knowpoint")
// 通过 @RequestMapping 注解为该控制器类下的所有请求路径设置一个公共的前缀,表明此类中定义的所有请求处理方法对应的路径都是以 "tiku/knowpoint" 开头,
// 便于对题库知识点相关的众多请求进行统一管理和分类,使代码结构更加清晰有条理。
@RequestMapping(path = "tiku/knowpoint")
public class KnowPointController {
/** 书籍*/
// 以下定义了多个字符串常量,分别对应不同知识点相关操作页面的视图名称,在 Spring MVC 的视图解析机制下,
// 这些常量值会指向具体的页面模板文件(比如 JSP、Thymeleaf 等模板文件)所在的路径,用于在相应业务场景下展示对应的页面内容。
/** 书籍 */
private final String KNOWPOINT_LIST_PAGE = "modules/tiku/knowpoint/list";
private final String KNOWPOINT_UPDATE_PAGE = "modules/tiku/knowpoint/update";
// 通过 @Autowired 注解自动注入 IKnowPointService 接口的实现类实例IKnowPointService 接口应该定义了一系列用于处理题库知识点相关业务逻辑的方法,
// 例如查询知识点详细信息、保存新的知识点、更新知识点已有信息、删除知识点以及获取知识点的树形结构数据等功能,
// 借助这个注入的实例,本控制器类可以方便地与业务逻辑层交互,调用相应方法来完成各种题库知识点相关的业务操作。
@Autowired
private IKnowPointService iKnowPointService;
// 通过 @Autowired 注解自动注入 ICourseService 接口的实现类实例ICourseService 主要用于处理与课程相关的业务逻辑,
// 由于在系统中知识点通常与课程存在关联关系(例如知识点属于某个课程范畴等情况),所以注入该实例可以辅助本控制器类完成涉及课程相关信息查询等的知识点业务处理,
// 比如在展示知识点信息时,同时展示其所属课程的相关信息等操作。
@Autowired
private ICourseService iCourseService;
@RequestMapping(path="list")
/**
* "tiku/knowpoint/list"
* KNOWPOINT_LIST_PAGE
* ModelAndView Spring MVC
* ModelAndView
*
* @param model ModelAndView
*
* @return KNOWPOINT_LIST_PAGE ModelAndView Spring MVC
*/
@RequestMapping(path = "list")
public ModelAndView index(ModelAndView model) {
model.setViewName(KNOWPOINT_LIST_PAGE);
return model;
}
@RequestMapping(path="update")
/**
* "tiku/knowpoint/update" GET便
*
* @param id
* 便
* @param model ModelAndView
* 使便
* @return KNOWPOINT_UPDATE_PAGE ModelAndView Spring MVC
*/
@RequestMapping(path = "update", method = RequestMethod.GET)
public ModelAndView update(String id, ModelAndView model) {
model.setViewName(KNOWPOINT_UPDATE_PAGE);
// 通过调用 iKnowPointService 的 selectById 方法,依据传入的 id 参数,从数据库等数据源中查询出要修改的知识点对象,
// 以便在修改页面上展示该知识点的当前信息,供用户查看并确定要修改的具体内容。
KnowPointEntity knowpoint = iKnowPointService.selectById(id);
// 接着调用 iCourseService 的 selectById 方法依据查询到的知识点对象中存储的所属课程编号knowpoint.getCourseId()),查询出对应的课程对象,
// 这么做是为了在修改知识点页面上同时展示出该知识点所属的课程信息,方便用户参考所属课程情况来进行合理的知识点信息修改,比如知识点与课程关联性调整等操作(具体取决于业务需求)。
CourseEntity course = iCourseService.selectById(knowpoint.getCourseId());
model.addObject("knowpoint", knowpoint);
model.addObject("course", course);
return model;
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "tiku/knowpoint/listData" POST
* jqGrid 使 Map JSON 便
*
* @param condition BookCondition
* 使 BookCondition KnowPointCondition
* @return KnowPointEntity Map<String, Object> Map Result.jqGridResult Page<KnowPointEntity>
* 便便
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(BookCondition condition) {
Page<KnowPointEntity> page = iKnowPointService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
@RequestMapping(path="save",method=RequestMethod.POST)
/**
* "tiku/knowpoint/save" POST
* JSON
*
* @param book KnowPointEntity
* iKnowPointService save
* @return Result Result result 0 便 book.getName() Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "save", method = RequestMethod.POST)
@ResponseBody
public Result save(KnowPointEntity book) {
try {
iKnowPointService.save(book);
return Result.result(0, null, "保存书籍【"+book.getName()+"】成功");
return Result.result(0, null, "保存书籍【" + book.getName() + "】成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("保存书籍", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "tiku/knowpoint/update" POST
* JSON
*
* @param book KnowPointEntity
* iKnowPointService update
* @return Result Result result 0 便 book.getName() Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(KnowPointEntity book) {
try {
iKnowPointService.update(book);
return Result.result(0, null, "修改书籍【"+book.getName()+"】成功");
return Result.result(0, null, "修改书籍【" + book.getName() + "】成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改书籍", this.getClass(), e);
}
}
@RequestMapping(path="delete",method=RequestMethod.POST)
/**
* "tiku/knowpoint/delete" POSTid
* JSON
*
* @param id
* @return Result Result result 0 Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(String id) {
try {
@ -87,8 +159,19 @@ public class KnowPointController {
return ExceptionSupport.resolverResult("删除书籍", this.getClass(), e);
}
}
@RequestMapping(path="enable",method=RequestMethod.POST)
/**
* "tiku/knowpoint/enable" POSTid
*
* JSON 便
*
* @param id
* 便 iKnowPointService enable
* @return Result Result result 0 便 Result
* ExceptionSupport resolverResult Result
*
*/
@RequestMapping(path = "enable", method = RequestMethod.POST)
@ResponseBody
public Result enable(String id) {
try {
@ -98,21 +181,13 @@ public class KnowPointController {
return ExceptionSupport.resolverResult("激活书籍", this.getClass(), e);
}
}
@RequestMapping(path="disabled",method=RequestMethod.POST)
@ResponseBody
public Result disabled(String id) {
try {
iKnowPointService.disabled(id);
return Result.result(0, null, "停用书籍成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("停用书籍", this.getClass(), e);
}
}
@RequestMapping(path="treeData",method=RequestMethod.POST)
@ResponseBody
public JSONArray treeData() {
return iKnowPointService.treeData();
}
}
/**
* "tiku/knowpoint/disabled" POSTid
*
* JSON 便
*
* @param id
* 便 iKnowPointService disabled
* @return Result Result result 0 便 Result
* ExceptionSupport resolverResult Result

@ -26,64 +26,141 @@ import com.tamguo.modules.member.model.MemberEntity;
import com.tamguo.modules.member.model.condition.MemberCondition;
import com.tamguo.modules.member.service.IMemberService;
// 使用 @Controller 注解将该类标记为 Spring MVC 中的控制器类表明它主要负责处理与题库中会员Member相关的 Web 请求,
// 通过调用对应的业务逻辑层IMemberService、IBookService、IBookCategoryService的方法实现诸如展示会员相关页面、处理会员数据查询、会员奖励操作以及获取与会员相关书籍信息等功能
// 是系统中涉及会员在题库业务模块下进行交互操作的核心控制部分。
@Controller
@RequestMapping(value="tiku/member")
// 通过 @RequestMapping 注解为这个控制器类下的所有请求路径设置一个公共前缀,即该控制器主要处理以 "tiku/member" 开头的请求路径,
// 便于对会员相关的众多不同类型请求进行统一的分类管理,使代码结构更加清晰,便于维护和扩展。
@RequestMapping(value = "tiku/member")
public class MemberController {
// 创建一个日志记录器对象,使用 SLF4J 框架的 LoggerFactory 来获取与当前类对应的 Logger 实例,
// 通过这个日志记录器,可以在代码中方便地记录各种级别的日志信息(如 DEBUG、INFO、WARN、ERROR 等),便于在系统运行过程中进行调试、监控以及问题排查等操作。
private Logger logger = LoggerFactory.getLogger(getClass());
// 通过 @Autowired 注解自动注入 IMemberService 接口的实现类实例IMemberService 接口中定义了一系列与会员核心业务相关的方法,
// 比如查询会员详细信息、根据条件查询会员列表、执行会员奖励等操作,借助这个注入的实例,本控制器类能够方便地调用这些业务逻辑方法,实现与业务逻辑层的交互,从而完成系统中会员相关业务的具体处理。
@Autowired
IMemberService iMemberService;
// 通过 @Autowired 注解自动注入 IBookService 接口的实现类实例IBookService 主要用于处理与书籍相关的业务逻辑,
// 例如查询会员拥有的书籍列表等操作,在系统业务中,会员与书籍可能存在关联关系(比如会员拥有某些书籍等情况),所以注入该实例辅助完成涉及书籍相关的会员业务处理。
@Autowired
IBookService iBookService;
// 通过 @Autowired 注解自动注入 IBookCategoryService 接口的实现类实例IBookCategoryService 用于处理书籍分类相关的业务逻辑,
// 比如根据书籍分类编号查询分类名称等操作,在涉及会员相关书籍展示等业务场景中,可能需要获取书籍所属分类信息来更全面地展示书籍详情,所以注入该实例辅助完成此类业务操作。
@Autowired
IBookCategoryService iBookCategoryService;
@RequestMapping(value="list")
/**
* "tiku/member/list"
* model.setViewName("modules/tiku/member/list")
* ModelAndView Spring MVC
* ModelAndView
*
* @param model ModelAndView
*
* @return "modules/tiku/member/list" ModelAndView Spring MVC
*/
@RequestMapping(value = "list")
public ModelAndView list(ModelAndView model) {
model.setViewName("modules/tiku/member/list");
return model;
}
@RequestMapping(value="listData" , method=RequestMethod.POST)
/**
* "tiku/member/listData" POST
* jqGrid 使 Map JSON 便
*
* @param condition MemberCondition
* 使iMemberService
* @return Map<String, Object> Result.jqGridResult Page<MemberEntity>
* 便便
*/
@RequestMapping(value = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(MemberCondition condition){
public Map<String, Object> listData(MemberCondition condition) {
Page<MemberEntity> page = iMemberService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
@RequestMapping(value="reward" , method=RequestMethod.GET)
public ModelAndView reward(String id , ModelAndView model) {
/**
* "tiku/member/reward" GET
* "modules/tiku/member/reward"
* iMemberService.selectById(id) id
* ModelAndView ModelAndView
* Spring MVC 便
*
* @param id
* 便
* @param model ModelAndView
* 使便
* @return "modules/tiku/member/reward" ModelAndView Spring MVC
*/
@RequestMapping(value = "reward", method = RequestMethod.GET)
public ModelAndView reward(String id, ModelAndView model) {
model.setViewName("modules/tiku/member/reward");
model.addObject("member", iMemberService.selectById(id));
return model;
}
/**
* "tiku/member/bookTreeData" POST
* 便
*
* @param memberId
*
* @return BookEntity List BookEntity
* 便
*/
@SuppressWarnings("unchecked")
@RequestMapping(value="bookTreeData",method=RequestMethod.POST)
@RequestMapping(value = "bookTreeData", method = RequestMethod.POST)
@ResponseBody
public List<BookEntity> bookTreeData(String memberId){
List<BookEntity> bookList = iBookService.selectList(Condition.create().eq("owner", memberId).orderDesc(Arrays.asList("create_date")));
if(!CollectionUtils.isEmpty(bookList)) {
for(int i=0 ; i<bookList.size() ; i++) {
BookEntity book = bookList.get(i);
BookCategoryEntity category = iBookCategoryService.selectById(book.getCategoryId().split(",")[0]);
book.setCategoryName(category.getName());
}
}
public List<BookEntity> bookTreeData(String memberId) {
// 通过调用 iBookService 的 selectList 方法,结合 MyBatis Plus 的条件构造器Condition.create().eq("owner", memberId).orderDesc(Arrays.asList("create_date"))
// 查询出所有者为指定会员(根据 memberId 确定)的书籍列表,并按照创建日期降序排列(以便展示时最新创建的书籍排在前面等情况,具体展示逻辑由前端决定),查询结果存储在 bookList 变量中。
List<BookEntity> bookList = iBookService.selectList(Condition.create().eq("owner", memberId).orderDesc(Arrays.asList("create_date")));
// 使用 Spring 提供的 CollectionUtils.isEmpty 方法判断查询到的书籍列表是否为空,如果不为空,则进行后续的处理操作(为书籍设置分类名称)。
if (!CollectionUtils.isEmpty(bookList)) {
// 遍历查询到的书籍列表,对每一本书籍进行处理。
for (int i = 0; i < bookList.size(); i++) {
BookEntity book = bookList.get(i);
// 从当前书籍对象中获取其分类编号book.getCategoryId()由于可能存在多个分类编号以逗号分隔等形式存储具体取决于业务设计这里取第一个分类编号split(",")[0]
// 然后通过调用 iBookCategoryService 的 selectById 方法,依据这个分类编号查询对应的书籍分类实体对象,获取其分类名称信息,用于设置到当前书籍对象中。
BookCategoryEntity category = iBookCategoryService.selectById(book.getCategoryId().split(",")[0]);
book.setCategoryName(category.getName());
}
}
return bookList;
}
@RequestMapping(value="reward" , method=RequestMethod.POST)
/**
* "tiku/member/reward" POST
* JSON
*
* @param id 便
* @param bookId
* @param rewardPoint
* @param rewardMoney BigDecimal
* @return Result Result result 0 Result
* logger Result result 1 便 Result
* Result
*/
@RequestMapping(value = "reward", method = RequestMethod.POST)
@ResponseBody
public Result submitReward(String id , String bookId , Integer rewardPoint , BigDecimal rewardMoney) {
public Result submitReward(String id, String bookId, Integer rewardPoint, BigDecimal rewardMoney) {
try {
iMemberService.reward(id , bookId , rewardPoint , rewardMoney);
// 调用 iMemberService 的 reward 方法传入会员编号id、书籍编号bookId、奖励点数rewardPoint以及奖励金额rewardMoney等参数
// 由业务逻辑层去执行具体的会员奖励逻辑,例如更新会员积分、账户余额等相关操作,以完成会员奖励的业务需求。
iMemberService.reward(id, bookId, rewardPoint, rewardMoney);
return Result.result(0, null, "奖励成功!");
} catch (Exception e) {
logger.error(e.getMessage() , e);
// 如果在执行会员奖励操作过程中出现异常,使用日志记录器记录异常详细信息,方便后续排查问题,
// 这里记录了异常消息e.getMessage()以及完整的异常堆栈信息e以便准确了解异常产生的原因和位置。
logger.error(e.getMessage(), e);
return Result.result(1, null, "奖励失败!");
}
}
}
}

@ -16,72 +16,153 @@ import com.tamguo.modules.tiku.model.SubjectEntity;
import com.tamguo.modules.tiku.model.condition.SubjectCondition;
import com.tamguo.modules.tiku.service.ISubjectService;
// 使用 @Controller 注解将该类标记为 Spring MVC 中的控制器类意味着它主要负责处理与题库分类Subject相关的 Web 请求,
// 通过调用对应的业务逻辑层ISubjectService的方法实现诸如展示题库分类相关页面、处理分类数据查询、进行分类信息的增删改查以及激活、停用等操作
// 是系统中题库分类功能模块在 Web 层面交互的核心组件。
@Controller
@RequestMapping(path="tiku/subject")
// 通过 @RequestMapping 注解为该控制器类下的所有请求路径设置一个公共的前缀,表明此类中定义的所有请求处理方法对应的路径都是以 "tiku/subject" 开头,
// 便于对题库分类相关的众多请求进行统一管理和分类,使代码结构更加清晰有条理。
@RequestMapping(path = "tiku/subject")
public class SubjectController {
/** 题库分类*/
// 以下定义了多个字符串常量,分别对应不同题库分类相关操作页面的视图名称,在 Spring MVC 的视图解析机制下,
// 这些常量值会指向具体的页面模板文件(比如 JSP、Thymeleaf 等模板文件)所在的路径,用于在相应业务场景下展示对应的页面内容。
/** 题库分类 */
private final String SUBJECT_INDEX_PAGE = "modules/tiku/subject/list";
private final String SUBJECT_UPDATE_PAGE = "modules/tiku/subject/update";
// 通过 @Autowired 注解自动注入 ISubjectService 接口的实现类实例ISubjectService 接口定义了一系列用于处理题库分类相关业务逻辑的方法,
// 例如查询分类详细信息、保存新的分类、更新分类已有信息、删除分类以及激活、停用分类等功能,
// 借助这个注入的实例,本控制器类可以方便地与业务逻辑层交互,调用相应方法来完成各种题库分类相关的业务操作。
@Autowired
private ISubjectService iSubjectService;
@RequestMapping(path="list")
/**
* "tiku/subject/list"
* SUBJECT_INDEX_PAGE
* ModelAndView Spring MVC
* ModelAndView
*
* @param model ModelAndView
*
* @return SUBJECT_INDEX_PAGE ModelAndView Spring MVC
*/
@RequestMapping(path = "list")
public ModelAndView list(ModelAndView model) {
model.setViewName(SUBJECT_INDEX_PAGE);
return model;
}
@RequestMapping(path="update")
public ModelAndView update(String uid , ModelAndView model) {
/**
* "tiku/subject/update" GET便
*
* @param uid
* 便
* @param model ModelAndView
* 使便
* @return SUBJECT_UPDATE_PAGE ModelAndView Spring MVC
*/
@RequestMapping(path = "update", method = RequestMethod.GET)
public ModelAndView update(String uid, ModelAndView model) {
model.setViewName(SUBJECT_UPDATE_PAGE);
// 通过调用 iSubjectService 的 selectById 方法,依据传入的 uid 参数,从数据库等数据源中查询出要修改的分类对象,
// 以便在修改页面上展示该分类的当前信息,供用户查看并确定要修改的具体内容。
model.addObject("subject", iSubjectService.selectById(uid));
return model;
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "tiku/subject/listData" POST
* jqGrid 使 Map JSON 便
*
* @param condition SubjectCondition
*
* @return SubjectEntity Map<String, Object> Map Result.jqGridResult Page<SubjectEntity>
* 便便
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(SubjectCondition condition) {
Page<SubjectEntity> page = iSubjectService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
/**
* "tiku/subject/checkSubjectCode" GETuid
* 0 false 0 true
*
* @param uid
* 使
* @return uid 0 false 0 true
* false 使
*/
@SuppressWarnings("unchecked")
@RequestMapping(path="checkSubjectCode",method=RequestMethod.GET)
@RequestMapping(path = "checkSubjectCode", method = RequestMethod.GET)
@ResponseBody
public Boolean checkSubjectCode(String uid) {
// 通过调用 iSubjectService 的 selectCount 方法,结合 MyBatis Plus 的条件构造器Condition.create().eq("uid", uid)
// 查询数据库中满足分类编号uid相等条件的记录数量将查询结果存储在 count 变量中。
Integer count = iSubjectService.selectCount(Condition.create().eq("uid", uid));
if(count > 0) {
if (count > 0) {
return false;
}else {
} else {
return true;
}
}
@RequestMapping(path="save",method=RequestMethod.POST)
/**
* "tiku/subject/save" POST
* JSON
*
* @param subject SubjectEntity
* iSubjectService save
* @return Result Result result 0 便 subject.getName() Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "save", method = RequestMethod.POST)
@ResponseBody
public Result save(SubjectEntity subject) {
try {
iSubjectService.save(subject);
return Result.result(0, null, "保存分类【"+subject.getName()+"】成功");
return Result.result(0, null, "保存分类【" + subject.getName() + "】成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("保存分类", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "tiku/subject/update" POST
* JSON
*
* @param subject SubjectEntity
* iSubjectService update
* @return Result Result result 0 便 subject.getName() Result
* ExceptionSupport resolverResult Result Result
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SubjectEntity subject) {
try {
iSubjectService.update(subject);
return Result.result(0, null, "修改分类【"+subject.getName()+"】成功");
return Result.result(0, null, "修改分类【" + subject.getName() + "】成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改分类", this.getClass(), e);
}
}
@RequestMapping(path="enable",method=RequestMethod.POST)
/**
* "tiku/subject/enable" POSTuid
*
* JSON 便
*
* @param uid
* 便 iSubjectService enable
* @return Result Result result 0 便 Result
* ExceptionSupport resolverResult Result
*
*/
@RequestMapping(path = "enable", method = RequestMethod.POST)
@ResponseBody
public Result enable(String uid) {
try {
@ -91,8 +172,19 @@ public class SubjectController {
return ExceptionSupport.resolverResult("激活分类", this.getClass(), e);
}
}
@RequestMapping(path="disabled",method=RequestMethod.POST)
/**
* "tiku/subject/disabled" POSTuid
*
* JSON 便
*
* @param uid
* 便 iSubjectService disabled
* @return Result Result result 0 便 Result
* ExceptionSupport resolverResult Result
*
*/
@RequestMapping(path = "disabled", method = RequestMethod.POST)
@ResponseBody
public Result disabled(String uid) {
try {
@ -102,16 +194,10 @@ public class SubjectController {
return ExceptionSupport.resolverResult("停用分类", this.getClass(), e);
}
}
@RequestMapping(path="delete",method=RequestMethod.POST)
@ResponseBody
public Result delete(String uid) {
try {
iSubjectService.delete(uid);
return Result.result(0, null, "删除分类成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("删除分类", this.getClass(), e);
}
}
}
/**
* "tiku/subject/delete" POSTuid
* JSON
*
* @param uid
* @return Result Result result
Loading…
Cancel
Save