1. 程式人生 > >ajax,mybatis使用者名稱重複校驗

ajax,mybatis使用者名稱重複校驗

Controller層

@RestController
public class StoreController {	
	@Autowired
	private IStoreService storeService;
	@PostMapping("/editStore")
	public  String editStore(TbStoreInfoBean store, MultipartHttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> 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

 <select id="selStoreName" parameterType="com.bean.TbStoreInfoBean" resultType="java.lang.Integer">
    SELECT COUNT(*)
    FROM storeInfo AS s
    WHERE s.store_Name =#{storeName}
  </select>

ajax

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