ajax,mybatis用户名重复校验

Controller层

@RestController
public class StoreController {	
	@Autowired
	private IStoreService storeService;
	@PostMapping("/editStore")
	public  String editStore(TbStoreInfoBean store, MultipartHttpServletRequest request, HttpServletResponse response) {
		Map map = new HashMap<>();
			int count =storeService.selStoreName(store);
			if(count > 0){
				return "22222"
			}
			。。。添加方法

Dao层

	 int selStoreName(TbStoreInfoBean store);

IStoreServic层

 int selStoreName(TbStoreInfoBean store);

StoreServiceImpl层

	 @Override
	 public int selStoreName(TbStoreInfoBean store) {
	  return storeDao.selStoreName(store);
	 }

mapper

 

ajax

 $.ajax({
	        url:  xxx
	        type: "POST",
	        data: formData,
		    success: function (data) {
			     if(data == '22222'){
			            	 layer.closeAll('loading');
			            	 layer.msg("店铺已存在!请重新填写");
			             }
	       });      

添加和修改走一个方法的时候,在mapper里写一个通过ID查询店铺名的SQL,Controller层逻辑

		 int count = storeService.selStoreName(store);
		 String rename = storeService.selStoreInfoName(store);
		 String newName = request.getParameter("storeInfoName");
	
		 boolean b = false ;
			 
		 if(rename == null ) {
			 if(count == 0) {
				 b = true;
			 }
		 }else if( rename.equals(newName) && count >=1){
			 b =true;
		 }
		 
		 if(!b) {
			 return "22222";
		 }

你可能感兴趣的:(用户名重复校验)