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

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

@ -4,29 +4,56 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类表明它负责处理Web请求并将请求转发到相应的视图进行展示是Web应用中实现页面交互逻辑的重要组成部分。
@Controller
public class CommonController {
// 定义一个常量字符串表示树状选择页面的视图名称具体路径格式遵循Spring MVC视图解析的配置规则这里的"modules/sys/common/treeselect"可能对应的是一个JSP、Thymeleaf等模板文件的路径用于展示树状选择相关的页面内容
private final String TREE_SELECT_PAGE = "modules/sys/common/treeselect";
// 定义常量字符串,代表树状图标选择页面的视图名称,同样对应着用于展示树状图标选择相关内容的模板文件路径。
private final String TREE_ICON_PAGE = "modules/sys/common/iconselect";
// 定义常量字符串,用于表示系统桌面页面的视图名称,即对应展示系统桌面相关内容的模板文件路径。
private final String SYS_DESKTOP_PAGE = "modules/sys/common/desktop";
@RequestMapping(path="sys/treeselect")
public ModelAndView index(ModelAndView model , String url) {
model.addObject("url" , url);
/**
* "sys/treeselect"
* Spring MVC@RequestMapping
* ModelAndView"url"
*
* @param model ModelAndView
* @param url URLModelAndView
* @return ModelAndViewSpring MVC
*/
@RequestMapping(path = "sys/treeselect")
public ModelAndView index(ModelAndView model, String url) {
model.addObject("url", url);
model.setViewName(TREE_SELECT_PAGE);
return model;
}
@RequestMapping(path="sys/iconselect")
/**
* "sys/iconselect"
* @RequestMapping
*
* @param model ModelAndView
* @return ModelAndView使Spring MVC
*/
@RequestMapping(path = "sys/iconselect")
public ModelAndView iconselect(ModelAndView model) {
model.setViewName(TREE_ICON_PAGE);
return model;
}
@RequestMapping(path="sys/desktop")
/**
* "sys/desktop"
* @RequestMappingSpring MVC
*
* @param model ModelAndView
* @return ModelAndView使
*/
@RequestMapping(path = "sys/desktop")
public ModelAndView index(ModelAndView model) {
model.setViewName(SYS_DESKTOP_PAGE);
return model;
}
}
}

@ -18,33 +18,63 @@ import com.tamguo.modules.sys.model.condition.SysCompanyCondition;
import com.tamguo.modules.sys.service.ISysAreaService;
import com.tamguo.modules.sys.service.ISysCompanyService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类表明它负责处理与公司相关的Web请求并根据不同的请求调用相应的业务逻辑方法将处理结果返回给客户端或者转发到对应的视图进行展示是实现公司业务模块页面交互和数据处理的核心部分。
@Controller
@RequestMapping(path="sys/company")
// 通过@RequestMapping注解为这个控制器类下的所有请求路径设置一个公共的前缀即该控制器处理的请求路径都以"sys/company"开头,方便对公司相关的各种请求进行统一管理和分类。
@RequestMapping(path = "sys/company")
public class CompanyController {
// 定义一个常量字符串表示公司列表页面或首页的视图名称遵循Spring MVC视图解析的配置规则对应着展示公司列表相关内容的模板文件路径如JSP、Thymeleaf等模板文件的具体路径
private final String COMPANY_INDEX_PAGE = "modules/sys/company/index";
// 定义常量字符串,代表公司详情页面(可能用于新增公司时展示相关信息的页面,也可能用于查看已有公司详情的页面,具体取决于业务逻辑)的视图名称,对应着展示公司详细信息相关内容的模板文件路径。
private final String COMPANY_DETAIL_PAGE = "modules/sys/company/add";
// 定义常量字符串,用于表示公司信息更新页面的视图名称,对应展示修改公司信息相关内容的模板文件路径。
private final String COMPANY_UPDATE_PAGE = "modules/sys/company/update";
// 通过@Autowired注解自动注入ISysCompanyService接口的实现类实例用于调用与公司相关的业务逻辑方法比如查询、保存、更新公司信息等操作实现控制器层与业务逻辑层的交互。
@Autowired
ISysCompanyService iSysCompanyService;
// 同样使用@Autowired注解注入ISysAreaService接口的实现类实例用于获取与地区相关的服务可能在处理公司信息时涉及到关联地区信息等业务场景比如公司所属地区的查询等操作实现与其他相关业务模块的交互。
@Autowired
ISysAreaService iSysAreaService;
@RequestMapping(path="index")
/**
* "sys/company/index"
* Spring MVC便
*
* @param model ModelAndViewSpring MVC
* @return COMPANY_INDEX_PAGESpring MVC
*/
@RequestMapping(path = "index")
public String index(ModelAndView model) {
return COMPANY_INDEX_PAGE;
}
@RequestMapping(path="add")
public ModelAndView add(String parentCode , ModelAndView model) {
/**
* "sys/company/add"
* COMPANY_DETAIL_PAGEISysCompanyServiceparentCodeModelAndView使ModelAndView使Spring MVC
*
* @param parentCode
* @param model ModelAndView
* @return COMPANY_DETAIL_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "add")
public ModelAndView add(String parentCode, ModelAndView model) {
model.setViewName(COMPANY_DETAIL_PAGE);
model.addObject("company", iSysCompanyService.selectById(parentCode));
return model;
}
@RequestMapping(path="update")
public ModelAndView update(String companyCode , ModelAndView model) {
/**
* "sys/company/update"
* COMPANY_UPDATE_PAGEISysCompanyServiceparentCodeISysAreaServiceareaCodeModelAndView便ModelAndView便Spring MVC
*
* @param companyCode
* @param model ModelAndView
* @return COMPANY_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(String companyCode, ModelAndView model) {
model.setViewName(COMPANY_UPDATE_PAGE);
SysCompanyEntity company = iSysCompanyService.selectById(companyCode);
SysCompanyEntity parentCompany = iSysCompanyService.selectById(company.getParentCode());
@ -54,44 +84,80 @@ public class CompanyController {
model.addObject("area", area);
return model;
}
@RequestMapping(path="info/{code}")
/**
* "sys/company/info/{code}"JSON
* @PathVariable{code}ISysCompanyServiceselectByCodeResultResult@ResponseBodyJSON便
*
* @param code @PathVariable
* @return ResultResultJSON
*/
@RequestMapping(path = "info/{code}")
@ResponseBody
public Result info(@PathVariable("code") String code) {
return Result.successResult(iSysCompanyService.selectByCode(code));
}
@RequestMapping(path="listData")
/**
* "sys/company/listData"JSON
* SysCompanyConditionISysCompanyServicelistDataList<SysCompanyEntity>Spring MVC@ResponseBodyJSON
*
* @param condition SysCompanyCondition使
* @return JSON
*/
@RequestMapping(path = "listData")
@ResponseBody
public List<SysCompanyEntity> listData(SysCompanyCondition condition) {
return iSysCompanyService.listData(condition);
}
@RequestMapping(path="treeData")
/**
* "sys/company/treeData"JSON
* excludeIdISysCompanyServicetreeDataJSONArrayJSON便@ResponseBodyJSON便
*
* @param excludeId
* @return JSONArrayJSON
*/
@RequestMapping(path = "treeData")
@ResponseBody
public JSONArray treeData(String excludeId) {
return iSysCompanyService.treeData(excludeId);
}
@RequestMapping(path="save")
/**
* "sys/company/save"JSON
* SysCompanyEntityISysCompanyServicesaveResultResult.resultExceptionSupportresolverResultResult
*
* @param company SysCompanyEntity
* @return ResultJSON
*/
@RequestMapping(path = "save")
@ResponseBody
public Result save(SysCompanyEntity company) {
try {
iSysCompanyService.save(company);
return Result.result(0, null, "公司【"+company.getCompanyName()+"】保存成功!");
return Result.result(0, null, "公司【" + company.getCompanyName() + "】保存成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("保存公司", this.getClass(), e);
}
}
@RequestMapping(path="update" , method=RequestMethod.POST)
/**
* "sys/company/update"使POSTJSON
* SysCompanyEntityISysCompanyServiceupdateResultExceptionSupportresolverResultResult便
* RequestMethod.POSTPOSTRESTfulGETPOST
*
* @param company SysCompanyEntity
* @return ResultJSON
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SysCompanyEntity company) {
try {
iSysCompanyService.update(company);
return Result.result(0, null, "公司【"+company.getCompanyName()+"】修改成功!");
return Result.result(0, null, "公司【" + company.getCompanyName() + "】修改成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改公司", this.getClass(), e);
}
}
}
}

@ -15,55 +15,99 @@ import com.tamguo.modules.sys.model.SysUserEntity;
import com.tamguo.modules.sys.model.condition.SysUserCondition;
import com.tamguo.modules.sys.service.ISysUserService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与企业管理员相关的Web请求调用相应的业务逻辑方法并根据处理结果返回给客户端合适的响应或者转发到对应的视图进行展示是实现企业管理员业务模块页面交互和数据处理的关键部分。
@Controller
@RequestMapping(path="sys/corpAdmin")
// 通过@RequestMapping注解为这个控制器类下的所有请求路径设置一个公共的前缀即该控制器处理的请求路径都以"sys/corpAdmin"开头,便于对企业管理员相关的各种请求进行统一管理和分类。
@RequestMapping(path = "sys/corpAdmin")
public class CorpAdminController {
// 定义一个常量字符串表示企业管理员列表页面或首页的视图名称遵循Spring MVC视图解析的配置规则对应着展示企业管理员列表相关内容的模板文件路径如JSP、Thymeleaf等模板文件的具体路径
private final String CORPADMIN_INDEX_PAGE = "modules/sys/corpAdmin/index";
// 定义常量字符串,代表企业管理员信息更新页面的视图名称,对应展示修改企业管理员信息相关内容的模板文件路径。
private final String CORPADMIN_UPDATE_PAGE = "modules/sys/corpAdmin/update";
// 通过@Autowired注解自动注入ISysUserService接口的实现类实例用于调用与系统用户这里特指企业管理员相关的用户操作因为从类名和业务逻辑推测处理的是企业管理员相关的业务相关的业务逻辑方法比如查询、保存、更新管理员信息等操作实现控制器层与业务逻辑层的交互。
@Autowired
private ISysUserService iSysUserService;
@RequestMapping(path="index")
/**
* "sys/corpAdmin/index"
* Spring MVC便
*
* @param model ModelAndViewSpring MVC
* @return CORPADMIN_INDEX_PAGESpring MVC
*/
@RequestMapping(path = "index")
public String index(ModelAndView model) {
return CORPADMIN_INDEX_PAGE;
}
@RequestMapping(path="update")
public ModelAndView update(String userCode , ModelAndView model) {
/**
* "sys/corpAdmin/update"
* ISysUserServiceuserCodeModelAndViewCORPADMIN_UPDATE_PAGEModelAndView使Spring MVC
*
* @param userCode
* @param model ModelAndView
* @return CORPADMIN_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(String userCode, ModelAndView model) {
model.addObject("user", iSysUserService.selectById(userCode));
model.setViewName(CORPADMIN_UPDATE_PAGE);
return model;
}
@RequestMapping(path="save",method=RequestMethod.POST)
/**
* "sys/corpAdmin/save"POSTJSON
* SysUserEntityISysUserServicesaveAdminResultResult.resultExceptionSupportresolverResultResult
* RequestMethod.POSTRESTfulPOST
*
* @param user SysUserEntity
* @return ResultJSON
*/
@RequestMapping(path = "save", method = RequestMethod.POST)
@ResponseBody
public Result save(SysUserEntity user) {
try {
iSysUserService.saveAdmin(user);
return Result.result(0, null, "管理员【"+user.getUserName()+"】添加成功");
return Result.result(0, null, "管理员【" + user.getUserName() + "】添加成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("添加管理员错误", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "sys/corpAdmin/update"POSTJSON
* SysUserEntityISysUserServiceupdateAdminResultExceptionSupportresolverResultResult便
* RequestMethod.POSTRESTfulPOST
*
* @param user SysUserEntity
* @return ResultJSON
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SysUserEntity user) {
try {
iSysUserService.updateAdmin(user);
return Result.result(0, null, "管理员【"+user.getUserName()+"】修改成功");
return Result.result(0, null, "管理员【" + user.getUserName() + "】修改成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改管理员错误", this.getClass(), e);
}
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "sys/corpAdmin/listData"POSTjqGrid使MapJSON
* SysUserConditionISysUserServicelistDataPage<SysUserEntity>MyBatis PlusResult.jqGridResultMap@ResponseBodyMapJSON
* RequestMethod.POSTPOST
*
* @param condition SysUserCondition使
* @return MapMapJSON
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(SysUserCondition condition) {
Page<SysUserEntity> page = iSysUserService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
}
}

@ -4,12 +4,21 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类意味着它负责处理Web请求并将请求转发到相应的视图进行展示在整个Web应用中承担着页面交互逻辑的一部分这里大概率是用于处理系统首页相关的请求逻辑。
@Controller
public class IndexController {
@RequestMapping(path="index")
/**
* 使@RequestMapping"index""index"
* ModelAndViewModelAndViewSpring MVC
* "index"Spring MVCJSPThymeleafSpring MVC"index"
*
* @param model ModelAndViewSpring MVC
* @return "index"便Spring MVC
*/
@RequestMapping(path = "index")
public String sysLogin(ModelAndView model) {
return "index";
}
}
}

@ -22,49 +22,89 @@ import com.tamguo.common.utils.SystemConstant;
import com.tamguo.modules.sys.service.ISysUserService;
import com.tamguo.modules.sys.utils.ShiroUtils;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与用户登录相关的Web请求在登录流程中与Shiro框架以及业务逻辑层进行交互根据不同情况返回相应的响应给客户端是实现用户登录功能的核心控制器类。
@Controller
public class LoginController {
// 通过@Autowired注解自动注入ISysUserService接口的实现类实例用于调用与系统用户相关的业务逻辑方法比如查询用户权限菜单等操作实现控制器层与业务逻辑层的交互辅助完成登录相关的业务处理。
@Autowired
private ISysUserService iSysUserService;
@RequestMapping(path="login")
/**
* "login"GET
* ShiroUtilsisLogintrue"index"Spring MVCfalse"login"
*
* @param model ModelAndViewSpring MVC
* @return "index""login"便Spring MVC
*/
@RequestMapping(path = "login")
public String sysLogin(ModelAndView model) {
if(ShiroUtils.isLogin()) {
if (ShiroUtils.isLogin()) {
return "index";
}
return "login";
}
/**
* "login"POSTJSON
* @ResponseBodyResultJSON便RequestMethod.POSTPOSTRESTfulGETsysLogin
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @param username
* @param rememberUser CookieShiro
* @param password
* @param validCode
* @return ResultResultJSON便
* @throws IOException IOException便Spring MVC
*/
@ResponseBody
@RequestMapping(value = "login", method = RequestMethod.POST)
public Result toLogin(HttpServletRequest request, HttpServletResponse response , String username , Boolean rememberUser, String password, String validCode)
throws IOException {
public Result toLogin(HttpServletRequest request, HttpServletResponse response, String username,
Boolean rememberUser, String password, String validCode) throws IOException {
try {
// 通过ShiroUtils工具类获取存储在会话中的验证码使用SystemConstant.KAPTCHA_SESSION_KEY作为键来查找对应的验证码SystemConstant应该是一个用于存放系统常量的类并将获取到的验证码与用户输入的验证码进行不区分大小写的比对如果不一致说明验证码错误直接返回包含相应错误提示信息的Result对象给客户端。
String kaptcha = ShiroUtils.getKaptcha(SystemConstant.KAPTCHA_SESSION_KEY);
if (!validCode.equalsIgnoreCase(kaptcha)) {
return Result.failResult("验证码错误");
}
// 通过ShiroUtils工具类获取当前的Subject对象Subject代表当前执行操作的用户主体在Shiro框架中是进行认证、授权等操作的核心入口点后续将基于这个对象进行用户登录认证操作。
Subject subject = ShiroUtils.getSubject();
// sha256加密
// 使用Sha256Hash对用户输入的密码进行加密处理将加密后的结果转换为十六进制字符串形式以提高密码存储和传输的安全性确保在与数据库中存储的密码进行比对时使用的是经过相同加密算法处理后的密码符合安全规范。
password = new Sha256Hash(password).toHex();
// 创建一个UsernamePasswordToken对象将用户名和加密后的密码传入构造函数这个对象在Shiro框架中用于表示用户登录的凭证信息后续会传递给Shiro的认证机制进行登录验证。
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
// 通过Subject对象调用login方法传入之前创建的包含用户凭证信息的UsernamePasswordToken对象触发Shiro框架的登录认证流程Shiro会根据配置的Realm通常是自定义的实现了认证逻辑的类去验证用户名和密码等信息是否正确如果认证通过则登录成功否则会抛出相应的认证异常。
subject.login(token);
// 获取权限菜单
// 登录成功后通过注入的ISysUserService实例调用其findUserMenuList方法根据当前登录用户的用户代码通过ShiroUtils.getUserCode方法获取)查询该用户对应的权限菜单信息,并将查询到的权限菜单列表存储到当前会话中,键为"userMenuList",方便后续在系统中根据用户权限展示不同的菜单选项,实现权限控制和菜单展示的功能。
request.getSession().setAttribute("userMenuList", iSysUserService.findUserMenuList(ShiroUtils.getUserCode()));
// 将当前登录用户的信息通过ShiroUtils.getUser方法获取存储到当前会话中键为"currAdmin",方便在系统的其他地方获取当前登录用户的详细信息进行相关业务处理,例如在页面上展示当前登录用户的相关信息等操作。
request.getSession().setAttribute("currAdmin", ShiroUtils.getUser());
} catch (UnknownAccountException e) {
// 如果在Shiro的登录认证过程中抛出UnknownAccountException异常说明找不到对应的用户账户可能是用户名不存在等原因则返回一个包含相应错误状态码和提示信息"找不到账户"的Result对象给客户端告知用户登录失败的原因。
return Result.result(501, null, "找不到账户");
} catch (IncorrectCredentialsException e) {
// 当抛出IncorrectCredentialsException异常时表示用户输入的账户验证失败通常是密码错误等原因导致返回包含对应错误状态码和提示信息"账户验证失败"的Result对象给客户端提示用户登录失败。
return Result.result(502, null, "账户验证失败");
} catch (LockedAccountException e) {
// 如果出现LockedAccountException异常意味着用户账户被锁定可能是由于多次错误登录等原因具体锁定逻辑通常在业务层或相关配置中设置同样返回包含相应错误状态码和提示信息"账户验证失败"的Result对象给客户端告知用户账户状态异常导致登录失败。
return Result.result(503, null, "账户验证失败");
} catch (AuthenticationException e) {
// 捕获其他类型的AuthenticationException异常这类异常通常涵盖了各种登录认证过程中出现的问题除了上述明确处理的几种常见异常情况外同样返回包含错误状态码和提示信息"账户验证失败"的Result对象给客户端提示用户登录失败以及可能存在的未知认证问题。
return Result.result(504, null, "账户验证失败");
}
// 再次将当前登录用户的信息存储到会话中(这里可能是为了确保会话中一定存在该用户信息,或者在后续可能的业务逻辑中方便再次获取等原因,代码逻辑上有一定的重复,但不影响功能实现),键为"currAdmin"。
request.getSession().setAttribute("currAdmin", ShiroUtils.getUser());
// 如果登录过程顺利没有抛出任何异常说明登录成功返回一个包含成功状态码以及用户名信息的Result对象给客户端告知客户端登录成功以及登录的用户名等情况方便前端进行相应的页面跳转和提示操作例如跳转到系统首页等。
return Result.successResult(username);
}
}
}

@ -6,14 +6,27 @@ import org.springframework.web.servlet.ModelAndView;
import com.tamguo.modules.sys.utils.ShiroUtils;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与用户注销相关的Web请求通过调用Shiro框架提供的注销方法来实现用户注销功能并将页面重定向到登录页面是实现用户退出登录操作的关键部分。
@Controller
public class LogoutController {
@RequestMapping(path="logout")
/**
* "logout"
* @RequestMapping"logout"
* ModelAndViewShiroUtils
*
* @param model ModelAndView"login"使Spring MVC
* @return "login"ModelAndViewSpring MVC
*/
@RequestMapping(path = "logout")
public ModelAndView logout(ModelAndView model) {
// 调用ShiroUtils工具类的logout方法该方法会触发Shiro框架执行用户注销的相关操作清除当前用户的认证信息、会话数据等相关内容使当前用户退出登录状态确保用户注销后相关数据的安全性以及资源的合理释放。
ShiroUtils.logout();
// 设置要返回的视图名称为"login"这样Spring MVC在处理这个ModelAndView对象时会将页面重定向到登录页面方便用户在注销后重新进行登录操作或者进行其他相应的操作比如忘记密码等相关操作如果登录页面有提供相应入口的话
model.setViewName("login");
return model;
}
}
}

@ -15,40 +15,77 @@ import com.tamguo.modules.sys.model.condition.SysUserCondition;
import com.tamguo.modules.sys.model.enums.SysUserMgrTypeEnum;
import com.tamguo.modules.sys.service.ISysUserService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与安全管理员相关的Web请求调用相应的业务逻辑方法并根据处理结果返回给客户端合适的响应或者转发到对应的视图进行展示是实现安全管理员业务模块页面交互和数据处理的关键部分。
@Controller
@RequestMapping(path="sys/secAdmin")
// 通过@RequestMapping注解为这个控制器类下的所有请求路径设置一个公共的前缀即该控制器处理的请求路径都以"sys/secAdmin"开头,便于对安全管理员相关的各种请求进行统一管理和分类。
@RequestMapping(path = "sys/secAdmin")
public class SecAdminController {
// 定义一个常量字符串表示安全管理员列表页面或首页的视图名称遵循Spring MVC视图解析的配置规则对应着展示安全管理员列表相关内容的模板文件路径如JSP、Thymeleaf等模板文件的具体路径
private final String SECADMIN_INDEX_PAGE = "modules/sys/secAdmin/index";
// 定义常量字符串,代表安全管理员添加(或编辑相关信息,具体取决于业务逻辑)页面的视图名称,对应展示添加安全管理员信息相关内容的模板文件路径。
private final String SECADMIN_ADD_PAGE = "modules/sys/secAdmin/add";
// 通过@Autowired注解自动注入ISysUserService接口的实现类实例用于调用与系统用户这里特指安全管理员相关的用户操作因为从类名和业务逻辑推测处理的是安全管理员相关的业务相关的业务逻辑方法比如查询、保存、设置数据权限等操作实现控制器层与业务逻辑层的交互。
@Autowired
private ISysUserService iSysUserService;
@RequestMapping(path="index")
/**
* "sys/secAdmin/index"
* Spring MVC便
*
* @param model ModelAndViewSpring MVC
* @return SECADMIN_INDEX_PAGESpring MVC
*/
@RequestMapping(path = "index")
public String index(ModelAndView model) {
return SECADMIN_INDEX_PAGE;
}
@RequestMapping(path="add")
public ModelAndView add(String userCode , ModelAndView model) {
/**
* "sys/secAdmin/add"
* SECADMIN_ADD_PAGEISysUserServiceuserCodeModelAndViewiSysUserServiceselectUserDataScopeuserCodeModelAndViewModelAndView使Spring MVC
*
* @param userCode
* @param model ModelAndView
* @return SECADMIN_ADD_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "add")
public ModelAndView add(String userCode, ModelAndView model) {
model.setViewName(SECADMIN_ADD_PAGE);
model.addObject("user", iSysUserService.selectById(userCode));
model.addObject("userDataScopeList", iSysUserService.selectUserDataScope(userCode));
return model;
}
@RequestMapping(path="save")
/**
* "sys/secAdmin/save"JSON
* SysUserEntityModelAndViewISysUserServicesaveUserDataScopeSysUserMgrTypeEnum.SEC_ADMINResultResult.result
*
* @param user SysUserEntity
* @param model ModelAndView使Spring MVC
* @return ResultJSON
*/
@RequestMapping(path = "save")
@ResponseBody
public Result save(SysUserEntity user , ModelAndView model) {
iSysUserService.saveUserDataScope(user , SysUserMgrTypeEnum.SEC_ADMIN);
return Result.result(0, null, "【"+user.getUserName()+"】保存数据权限成功!");
public Result save(SysUserEntity user, ModelAndView model) {
iSysUserService.saveUserDataScope(user, SysUserMgrTypeEnum.SEC_ADMIN);
return Result.result(0, null, "【" + user.getUserName() + "】保存数据权限成功!");
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "sys/secAdmin/listData"POSTjqGrid使MapJSON
* SysUserConditionISysUserServicelistDataPage<SysUserEntity>MyBatis PlusResult.jqGridResultMap@ResponseBodyMapJSON
* RequestMethod.POSTPOST
*
* @param condition SysUserCondition使
* @return MapMapJSON
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(SysUserCondition condition) {
Page<SysUserEntity> page = iSysUserService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
}
}

@ -15,31 +15,59 @@ import com.tamguo.modules.sys.model.SysAreaEntity;
import com.tamguo.modules.sys.model.condition.SysAreaCondition;
import com.tamguo.modules.sys.service.ISysAreaService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与系统地区相关的Web请求它会根据不同的请求路径调用对应的业务逻辑方法然后将处理结果以合适的形式如视图展示或JSON数据返回反馈给客户端是实现地区业务模块在Web端交互的核心部分。
@Controller
@RequestMapping(path="sys/area")
// 通过@RequestMapping注解为这个控制器类下的所有请求路径设置一个公共的前缀表明该控制器主要处理以"sys/area"开头的请求,便于对地区相关的各类请求进行统一管理与分类。
@RequestMapping(path = "sys/area")
public class SysAreaController {
// 定义一个常量字符串表示地区列表页面通常作为地区管理模块的首页的视图名称遵循Spring MVC视图解析的配置规则其对应着实际用于展示地区列表相关内容的模板文件路径例如可能是JSP、Thymeleaf等模板文件的具体路径
private final String AREA_INDEX_PAGE = "modules/sys/area/index";
// 定义常量字符串,代表添加地区页面的视图名称,对应着展示添加地区相关表单及信息的模板文件路径,用于在添加新地区时向用户呈现相应的输入界面。
private final String AREA_ADD_PAGE = "modules/sys/area/add";
// 定义常量字符串,用于表示修改地区信息页面的视图名称,对应展示修改地区已有信息相关内容的模板文件路径,方便用户对已存在的地区记录进行编辑操作。
private final String AREA_UPDATE_PAGE = "modules/sys/area/update";
// 通过@Autowired注解自动注入ISysAreaService接口的实现类实例用于调用与地区相关的业务逻辑方法例如查询地区信息、保存地区数据、更新地区记录以及获取地区数据的树形结构等操作以此实现控制器层与业务逻辑层之间的交互完成地区相关业务的具体处理。
@Autowired
private ISysAreaService iSysAreaService;
@RequestMapping(path="index")
private ISysAreaService iSysAreaService;
/**
* "sys/area/index"
* AREA_INDEX_PAGESpring MVC
* ModelAndView
* @return AREA_INDEX_PAGESpring MVC
*/
@RequestMapping(path = "index")
public String index() {
return AREA_INDEX_PAGE;
}
@RequestMapping(path="add")
public ModelAndView add(String parentCode , ModelAndView model) {
/**
* "sys/area/add"
* AREA_ADD_PAGEISysAreaServiceparentCodeModelAndView便ModelAndView使Spring MVC
*
* @param parentCode
* @param model ModelAndView
* @return AREA_ADD_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "add")
public ModelAndView add(String parentCode, ModelAndView model) {
model.setViewName(AREA_ADD_PAGE);
model.addObject("parentArea", iSysAreaService.selectById(parentCode));
return model;
}
@RequestMapping(path="update")
public ModelAndView update(String areaCode , ModelAndView model) {
/**
* "sys/area/update"
* AREA_UPDATE_PAGEISysAreaServiceparentCodeModelAndView便便ModelAndView便Spring MVC
*
* @param areaCode
* @param model ModelAndView
* @return AREA_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(String areaCode, ModelAndView model) {
model.setViewName(AREA_UPDATE_PAGE);
SysAreaEntity area = iSysAreaService.selectById(areaCode);
SysAreaEntity parentArea = iSysAreaService.selectById(area.getParentCode());
@ -47,41 +75,69 @@ public class SysAreaController {
model.addObject("parentArea", parentArea);
return model;
}
@RequestMapping(path="save")
/**
* "sys/area/save"JSON
* SysAreaEntityISysAreaServicesaveResultResult.resultExceptionSupportresolverResultResult
*
* @param area SysAreaEntity
* @return ResultJSON
*/
@RequestMapping(path = "save")
@ResponseBody
public Result save(SysAreaEntity area) {
try {
iSysAreaService.save(area);
return Result.result(0, null, "保存【"+area.getAreaName()+"】地区成功!");
return Result.result(0, null, "保存【" + area.getAreaName() + "】地区成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("保存地区", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "sys/area/update"POSTJSON
* SysAreaEntityISysAreaServiceupdateResultExceptionSupportresolverResultResult便
* RequestMethod.POSTRESTfulPOST
*
* @param area SysAreaEntity
* @return ResultJSON
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SysAreaEntity area) {
try {
iSysAreaService.update(area);
return Result.result(0, null, "修改【"+area.getAreaName()+"】地区成功!");
return Result.result(0, null, "修改【" + area.getAreaName() + "】地区成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改地区", this.getClass(), e);
}
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "sys/area/listData"POSTJSON
* SysAreaConditionISysAreaServicelistDataList<SysAreaEntity>Spring MVC@ResponseBodyJSON便
*
* @param condition SysAreaCondition使
* @return JSON
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public List<SysAreaEntity> listData(SysAreaCondition condition) {
List<SysAreaEntity> list = iSysAreaService.listData(condition);
return list;
}
@RequestMapping(path="treeData")
/**
* "sys/area/treeData"JSON
* excludeIdISysAreaServicetreeDataJSONArrayJSON便@ResponseBodyJSON便
*
* @param excludeId
* @return JSONArrayJSON
*/
@RequestMapping(path = "treeData")
@ResponseBody
public JSONArray treeData(String excludeId) {
return iSysAreaService.treeData(excludeId);
}
}
}

@ -15,23 +15,42 @@ import com.tamguo.modules.sys.model.SysMenuEntity;
import com.tamguo.modules.sys.model.condition.SysMenuCondition;
import com.tamguo.modules.sys.service.ISysMenuService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与系统菜单相关的Web请求它依据不同的请求路径调用对应的业务逻辑方法来实现诸如菜单展示、保存、更新以及获取菜单列表、树形结构等功能并将处理结果以合适的形式视图展示或JSON数据返回反馈给客户端是系统菜单业务模块在Web端交互的关键部分。
@Controller
@RequestMapping(path="sys/menu")
// 通过@RequestMapping注解为该控制器类下所有请求路径设置公共前缀表明此控制器主要处理以"sys/menu"开头的请求,便于对系统菜单相关的各类请求进行统一管理和分类。
@RequestMapping(path = "sys/menu")
public class SysMenuController {
// 定义一个常量字符串表示系统菜单列表页面通常作为菜单管理模块的首页的视图名称按照Spring MVC视图解析的配置规则其对应着实际用于展示系统菜单列表相关内容的模板文件路径例如可能是JSP、Thymeleaf等模板文件的具体路径
private final String MENU_INDEX_PAGE = "modules/sys/menu/index";
// 定义常量字符串,代表修改系统菜单信息页面的视图名称,对应展示修改菜单已有信息相关内容的模板文件路径,方便用户对已存在的菜单记录进行编辑操作。
private final String MENU_UPDATE_PAGE = "modules/sys/menu/update";
// 通过@Autowired注解自动注入ISysMenuService接口的实现类实例用于调用与系统菜单相关的业务逻辑方法比如查询菜单信息、保存菜单数据、更新菜单记录以及获取菜单数据的树形结构、列表数据等操作以此实现控制器层与业务逻辑层之间的交互完成系统菜单相关业务的具体处理。
@Autowired
private ISysMenuService iSysMenuService;
@RequestMapping(path="index")
/**
* "sys/menu/index"
* MENU_INDEX_PAGESpring MVC
*
* @return MENU_INDEX_PAGESpring MVC
*/
@RequestMapping(path = "index")
public String index() {
return MENU_INDEX_PAGE;
}
@RequestMapping(path="update")
public ModelAndView update(String menuCode , ModelAndView model) {
/**
* "sys/menu/update"
* MENU_UPDATE_PAGEISysMenuServicemenuCodeparentCodeModelAndView便便ModelAndView便Spring MVC
*
* @param menuCode
* @param model ModelAndView
* @return MENU_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(String menuCode, ModelAndView model) {
model.setViewName(MENU_UPDATE_PAGE);
SysMenuEntity menu = iSysMenuService.selectById(menuCode);
SysMenuEntity parentMenu = iSysMenuService.selectById(menu.getParentCode());
@ -39,40 +58,71 @@ public class SysMenuController {
model.addObject("parentMenu", parentMenu);
return model;
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "sys/menu/listData"POSTJSON
* SysMenuConditionISysMenuServicelistDataList<SysMenuEntity>Spring MVC@ResponseBodyJSON便
*
* @param condition SysMenuCondition使
* @return JSON
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public List<SysMenuEntity> listData(SysMenuCondition condition) {
List<SysMenuEntity> list = iSysMenuService.listData(condition);
return list;
}
@RequestMapping(path="save")
/**
* "sys/menu/save"JSON
* SysMenuEntityISysMenuServicesaveResultResult.resultExceptionSupportresolverResultResult
*
* @param menu SysMenuEntity
* @return ResultJSON
*/
@RequestMapping(path = "save")
@ResponseBody
public Result save(SysMenuEntity menu) {
try {
iSysMenuService.save(menu);
return Result.result(0, null, "新增菜单【"+menu.getMenuName()+"】成功!");
return Result.result(0, null, "新增菜单【" + menu.getMenuName() + "】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("新增菜单", this.getClass(), e);
}
}
@RequestMapping(path="update" , method=RequestMethod.POST)
/**
* "sys/menu/update"POSTJSON
* SysMenuEntityISysMenuServiceupdateResultExceptionSupportresolverResultResult便
* RequestMethod.POSTRESTfulPOST
*
* @param menu SysMenuEntity
* @return ResultJSON
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result post(SysMenuEntity menu) {
try {
iSysMenuService.update(menu);
return Result.result(0, null, "修改菜单【"+menu.getMenuName()+"】成功!");
return Result.result(0, null, "修改菜单【" + menu.getMenuName() + "】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改菜单", this.getClass(), e);
}
}
@RequestMapping(path="treeData")
/**
* "sys/menu/treeData"JSON
* excludeIdsysCodeisShowNameOrigiSysMenuService.treeData使ISysMenuServicetreeDataexcludeIdJSONArrayJSON便@ResponseBodyJSON便
*
* @param excludeId
* @param sysCode 使
* @param isShowNameOrig 使
* @return JSONArrayJSON
*/
@RequestMapping(path = "treeData")
@ResponseBody
public JSONArray treeData(String excludeId , String sysCode , String isShowNameOrig) {
public JSONArray treeData(String excludeId, String sysCode, String isShowNameOrig) {
return iSysMenuService.treeData(excludeId);
}
}
}

@ -1,7 +1,6 @@
package com.tamguo.modules.sys.web;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -18,69 +17,133 @@ import com.tamguo.modules.sys.service.ISysOfficeService;
/**
* Controller -
*
* Spring MVCWeb
*
* JSONWeb
*
* @author tamguo
*
*/
@Controller
@RequestMapping(path="sys/office")
// 通过@RequestMapping注解为这个控制器类下所有请求路径设置公共前缀表明该控制器主要处理以"sys/office"开头的请求,便于对组织(机构)相关的各类请求进行统一管理与分类。
@RequestMapping(path = "sys/office")
public class SysOfficeController {
// 定义一个常量字符串表示添加组织机构页面的视图名称按照Spring MVC视图解析的配置规则其对应着实际用于展示添加机构相关表单及信息的模板文件路径例如可能是JSP、Thymeleaf等模板文件的具体路径用于在新增机构时向用户呈现相应的输入界面。
private final String OFFICE_ADD_PAGE = "modules/sys/office/add";
// 定义常量字符串,用于表示修改组织(机构)信息页面的视图名称,对应展示修改机构已有信息相关内容的模板文件路径,方便用户对已存在的机构记录进行编辑操作。
private final String OFFICE_UPDATE_PAGE = "modules/sys/office/update";
// 通过@Autowired注解自动注入ISysOfficeService接口的实现类实例用于调用与组织机构相关的业务逻辑方法例如查询机构信息、保存机构数据、更新机构记录以及获取机构数据的树形结构、列表数据等操作以此实现控制器层与业务逻辑层之间的交互完成组织机构相关业务的具体处理。
@Autowired
private ISysOfficeService iSysOfficeService;
@RequestMapping(path="add")
public ModelAndView add(String parentCode , ModelAndView model) {
private ISysOfficeService iSysOfficeService;
/**
* "sys/office/add"
* OFFICE_ADD_PAGE
* ISysOfficeServiceparentCodeModelAndView
* 便
* ModelAndView使Spring MVC
*
* @param parentCode
* @param model ModelAndView
* @return OFFICE_ADD_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "add")
public ModelAndView add(String parentCode, ModelAndView model) {
model.setViewName(OFFICE_ADD_PAGE);
model.addObject("parentOffice", iSysOfficeService.selectById(parentCode));
return model;
}
@RequestMapping(path="update")
public ModelAndView update(String officeCode , ModelAndView model) {
/**
* "sys/office/update"
* OFFICE_UPDATE_PAGE
* ISysOfficeServiceparentCodeModelAndView
* 便便ModelAndView便Spring MVC
*
* @param officeCode
* @param model ModelAndView
* @return OFFICE_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(String officeCode, ModelAndView model) {
model.setViewName(OFFICE_UPDATE_PAGE);
SysOfficeEntity office = iSysOfficeService.selectById(officeCode);
SysOfficeEntity parentOffice = iSysOfficeService.selectById(office.getParentCode());
model.addObject("office", office);
model.addObject("parentOffice" , parentOffice);
model.addObject("parentOffice", parentOffice);
return model;
}
@RequestMapping(path="listData")
/**
* "sys/office/listData"JSON
* SysOfficeCondition
* ISysOfficeServicelistDataList<SysOfficeEntity>
* Spring MVC@ResponseBodyJSON便
*
* @param condition SysOfficeCondition使
* @return JSON
*/
@RequestMapping(path = "listData")
@ResponseBody
public List<SysOfficeEntity> listData(SysOfficeCondition condition) {
return iSysOfficeService.listData(condition);
}
@RequestMapping(path="treeData")
/**
* "sys/office/treeData"JSON
* excludeId
* ISysOfficeServicetreeDataJSONArrayJSON便
* @ResponseBodyJSON便
*
* @param excludeId
* @return JSONArrayJSON
*/
@RequestMapping(path = "treeData")
@ResponseBody
public JSONArray treeData(String excludeId) {
return iSysOfficeService.treeData(excludeId);
}
@RequestMapping(path="save")
/**
* "sys/office/save"JSON
* SysOfficeEntity
* ISysOfficeServicesaveResultResult.result
* ExceptionSupportresolverResultResult
*
* @param office SysOfficeEntity
* @return ResultJSON
*/
@RequestMapping(path = "save")
@ResponseBody
public Result save(SysOfficeEntity office) {
try {
iSysOfficeService.save(office);
return Result.result(0, null, "新增机构【"+office.getOfficeName()+"】成功!");
return Result.result(0, null, "新增机构【" + office.getOfficeName() + "】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("新增机构", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "sys/office/update"POSTJSON
* SysOfficeEntityISysOfficeServiceupdateResult
* ExceptionSupportresolverResultResult便
* RequestMethod.POSTRESTfulPOST
*
* @param office SysOfficeEntity
* @return ResultJSON
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SysOfficeEntity office) {
try {
iSysOfficeService.update(office);
return Result.result(0, null, "修改机构【"+office.getOfficeName()+"】成功!");
return Result.result(0, null, "修改机构【" + office.getOfficeName() + "】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改机构", this.getClass(), e);
}
}
}
}

@ -6,18 +6,38 @@ import org.springframework.web.bind.annotation.RequestMapping;
/**
*
* Spring MVCSpring MVC
* 便Web"sys""tiku"
*/
@Controller
public class SysPageController {
/**
* "sys/{fn}/{page}"
* @PathVariable "fn" "page" "modules/sys/" "fn" "page"
* Spring MVCJSPThymeleaf
*
* @param fn @PathVariable
* @param page @PathVariable "fn"
* @return "modules/sys/" + fn + "/" + pageSpring MVC
*/
@RequestMapping("sys/{fn}/{page}")
public String sys(@PathVariable("fn") String fn , @PathVariable("page") String page){
public String sys(@PathVariable("fn") String fn, @PathVariable("page") String page) {
return "modules/sys/" + fn + "/" + page;
}
/**
* "tiku/{fn}/{page}" "sys"
* @PathVariable "fn" "page" "modules/tiku/" "fn" "page" Spring MVC
* 使
*
* @param fn @PathVariable
* @param page @PathVariable "fn"
* @return "modules/tiku/" + fn + "/" + pageSpring MVC
*/
@RequestMapping("tiku/{fn}/{page}")
public String ti(@PathVariable("fn") String fn , @PathVariable("page") String page){
public String ti(@PathVariable("fn") String fn, @PathVariable("page") String page) {
return "modules/tiku/" + fn + "/" + page;
}
}
}

@ -15,43 +15,85 @@ import com.tamguo.modules.sys.model.SysPostEntity;
import com.tamguo.modules.sys.model.condition.SysPostCondition;
import com.tamguo.modules.sys.service.ISysPostService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与系统岗位相关的Web请求调用相应的业务逻辑方法并根据处理结果返回给客户端合适的响应或者转发到对应的视图进行展示是实现岗位业务模块页面交互和数据处理的关键部分。
@Controller
@RequestMapping(path="sys/post")
// 通过@RequestMapping注解为这个控制器类下的所有请求路径设置一个公共的前缀即该控制器处理的请求路径都以"sys/post"开头,便于对岗位相关的各种请求进行统一管理和分类。
@RequestMapping(path = "sys/post")
public class SysPostController {
// 定义一个常量字符串表示岗位列表页面或首页的视图名称遵循Spring MVC视图解析的配置规则对应着展示岗位列表相关内容的模板文件路径如JSP、Thymeleaf等模板文件的具体路径
private final String POST_INDEX_PAGE = "modules/sys/post/index";
// 定义常量字符串,代表岗位信息更新页面的视图名称,对应展示修改岗位信息相关内容的模板文件路径。
private final String POST_UPDATE_PAGE = "modules/sys/post/update";
// 定义常量字符串,用于表示岗位添加页面的视图名称,对应展示添加新岗位相关内容的模板文件路径。
private final String POST_ADD_PAGE = "modules/sys/post/add";
// 通过@Autowired注解自动注入ISysPostService接口的实现类实例用于调用与系统岗位相关的业务逻辑方法比如查询、保存、更新岗位信息等操作实现控制器层与业务逻辑层的交互。
@Autowired
private ISysPostService iSysPostService;
@RequestMapping(path="index")
/**
* "sys/post/index"
* Spring MVC便
*
* @return POST_INDEX_PAGESpring MVC
*/
@RequestMapping(path = "index")
public String index() {
return POST_INDEX_PAGE;
}
@RequestMapping(path="update")
public ModelAndView update(ModelAndView model , String id) {
/**
* "sys/post/update"
* ModelAndView"修改岗位"ISysPostServiceidModelAndViewPOST_UPDATE_PAGEModelAndView使Spring MVC
*
* @param model ModelAndView
* @param id
* @return POST_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(ModelAndView model, String id) {
model.addObject("title", "修改岗位");
model.addObject("post", iSysPostService.selectById(id));
model.setViewName(POST_UPDATE_PAGE);
return model;
}
@RequestMapping(path="add")
/**
* "sys/post/add"
* POST_ADD_PAGE便Spring MVC
*
* @return POST_ADD_PAGESpring MVC
*/
@RequestMapping(path = "add")
public String add() {
return POST_ADD_PAGE;
}
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "sys/post/listData"POSTjqGrid使MapJSON
* SysPostConditionISysPostServicelistDataPage<SysPostEntity>MyBatis PlusResult.jqGridResultMap@ResponseBodyMapJSON
* RequestMethod.POSTPOST
*
* @param condition SysPostCondition使
* @return MapMapJSON
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(SysPostCondition condition) {
Page<SysPostEntity> page = iSysPostService.listData(condition);
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
}
@RequestMapping(path="save",method=RequestMethod.POST)
/**
* "sys/post/save"POSTJSON
* SysPostEntityISysPostServiceaddResultResult.resultExceptionSupportresolverResultResult
* RequestMethod.POSTRESTfulPOST
*
* @param post SysPostEntity
* @return ResultJSON
*/
@RequestMapping(path = "save", method = RequestMethod.POST)
@ResponseBody
public Result save(SysPostEntity post) {
try {
@ -61,8 +103,16 @@ public class SysPostController {
return ExceptionSupport.resolverResult("保存岗位", this.getClass(), e);
}
}
@RequestMapping(path="update",method=RequestMethod.POST)
/**
* "sys/post/update"POSTJSON
* SysPostEntityISysPostServiceupdateResultExceptionSupportresolverResultResult便
* RequestMethod.POSTRESTfulPOST
*
* @param post SysPostEntity
* @return ResultJSON
*/
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SysPostEntity post) {
try {
@ -71,6 +121,6 @@ public class SysPostController {
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改岗位", this.getClass(), e);
}
}
}
}

@ -18,50 +18,81 @@ import com.tamguo.modules.sys.model.condition.SysRoleCondition;
import com.tamguo.modules.sys.service.ISysRoleDataScopeService;
import com.tamguo.modules.sys.service.ISysRoleService;
// 使用@Controller注解将这个类标记为Spring MVC中的控制器类负责处理与系统角色相关的Web请求通过调用相应的业务逻辑服务方法实现诸如角色信息查询、角色授权包括菜单权限、数据权限等、角色列表展示、角色的增删改等功能并将处理结果以合适的形式视图展示或JSON数据返回反馈给客户端是系统角色业务模块在Web端交互操作的核心部分。
@Controller
@RequestMapping(path="sys/role")
// 通过@RequestMapping注解为该控制器类下所有请求路径设置公共前缀表明此控制器主要处理以"sys/role"开头的请求,便于对系统角色相关的各类请求进行统一管理和分类。
@RequestMapping(path = "sys/role")
public class SysRoleController {
// 分配角色菜单权限
// 分配角色菜单权限页面的视图名称按照Spring MVC视图解析的配置规则对应着实际用于展示分配角色菜单权限相关内容的模板文件路径例如可能是JSP、Thymeleaf等模板文件的具体路径用于在为角色分配菜单权限时向用户呈现相应的操作界面。
private final String ROLE_MENU_INDEX_PAGE = "modules/sys/role/menu";
// 数据权限
// 数据权限页面的视图名称,对应展示角色数据权限相关内容的模板文件路径,方便用户对角色的数据权限进行设置等操作。
private final String ROLE_DATA_INDEX_PAGE = "modules/sys/role/dataScope";
// 修改角色
// 修改角色信息页面的视图名称,对应展示修改角色已有信息相关内容的模板文件路径,便于用户对已存在的角色记录进行编辑操作。
private final String ROLE_MENU_UPDATE_PAGE = "modules/sys/role/update";
// 通过@Autowired注解自动注入ISysRoleService接口的实现类实例用于调用与系统角色相关的业务逻辑方法比如查询角色信息、保存角色数据、更新角色记录、角色授权菜单权限、数据权限等等操作以此实现控制器层与业务逻辑层之间的交互完成系统角色相关业务的主要处理。
@Autowired
private ISysRoleService iSysRoleService;
// 通过@Autowired注解自动注入ISysRoleDataScopeService接口的实现类实例用于专门处理角色数据权限相关的业务逻辑操作例如查询角色的数据权限列表、保存角色的数据权限设置等辅助完成角色数据权限方面的业务处理与ISysRoleService共同协作实现完整的角色相关业务功能。
@Autowired
private ISysRoleDataScopeService iSysRoleDataScopeService;
/** 角色授权功能菜单*/
@RequestMapping(path="menu")
public ModelAndView menu(String roleCode , ModelAndView model) {
/**
*
* "sys/role/menu"ISysRoleServiceroleCodeModelAndViewROLE_MENU_INDEX_PAGEModelAndView使Spring MVC便
*
* @param roleCode
* @param model ModelAndView
* @return ROLE_MENU_INDEX_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "menu")
public ModelAndView menu(String roleCode, ModelAndView model) {
model.addObject("role", iSysRoleService.selectById(roleCode));
model.setViewName(ROLE_MENU_INDEX_PAGE);
return model;
}
/** 修改角色*/
@RequestMapping(path="update")
public ModelAndView update(String roleCode , ModelAndView model) {
/**
*
* "sys/role/update"GETPOSTGETISysRoleServiceroleCodeModelAndViewROLE_MENU_UPDATE_PAGEModelAndView便Spring MVC便
*
* @param roleCode
* @param model ModelAndView
* @return ROLE_MENU_UPDATE_PAGEModelAndViewSpring MVC
*/
@RequestMapping(path = "update")
public ModelAndView update(String roleCode, ModelAndView model) {
model.addObject("role", iSysRoleService.selectById(roleCode));
model.setViewName(ROLE_MENU_UPDATE_PAGE);
return model;
}
/** 数据权限 */
/**
*
* "sys/role/dataScope"ISysRoleServiceroleCodeModelAndViewISysRoleDataScopeServiceMyBatis PlusCondition.create().eq("role_code", roleCode)ModelAndViewROLE_DATA_INDEX_PAGEModelAndView使Spring MVC便
*
* @param roleCode
* @param model ModelAndView
* @return ROLE_DATA_INDEX_PAGEModelAndViewSpring MVC
*/
@SuppressWarnings("unchecked")
@RequestMapping(path="dataScope")
public ModelAndView dataScope(String roleCode , ModelAndView model) {
@RequestMapping(path = "dataScope")
public ModelAndView dataScope(String roleCode, ModelAndView model) {
model.addObject("role", iSysRoleService.selectById(roleCode));
model.addObject("roleDataScopeList" , iSysRoleDataScopeService.selectList(Condition.create().eq("role_code", roleCode)));
model.addObject("roleDataScopeList", iSysRoleDataScopeService.selectList(Condition.create().eq("role_code", roleCode)));
model.setViewName(ROLE_DATA_INDEX_PAGE);
return model;
}
/** 角色列表数据*/
@RequestMapping(path="listData",method=RequestMethod.POST)
/**
* "sys/role/listData"POSTjqGrid使MapJSON
* SysRoleConditionISysRoleServicelistDataPage<SysRoleEntity>MyBatis PlusResult.jqGridResultMap@ResponseBodyMapJSONExceptionSupportresolverResultnull
*
* @param condition SysRoleCondition使
* @return MapMapJSONnull
*/
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(SysRoleCondition condition) {
try {
@ -72,9 +103,15 @@ public class SysRoleController {
return null;
}
}
/** 菜单树*/
@RequestMapping(path="menuTreeData")
/**
* "sys/role/menuTreeData"便JSON
* roleCodeISysRoleServicemenuTreeDataroleCodeMap<String, Object>@ResponseBodyJSONExceptionSupportresolverResultnull
*
* @param roleCode
* @return Map<String, Object>JSONnull
*/
@RequestMapping(path = "menuTreeData")
@ResponseBody
public Map<String, Object> menuTreeData(String roleCode) {
try {
@ -83,80 +120,45 @@ public class SysRoleController {
ExceptionSupport.resolverResult("菜单树", this.getClass(), e);
return null;
}
}
/** 角色授权功能菜单 */
@RequestMapping(path="allowMenuPermission",method=RequestMethod.POST)
/**
* JSON
* SysRoleEntityISysRoleServiceallowMenuPermissionResultResult.resultExceptionSupportresolverResultResult
*
* @param role SysRoleEntity
* @return ResultJSON
*/
@RequestMapping(path = "allowMenuPermission", method = RequestMethod.POST)
@ResponseBody
public Result allowMenuPermission(SysRoleEntity role) {
try {
iSysRoleService.allowMenuPermission(role);
return Result.result(0, null, "保存角色【"+role.getRoleName()+"】成功!");
return Result.result(0, null, "保存角色【" + role.getRoleName() + "】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("授权功能菜单", this.getClass(), e);
}
}
/** 数据权限 */
@RequestMapping(path="allowDataScope",method=RequestMethod.POST)
/**
* JSON
* SysRoleEntityISysRoleServiceallowDataScopeResultExceptionSupportresolverResultResult便
*
* @param role SysRoleEntity
* @return ResultJSON
*/
@RequestMapping(path = "allowDataScope", method = RequestMethod.POST)
@ResponseBody
public Result allowDataScope(SysRoleEntity role) {
try {
iSysRoleService.allowDataScope(role);
return Result.result(0, null, "保存角色【"+role.getRoleName()+"】成功!");
return Result.result(0, null, "保存角色【" + role.getRoleName() + "】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("授权数据权限", this.getClass(), e);
}
}
/** 授权用户 */
@RequestMapping(path="allowUser",method=RequestMethod.POST)
@ResponseBody
public Result allowUser(SysRoleEntity role) {
try {
iSysRoleService.allowDataScope(role);
return Result.result(0, null, "保存角色【"+role.getRoleName()+"】成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("授权用户", this.getClass(), e);
}
}
/** 角色树结构*/
@RequestMapping(path="treeData",method=RequestMethod.POST)
@ResponseBody
public JSONArray treeData(String userType){
try {
return iSysRoleService.treeDate(userType);
} catch (Exception e) {
ExceptionSupport.resolverResult("角色树", this.getClass(), e);
return null;
}
}
/** 修改角色*/
@RequestMapping(path="update",method=RequestMethod.POST)
@ResponseBody
public Result update(SysRoleEntity role) {
try {
iSysRoleService.update(role);
return Result.result(0, null, "角色【"+role.getRoleName()+"】修改成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改角色", this.getClass(), e);
}
}
/** 新增角色*/
@RequestMapping(path="save",method=RequestMethod.POST)
@ResponseBody
public Result save(SysRoleEntity role) {
try {
iSysRoleService.save(role);
return Result.result(0, null, "角色【"+role.getRoleName()+"】新增成功!");
} catch (Exception e) {
return ExceptionSupport.resolverResult("新增角色", this.getClass(), e);
}
}
}
/**
* iSysRoleService.allowDataScopeJSON
* SysRoleEntityiSysRoleService.allowDataScopeResultExceptionSupportresolverResultResult便

@ -17,10 +17,17 @@ import com.tamguo.modules.sys.model.condition.SysUserCondition;
import com.tamguo.modules.sys.service.ISysPostService;
import com.tamguo.modules.sys.service.ISysUserService;
// @Controller注解表明这个类是Spring MVC框架中的控制器类用于处理Web请求在此处主要负责处理与系统用户相关的各类请求
// 它会协调视图展示以及调用相应的业务逻辑服务来完成具体的用户业务操作,是连接前端页面和后端业务逻辑的关键部分。
@Controller
@RequestMapping(path="sys/user")
// @RequestMapping注解为这个控制器类下的所有请求路径设置一个公共的前缀意味着该控制器主要处理以"sys/user"开头的请求,
// 这样的设置便于对系统用户相关的众多请求进行分类管理,使代码结构更清晰,便于后续的维护和扩展。
@RequestMapping(path = "sys/user")
public class SysUserController {
// 以下定义了多个常量字符串分别代表不同用户相关页面的视图名称按照Spring MVC的视图解析机制这些字符串对应着具体的模板文件路径例如JSP、Thymeleaf等模板文件所在的实际路径
// 用于在不同业务场景下展示相应的用户页面内容。
/** 用户列表*/
private final String USER_LIST_PAGE = "modules/sys/user/list";
/** 修改*/
@ -31,153 +38,277 @@ public class SysUserController {
private final String USER_ROLE_PAGE = "modules/sys/user/role";
/** 数据权限*/
private final String USER_DATA_SCOPE_PAGE = "modules/sys/user/dataScope";
// 通过@Autowired注解自动注入ISysUserService接口的实现类实例ISysUserService接口应该定义了许多与系统用户业务相关的方法
// 例如查询用户信息、保存用户数据、更新用户记录、管理用户角色分配、处理用户数据权限以及对用户状态进行操作等,
// 通过注入该实例,本控制器类能够方便地调用这些业务逻辑方法来实现各种用户相关的功能,完成与业务逻辑层的交互。
@Autowired
private ISysUserService iSysUserService;
// 同样通过@Autowired注解注入ISysPostService接口的实现类实例ISysPostService主要用于处理与岗位相关的业务逻辑
// 例如查询岗位列表等操作,由于在系统中用户通常与岗位存在关联关系(比如用户属于某个岗位),所以在这里注入该服务实例,
// 可以辅助完成涉及岗位相关信息查询等的用户业务处理。
@Autowired
private ISysPostService iSysPostService;
// 处理路径为"sys/user/list"的请求方法,用于准备并返回用户列表页面相关的数据和视图信息。
// 当客户端发起此请求时,该方法会被调用,主要完成设置视图名称以及向视图传递岗位列表数据的操作,使得页面能够展示相应内容。
@SuppressWarnings("unchecked")
@RequestMapping(path="list")
@RequestMapping(path = "list")
public ModelAndView list(ModelAndView model) {
// 设置要返回的视图名称为用户列表页面的视图名称USER_LIST_PAGE这样Spring MVC就能根据这个名称找到对应的模板文件进行渲染展示。
model.setViewName(USER_LIST_PAGE);
// 通过ISysPostService的selectList方法结合MyBatis Plus的条件构造器Condition.create().eq("status", "normal"))查询状态为正常的岗位列表,
// 并将查询到的岗位列表数据添加到ModelAndView对象中以便在视图层可以获取并展示这些岗位信息可能用于在用户列表页面关联显示用户所属岗位等情况。
model.addObject("postList", iSysPostService.selectList(Condition.create().eq("status", "normal")));
// 返回包含了视图名称和岗位列表数据的ModelAndView对象供Spring MVC进行后续的视图渲染操作最终将用户列表页面展示给客户端。
return model;
}
// 处理路径为"sys/user/add"的请求方法,目的是准备并返回新增用户页面相关的数据和视图,让客户端可以进入新增用户的操作界面。
@SuppressWarnings("unchecked")
@RequestMapping(path="add")
public ModelAndView add(String userCode , ModelAndView model) {
@RequestMapping(path = "add")
public ModelAndView add(String userCode, ModelAndView model) {
// 设置返回的视图名称为新增用户页面的视图名称USER_ADD_PAGE以便Spring MVC找到对应的模板文件进行页面展示。
model.setViewName(USER_ADD_PAGE);
// 同样查询状态为正常的岗位列表数据通过ISysPostService并添加到ModelAndView对象中方便在新增用户页面上展示岗位信息
// 例如让用户选择所属岗位等操作虽然当前传入了userCode参数但在此处代码逻辑中暂时未对其进行实质性使用可能后续会用于预填充部分信息等扩展功能
model.addObject("postList", iSysPostService.selectList(Condition.create().eq("status", "normal")));
// 返回包含了视图名称和岗位列表数据的ModelAndView对象供Spring MVC渲染展示新增用户页面给客户端。
return model;
}
@RequestMapping(path="role")
public ModelAndView role(String userCode , ModelAndView model) {
// 处理路径为"sys/user/role"的请求方法,负责准备并返回分配用户角色页面相关的数据和视图,以便在页面上进行用户角色分配的相关操作。
@RequestMapping(path = "role")
public ModelAndView role(String userCode, ModelAndView model) {
// 设置要返回的视图名称为分配用户角色页面的视图名称USER_ROLE_PAGE使Spring MVC能找到对应的模板文件进行渲染展示该页面。
model.setViewName(USER_ROLE_PAGE);
// 通过ISysUserService的selectById方法依据传入的userCode参数用于指定具体的用户一般是用户的唯一标识比如用户编号等查询对应的用户信息
// 并将查询到的用户对象添加到ModelAndView对象中这样在视图层就能展示该用户的相关基本信息方便进行角色分配操作时参考。
model.addObject("user", iSysUserService.selectById(userCode));
// 调用ISysUserService的findUserRole方法同样依据userCode参数查询该用户已分配的角色列表
// 然后将角色列表数据添加到ModelAndView对象中使得在分配用户角色页面上能够展示用户当前已有的角色情况方便进行角色调整等操作。
model.addObject("userRoleList", iSysUserService.findUserRole(userCode));
// 返回包含了视图名称、用户对象以及用户角色列表数据的ModelAndView对象供Spring MVC进行视图渲染展示分配用户角色页面给客户端。
return model;
}
@RequestMapping(path="dataScope")
public ModelAndView dataScope(String userCode , ModelAndView model) {
// 处理路径为"sys/user/dataScope"的请求方法,用于准备并返回用户数据权限页面相关的数据和视图,便于在页面上对用户的数据权限进行设置等操作。
@RequestMapping(path = "dataScope")
public ModelAndView dataScope(String userCode, ModelAndView model) {
// 设置返回的视图名称为用户数据权限页面的视图名称USER_DATA_SCOPE_PAGE让Spring MVC可以找到对应的模板文件进行页面渲染展示。
model.setViewName(USER_DATA_SCOPE_PAGE);
// 通过ISysUserService的selectById方法根据传入的userCode参数查询对应的用户信息并添加到ModelAndView对象中
// 以便在视图层展示用户的基本信息,为设置数据权限提供参考依据。
model.addObject("user", iSysUserService.selectById(userCode));
// 调用ISysUserService的selectUserDataScope方法依据userCode参数查询该用户的数据权限列表
// 再将查询到的数据权限列表数据添加到ModelAndView对象中使得在用户数据权限页面上可以展示用户当前的数据权限情况方便进行权限设置调整操作。
model.addObject("userDataScopeList", iSysUserService.selectUserDataScope(userCode));
// 返回包含了视图名称、用户对象以及用户数据权限列表数据的ModelAndView对象供Spring MVC进行视图渲染展示用户数据权限页面给客户端。
return model;
}
// 处理路径为"sys/user/update"的请求方法此路径下一般会有两个方法一个用于处理GET请求展示修改页面一个用于处理POST请求提交修改内容这里是处理GET请求展示页面的情况
// 主要功能是准备并返回修改用户信息页面相关的数据和视图,让用户可以看到要修改的用户信息详情并进行编辑操作。
@SuppressWarnings("unchecked")
@RequestMapping(path="update")
public ModelAndView update(String userCode , ModelAndView model) {
@RequestMapping(path = "update")
public ModelAndView update(String userCode, ModelAndView model) {
// 设置要返回的视图名称为修改用户信息页面的视图名称USER_UPDATE_PAGE以便Spring MVC找到对应的模板文件进行页面渲染展示。
model.setViewName(USER_UPDATE_PAGE);
// 通过ISysUserService的selectById方法依据传入的userCode参数指定要修改的用户的唯一标识查询对应的用户信息
// 并将查询到的用户对象添加到ModelAndView对象中使得在修改页面上能展示用户的当前信息方便用户进行编辑修改。
model.addObject("user", iSysUserService.selectById(userCode));
// 通过ISysPostService的selectList方法结合条件构造器Condition.create().eq("status", "0"))查询状态为特定值(这里"0"可能表示正常等可用状态,具体取决于业务中岗位状态定义)的岗位列表,
// 然后将岗位列表数据添加到ModelAndView对象中方便在修改用户信息页面上展示岗位相关信息比如让用户可以重新选择所属岗位等操作。
model.addObject("postList", iSysPostService.selectList(Condition.create().eq("status", "0")));
// 调用ISysUserService的queryUserPostByUserCode方法依据userCode参数查询该用户所属岗位编号等相关信息
// 并将这些信息添加到ModelAndView对象中以便在修改页面上展示用户当前所属岗位的具体情况辅助用户进行相关信息的修改。
model.addObject("userPostCode", iSysUserService.queryUserPostByUserCode(userCode));
// 返回包含了视图名称、用户对象、岗位列表数据以及用户所属岗位编号相关信息的ModelAndView对象供Spring MVC进行视图渲染展示修改用户信息页面给客户端。
return model;
}
/** 列表*/
@RequestMapping(path="listData",method=RequestMethod.POST)
// 处理路径为"sys/user/listData"且请求方法为POST的请求的请求方法用于查询并返回符合条件的用户列表数据
// 返回结果会以适合前端表格组件如jqGrid等使用的格式包装在Map中并以JSON格式响应给客户端方便前端进行数据展示和分页等操作。
@RequestMapping(path = "listData", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> listData(SysUserCondition condition) {
try {
// 通过ISysUserService的listData方法依据传入的SysUserCondition对象该对象用于封装查询用户列表的各种条件比如查询关键字、分页信息、用户状态筛选等条件查询用户列表
// 返回的结果是一个Page<SysUserEntity>对象它是MyBatis Plus分页插件生成的分页后的用户实体对象列表包含了相关的分页信息总记录数、每页记录数、当前页码、总页数等
Page<SysUserEntity> page = iSysUserService.listData(condition);
// 调用Result类的jqGridResult方法将分页信息以及实际的用户记录数据进行整合包装成一个Map对象这个Map对象的格式符合前端表格组件期望的格式
// 以便前端能够方便地解析并展示用户列表数据以及进行分页等相关操作。
return Result.jqGridResult(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent(), page.getPages());
} catch (Exception e) {
// 如果在查询用户列表数据过程中出现异常调用ExceptionSupport的resolverResult方法处理异常
// 该方法可能会进行一些异常记录、日志输出等操作并返回一个相应的处理结果在这里返回null表示查询出现问题方便客户端根据返回结果判断是否获取到正确的用户列表数据以及是否出现异常情况。
ExceptionSupport.resolverResult("查询用户列表", this.getClass(), e);
return null;
}
}
/** 校验登录账号*/
@RequestMapping(path="checkLoginCode",method=RequestMethod.GET)
// 处理路径为"sys/user/checkLoginCode"且请求方法为GET的请求的请求方法用于校验登录账号是否可用例如检查新输入的登录账号是否已存在或者与原登录账号对比是否符合修改规则等情况
// 并返回校验结果给客户端结果以布尔值形式响应true表示可用false表示不可用方便前端根据校验结果进行相应的提示或后续操作。
@RequestMapping(path = "checkLoginCode", method = RequestMethod.GET)
@ResponseBody
public Boolean checkLoginCode(String oldLoginCode , String loginCode) {
return iSysUserService.checkLoginCode(oldLoginCode , loginCode);
public Boolean checkLoginCode(String oldLoginCode, String loginCode) {
// 直接调用ISysUserService的checkLoginCode方法传入旧登录账号oldLoginCode和新登录账号loginCode两个参数进行账号可用性校验
// 并将校验结果(布尔值)直接返回给客户端,由前端根据这个结果来决定后续的操作,比如是否允许修改登录账号等。
return iSysUserService.checkLoginCode(oldLoginCode, loginCode);
}
/** 更新用户*/
@RequestMapping(path="update",method=RequestMethod.POST)
// 处理路径为"sys/user/update"且请求方法为POST的请求的请求方法用于更新用户信息当客户端提交修改后的用户信息时此方法会被调用进行实际的更新操作
// 并返回更新操作的结果给客户端结果以JSON格式响应告知客户端更新是否成功以及相关提示信息等内容。
@RequestMapping(path = "update", method = RequestMethod.POST)
@ResponseBody
public Result update(SysUserEntity user) {
try {
// 调用ISysUserService的update方法传入包含了更新后用户信息的SysUserEntity对象进行用户信息的更新操作
// 如果更新操作成功通过Result类的result方法构建一个包含成功状态码0表示成功、提示信息表明保存用户成功以及用户的名称等相关内容以及空数据的Result对象返回给客户端。
iSysUserService.update(user);
return Result.result(0, null, "保存用户【"+user.getUserName()+"】成功!");
return Result.result(0, null, "保存用户【" + user.getUserName() + "】成功!");
} catch (Exception e) {
// 如果在更新用户信息过程中出现异常调用ExceptionSupport的resolverResult方法处理异常
// 并将处理后的结果同样包装在Result对象中返回给客户端客户端可以根据返回的Result对象判断更新操作是否成功以及获取相应的提示信息等。
return ExceptionSupport.resolverResult("更新用户", this.getClass(), e);
}
}
/** 保存用户*/
@RequestMapping(path="save",method=RequestMethod.POST)
// 处理路径为"sys/user/save"且请求方法为POST的请求的请求方法用于保存新用户信息将客户端提交的新用户相关数据保存到数据库等存储介质中
// 并返回保存操作的结果给客户端结果以JSON格式响应告知客户端保存是否成功以及相应提示信息。
@RequestMapping(path = "save", method = RequestMethod.POST)
@ResponseBody
public Result save(SysUserEntity user) {
try {
// 调用ISysUserService的save方法传入包含新用户信息的SysUserEntity对象进行保存新用户信息的操作
// 如果保存操作成功同样通过Result类的result方法构建一个包含成功状态码、提示信息表明保存用户成功以及用户的名称等相关内容以及空数据的Result对象返回给客户端。
iSysUserService.save(user);
return Result.result(0, null, "保存用户【"+user.getUserName()+"】成功!");
return Result.result(0, null, "保存用户【" + user.getUserName() + "】成功!");
} catch (Exception e) {
// 如果在保存新用户信息过程中出现异常调用ExceptionSupport的resolverResult方法处理异常
// 并将处理后的结果包装在Result对象中返回给客户端方便客户端知晓保存操作是否成功以及获取相应的提示信息等。
return ExceptionSupport.resolverResult("保存用户", this.getClass(), e);
}
}
/** 授权用户角色*/
@RequestMapping(path="allowUserRole",method=RequestMethod.POST)
// 处理路径为"sys/user/allowUserRole"且请求方法为POST的请求的请求方法用于授权用户角色即对用户的角色进行分配或调整操作
// 并返回授权操作的结果给客户端结果以JSON格式响应告知客户端角色分配是否成功以及相关提示信息等内容。
/**
*
* SysUserEntity
*
* "sys/user/allowUserRole" POST
* 使 @ResponseBody JSON 便
*/
@RequestMapping(path = "allowUserRole", method = RequestMethod.POST)
@ResponseBody
public Result allowUserRole(SysUserEntity user) {
try {
// 调用 iSysUserService 的 allowUserRole 方法,传入包含了用户相关信息以及角色分配相关设置的 SysUserEntity 对象,
// 由业务逻辑层去执行具体的用户角色授权逻辑,比如将用户与指定的角色在数据库中建立关联关系等操作,以完成角色分配的业务需求。
iSysUserService.allowUserRole(user);
return Result.result(0, null, "【"+user.getUserName()+"】分配角色成功!");
// 如果角色授权操作成功,通过 Result 类的 result 方法构建一个 Result 对象返回给客户端。
// 该 Result 对象包含了表示操作成功的状态码(这里使用 0 表示成功)、提示信息(表明【用户名称】分配角色成功,方便客户端展示友好且明确的提示内容告知用户操作结果,其中用户名称通过 user.getUserName() 获取)以及空的数据部分(因为在此场景下,成功授权角色后通常不需要额外返回具体的数据)。
return Result.result(0, null, "【" + user.getUserName() + "】分配角色成功!");
} catch (Exception e) {
// 如果在执行用户角色授权操作过程中出现异常,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 这个方法可能会进行一些诸如记录异常详细信息到日志、根据异常类型返回合适的错误提示信息等操作,并将处理后的结果(同样包装在 Result 对象中)返回给客户端,
// 客户端可以根据接收到的 Result 对象判断角色分配操作是否成功以及获取相应的异常提示信息,以便进行后续的处理(如向用户展示错误提示等)。
return ExceptionSupport.resolverResult("分配角色", this.getClass(), e);
}
}
/** 保存用户数据权限*/
@RequestMapping(path="saveUserDataScope",method=RequestMethod.POST)
/**
*
* SysUserEntity
*
* "sys/user/saveUserDataScope" POST
* @ResponseBody JSON 便
*/
@RequestMapping(path = "saveUserDataScope", method = RequestMethod.POST)
@ResponseBody
public Result saveUserDataScope(SysUserEntity user) {
try {
// 调用 iSysUserService 的 saveUserDataScope 方法,传入包含了用户信息以及要保存的数据权限相关设置的 SysUserEntity 对象,
// 由业务逻辑层执行具体的保存用户数据权限的逻辑,例如将用户的数据权限配置信息持久化存储到数据库等操作,以满足数据权限设置保存的业务需求。
iSysUserService.saveUserDataScope(user);
return Result.result(0, null, "【"+user.getUserName()+"】保存数据权限成功!");
// 若保存用户数据权限操作成功,使用 Result 类的 result 方法创建一个 Result 对象返回给客户端。
// 该 Result 对象包含表示成功的状态码0 表示成功)、提示信息(表明【用户名称】保存数据权限成功,便于客户端向用户展示清晰的操作成功提示,其中用户名称通过 user.getUserName() 获取)以及空的数据部分(通常保存成功后不需要额外返回其他数据)。
return Result.result(0, null, "【" + user.getUserName() + "】保存数据权限成功!");
} catch (Exception e) {
// 当保存用户数据权限操作出现异常时,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 此方法会进行如记录异常详情到日志、根据异常生成合适的错误提示信息等操作,然后将处理后的结果(包装在 Result 对象中)返回给客户端,
// 客户端可依据接收到的 Result 对象判断保存操作是否成功以及获取相应的异常提示,进而进行后续的处理(例如向用户展示错误提示等)。
return ExceptionSupport.resolverResult("保存数据权限", this.getClass(), e);
}
}
@RequestMapping(path="disable",method=RequestMethod.POST)
/**
*
* userCode
*
* "sys/user/disable" POST
* @ResponseBody JSON 便
*/
@RequestMapping(path = "disable", method = RequestMethod.POST)
@ResponseBody
public Result disable(String userCode) {
try {
// 调用 iSysUserService 的 disable 方法传入表示要停用用户的唯一标识userCode比如用户编号等
// 由业务逻辑层去执行具体的停用用户的逻辑,例如在数据库中将用户的状态标记为停用状态等操作,以实现停用用户的业务需求。
return iSysUserService.disable(userCode);
} catch (Exception e) {
// 若在停用用户操作过程中出现异常,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 该方法可能会记录异常信息到日志、返回合适的错误提示等操作,并返回处理后的结果(此处返回 null表示操作出现问题未能正常停用用户
// 客户端可以根据接收到的返回值判断停用操作是否成功以及是否出现异常情况,进而进行相应的处理(如向用户展示错误提示等)。
ExceptionSupport.resolverResult("停用用户", this.getClass(), e);
return null;
}
}
@RequestMapping(path="enable",method=RequestMethod.POST)
/**
*
* userCode
*
* "sys/user/enable" POST
* @ResponseBody JSON 便
*/
@RequestMapping(path = "enable", method = RequestMethod.POST)
@ResponseBody
public Result enable(String userCode) {
try {
// 调用 iSysUserService 的 enable 方法传入代表要激活用户的唯一标识userCode
// 由业务逻辑层去执行具体的激活用户的逻辑,比如在数据库中将用户的状态修改为激活状态等操作,以此实现激活用户的业务要求。
return iSysUserService.enable(userCode);
} catch (Exception e) {
// 当激活用户操作出现异常时,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 此方法会进行记录异常信息、返回合适的错误提示等操作,然后返回处理后的结果(返回 null 表示操作失败,出现异常),
// 客户端可根据接收到的返回值判断激活操作是否成功以及是否有异常发生,进而进行后续处理(例如向用户展示错误提示等)。
ExceptionSupport.resolverResult("激活用户", this.getClass(), e);
return null;
}
}
@RequestMapping(path="delete",method=RequestMethod.POST)
/**
*
* userCode
*
* "sys/user/delete" POST
* 使 @ResponseBody JSON 便
*/
@RequestMapping(path = "delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(String userCode) {
try {
// 调用 iSysUserService 的 delete 方法传入用于标识要删除用户的用户编号userCode
// 由业务逻辑层去执行具体的删除用户的逻辑,例如从数据库中删除该用户的相关记录等操作,以完成删除用户的业务需求。
return iSysUserService.delete(userCode);
} catch (Exception e) {
// 若在删除用户操作过程中出现异常,调用 ExceptionSupport 的 resolverResult 方法来处理异常情况。
// 该方法可能会记录异常详情到日志、返回合适的错误提示等操作,并返回处理后的结果(返回 null 表示操作失败,出现异常),
// 客户端可以根据接收到的返回值判断删除操作是否成功以及是否出现异常情况,进而进行相应的处理(如向用户展示错误提示等)。
ExceptionSupport.resolverResult("删除用户", this.getClass(), e);
return null;
}
}
}
}

@ -14,30 +14,67 @@ import com.tamguo.common.utils.ExceptionSupport;
import com.tamguo.common.utils.SystemConstant;
import com.tamguo.modules.sys.utils.ShiroUtils;
// 使用 @Controller 注解将该类标记为 Spring MVC 中的控制器类,表明它主要负责处理与验证码相关的 Web 请求,
// 通过调用相关工具类和方法来生成验证码图片以及验证用户输入的验证码是否正确等操作,是系统中验证码功能模块在 Web 层面交互的核心组件。
@Controller
public class ValidCodeController {
/**
*
* "validCode"便使
* HttpServletRequest HttpServletResponse
* ServletException IOException Servlet
*
* @param request HttpServletRequest 使
* @param response HttpServletResponse
* @throws ServletException Servlet Servlet
* @throws IOException I/O
*/
@RequestMapping("validCode")
public void validCode(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException {
public void validCode(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 设置响应头的 "Cache-Control" 属性,值为 "no-store, no-cache",目的是告诉浏览器不要缓存该响应内容,
// 因为验证码通常是每次请求都需要重新生成和验证的,不希望浏览器使用缓存的旧验证码图片和数据,保证每次验证的时效性和准确性。
response.setHeader("Cache-Control", "no-store, no-cache");
// 设置响应的内容类型为 "image/jpeg",表明要返回给客户端的是 JPEG 格式的图片数据,让浏览器能够正确识别并展示验证码图片。
response.setContentType("image/jpeg");
// 调用 CaptchaUtils 工具类的 generateCaptcha 方法,传入 response 的输出流对象response.getOutputStream()
// 用于生成验证码图片,并将验证码图片数据输出到响应流中,使得客户端能够接收到验证码图片进行展示。同时,该方法返回生成的验证码文本内容(以字符串形式)。
String a = CaptchaUtils.generateCaptcha(response.getOutputStream());
// 调用 ShiroUtils 工具类的 setSessionAttribute 方法,将生成的验证码文本(存储在变量 a 中以指定的键SystemConstant.KAPTCHA_SESSION_KEY通常是一个常量字符串用于在会话中唯一标识验证码相关属性存储到会话中
// 这样后续在验证用户输入的验证码时,可以从会话中获取到正确的验证码文本进行比对验证。
ShiroUtils.setSessionAttribute(SystemConstant.KAPTCHA_SESSION_KEY, a);
}
/**
*
* "checkCode"使 @ResponseBody JSON 便
* validCode
* ServletException IOException ExceptionSupport
*
* @param validCode
* @throws ServletException Servlet
* @throws IOException I/O I/O
* @return true false
*/
@RequestMapping("checkCode")
@ResponseBody
public Boolean checkCode(String validCode) throws ServletException, IOException {
try {
// 调用 ShiroUtils 工具类的 getKaptcha 方法,传入用于标识验证码在会话中存储键的 SystemConstant.KAPTCHA_SESSION_KEY
// 从会话中获取之前存储的正确验证码文本内容(存储在变量 kaptcha 中),以便和用户输入的验证码进行比对验证。
String kaptcha = ShiroUtils.getKaptcha(SystemConstant.KAPTCHA_SESSION_KEY);
// 将用户输入的验证码validCode和从会话中获取的正确验证码kaptcha进行忽略大小写的字符串相等比较
// 如果两者相等,说明用户输入的验证码正确,返回 true表示验证通过否则返回 false表示验证不通过。
if (validCode.equalsIgnoreCase(kaptcha)) {
return true;
}
} catch (Exception e) {
// 如果在获取验证码、比对验证等过程中出现任何异常(例如会话不存在、获取属性失败等情况),
// 调用 ExceptionSupport 类的 resolverResult 方法来处理异常情况,该方法可能会进行一些诸如记录异常信息到日志、返回合适的错误提示等操作,
// 在这里捕获异常后继续返回 false表示验证不通过同时客户端可以根据服务器端的日志等方式排查具体的异常原因如果需要的话
ExceptionSupport.resolverResult("验证编码错误", this.getClass(), e);
}
return false;
}
}
}
Loading…
Cancel
Save