怎样建立网站赚钱,网页制作代码,网站建设云主机云服务器,手机百度下载免费请求参数传json对象#xff0c;后端采用#xff08;pojo#xff09;接收的前提条件#xff1a;
1.pom.xml文件加入坐标依赖#xff1a;jackson-databind 2.Spring Boot 的启动类加注解#xff1a;EnableWebMvc 3.Spring Boot 的Controller接受参数采用#xff1a;Reque…请求参数传json对象后端采用pojo接收的前提条件
1.pom.xml文件加入坐标依赖jackson-databind 2.Spring Boot 的启动类加注解EnableWebMvc 3.Spring Boot 的Controller接受参数采用RequestBody 4.postman入参采用json格式
1.pom.xml文件加入坐标 dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.9.8/version
/dependency
2.Spring Boot 启动类加注解EnableWebMvc import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;SpringBootApplication
EnableWebMvc
EnableFeignClients(basePackages {com.itheima.platform.common.feign.services.home,com.itheima.bcg.service.fegin,com.itheima.platform.common.feign.services.paperTask,com.itheima.platform.common.feign.services.problem,com.itheima.platform.common.feign.services.auth,com.itheima.platform.common.feign.services.bpmn})
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}Beanpublic RestTemplate restTemplate() {//复杂构造函数的使用SimpleClientHttpRequestFactory requestFactory new SimpleClientHttpRequestFactory();requestFactory.setConnectTimeout(300000);// 设置超时requestFactory.setReadTimeout(300000);RestTemplate restTemplate new RestTemplate();restTemplate.setRequestFactory(requestFactory);return restTemplate;}Beanpublic ClientHttpRequestFactory simpleClientHttpRequestFactory() {SimpleClientHttpRequestFactory factory new SimpleClientHttpRequestFactory();factory.setConnectTimeout(150000);factory.setReadTimeout(50000);return factory;}
}
POJO类 import lombok.Data;Data
public class Config {private int seqId;private int sortId;private String interfaceType;private String dicNameFirst;private int dicValueFirst;private String dicNameSecond;private int dicValueSecond;private String dicType;private String isEnable;
}
3.Controller接受参数采用RequestBody Controller类 备注为了便于测试Controller类只写了一个接口实际开发可不要这样写噢
/** 请求参数传json对象POJO**/PostMapping(value /addTest)AuthInterceptor(mg:get:addTest)public Result addTest(RequestBody Config config) {try {return xxxListService.addTest(config);} catch (Exception e) {log.error(Controller addTest is error: e.getMessage(), e);return Result.failure(测试成功);}}
Service类 Result addTest(Config config);ServiceImpl类
Overridepublic Result addTest(Config config) {ListMapString, Object res new ArrayList();String interfaceType config.getInterfaceType();if(interfaceType.equals(add)){xxxListMapper.addTest(config);}else if(interfaceType.equals(del)){xxxListMapper.delTest(config);}else if(interfaceType.equals(modify)){xxxListMapper.modifyTest(config);}else if(interfaceType.equals(sel)){res xxxListMapper.selTest(config);}return Result.success().result(res);}
Mapper类 //新增void addTest(Config config);//删除void delTest(Config config);//修改void modifyTest(Config config);//查询ListMapString, Object selTest(Config config);
Mapper.xml类
!-- 新增 --insert idaddTestINSERT IGNORE INTO xxx_other_list_dic(dicNameFirst,dicValueFirst,dicNameSecond,dicValueSecond,dicType,isEnable)VALUES(#{dicNameFirst},#{dicValueFirst},#{dicNameSecond},#{dicValueSecond},#{dicType},#{isEnable})/insert!-- 删除 --select iddelTestdeleteFROM xxx_other_list_dic whereif test null ! seqId and ! seqIdseqId #{seqId}/if/select!-- 修改 --update idmodifyTestupdate xxx_other_list_dicsetif test null ! sortId and ! sortIdsortId #{sortId},/ifif test null ! isEnable and ! isEnableisEnable #{isEnable}/if/setwhereif test null ! seqId and ! seqIdseqId #{seqId}/if/update!-- 查询 --select idselTest resultTypemapSELECT *FROM xxx_other_list_dic where 1 1if testnull ! dicNameFirst and ! dicNameFirstand dicNameFirst #{dicNameFirst}/ifif testnull ! dicValueFirst and ! dicValueFirstand dicValueFirst #{dicValueFirst}/ifif testnull ! dicNameSecond and ! dicNameSecondand dicNameSecond #{dicNameSecond}/ifif testnull ! dicValueSecond and ! dicValueSecondand dicValueSecond #{dicValueSecond}/ifif testnull ! dicType and ! dicTypeand dicType #{dicType}/ifif testnull ! isEnable and ! isEnableand isEnable #{isEnable}/iforder by sortId/select
4.postman入参采用json格式 postman 接口测试: 新增 修改 查询 删除 文章转载自: http://www.morning.hsklc.cn.gov.cn.hsklc.cn http://www.morning.zqnmp.cn.gov.cn.zqnmp.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.xsctd.cn.gov.cn.xsctd.cn http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn http://www.morning.knmby.cn.gov.cn.knmby.cn http://www.morning.fxpyt.cn.gov.cn.fxpyt.cn http://www.morning.dpjtn.cn.gov.cn.dpjtn.cn http://www.morning.cwqln.cn.gov.cn.cwqln.cn http://www.morning.kjgrg.cn.gov.cn.kjgrg.cn http://www.morning.rkbly.cn.gov.cn.rkbly.cn http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn http://www.morning.ndcf.cn.gov.cn.ndcf.cn http://www.morning.jzklb.cn.gov.cn.jzklb.cn http://www.morning.qcztm.cn.gov.cn.qcztm.cn http://www.morning.mm27.cn.gov.cn.mm27.cn http://www.morning.rqlbp.cn.gov.cn.rqlbp.cn http://www.morning.srrzb.cn.gov.cn.srrzb.cn http://www.morning.bxbnf.cn.gov.cn.bxbnf.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.jgrjj.cn.gov.cn.jgrjj.cn http://www.morning.frfnb.cn.gov.cn.frfnb.cn http://www.morning.hgfxg.cn.gov.cn.hgfxg.cn http://www.morning.qhmhz.cn.gov.cn.qhmhz.cn http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn http://www.morning.nfmtl.cn.gov.cn.nfmtl.cn http://www.morning.nypsz.cn.gov.cn.nypsz.cn http://www.morning.snktp.cn.gov.cn.snktp.cn http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn http://www.morning.c7617.cn.gov.cn.c7617.cn http://www.morning.lywcd.cn.gov.cn.lywcd.cn http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn http://www.morning.nxfuke.com.gov.cn.nxfuke.com http://www.morning.pmjhm.cn.gov.cn.pmjhm.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.rwdbz.cn.gov.cn.rwdbz.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.pdmml.cn.gov.cn.pdmml.cn http://www.morning.rfxg.cn.gov.cn.rfxg.cn http://www.morning.rdkt.cn.gov.cn.rdkt.cn http://www.morning.rpth.cn.gov.cn.rpth.cn http://www.morning.dlrsjc.com.gov.cn.dlrsjc.com http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.attorneysportorange.com.gov.cn.attorneysportorange.com http://www.morning.lgsfb.cn.gov.cn.lgsfb.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.ltrms.cn.gov.cn.ltrms.cn http://www.morning.wwdlg.cn.gov.cn.wwdlg.cn http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.wjrq.cn.gov.cn.wjrq.cn http://www.morning.kyjpg.cn.gov.cn.kyjpg.cn http://www.morning.rsxw.cn.gov.cn.rsxw.cn http://www.morning.dgpxp.cn.gov.cn.dgpxp.cn http://www.morning.dpnhs.cn.gov.cn.dpnhs.cn http://www.morning.nsfxt.cn.gov.cn.nsfxt.cn http://www.morning.rfwrn.cn.gov.cn.rfwrn.cn http://www.morning.gqksd.cn.gov.cn.gqksd.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn http://www.morning.nslwj.cn.gov.cn.nslwj.cn http://www.morning.ghfrb.cn.gov.cn.ghfrb.cn http://www.morning.pngph.cn.gov.cn.pngph.cn http://www.morning.rgnq.cn.gov.cn.rgnq.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn http://www.morning.glnfn.cn.gov.cn.glnfn.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.pqkgb.cn.gov.cn.pqkgb.cn http://www.morning.wnrcj.cn.gov.cn.wnrcj.cn http://www.morning.xpqsk.cn.gov.cn.xpqsk.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.dpfr.cn.gov.cn.dpfr.cn http://www.morning.kycwt.cn.gov.cn.kycwt.cn http://www.morning.fydsr.cn.gov.cn.fydsr.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.btlsb.cn.gov.cn.btlsb.cn http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.tdscl.cn.gov.cn.tdscl.cn http://www.morning.wqgr.cn.gov.cn.wqgr.cn