SpringBoot+ajax踩的坑Error resolving template, template might not exist or might not be accessible

最近写SpringBoot项目的时候用到了ajax

但是在我运行后报错了,如下:
Exception processing template “/addType”: Error resolving template [/addType], template might not exist or might not be accessible by any of the configured Template Resolvers

大概意思就是找不到/type这个url

Controller方法如下

    @RequestMapping("/addType1")
    public void addType1(Type type){
        typeService.addType(type);
    }

ajax代码如下

		<script>
			function add() {

			var typeadd = $("#type1-add").val();

			$.ajax({

				url: "/addType1",
				data: {'type':typeadd},
				dataType: "JSON",
				method: "POST",
				success: function (data) {
					alert("添加成功!");
				}
			});
			}
		</script>

我寻思这也没问题啊,但是后来百度过才发现,SpringBoot后端要想接受数据,Controller里@Controller换成@RestController,或者在方法上加@Responsbody的注解,不然无法被识别。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值