使用springmvc采用注解方式注入service:
1.在spring.xml配置文件中注入要扫描的类:
<context:component-scan base-package=”com.doron” >
<context:exclude-filter type=”annotation” expression=”org.springframework.stereotype.Controller”/>
</context:component-scan>
2.service层
接口:
public interface TEventsService{ int insertSelective(HttpServletRequest req ,TItmpTcsEvents record); }
实现类:
@Service("eventsService") public class TEventsServiceImpl implements TEventsService { @Autowired private TItmpTcsEventsMapper eventsMapper; public int insertSelective(HttpServletRequest req ,TItmpTcsEvents record){ return eventsMapper.insertSelective(record); } }
3.controller层:
@Controller @RequestMapping(value = "/events") public class TEventsController{ @Autowired private TEventsService eventsService; @SuppressWarnings("unused") @RequestMapping(value = "/saveEvents", produces = {"application/json;charset=UTF-8"}) @ResponseBody public Map<String, Object> saveArtificalReceive(HttpServletRequest req, HttpServletResponse resp,TItmpTcsEvents record{ Map<String, Object> result = new HashMap<String, Object>(); int eventCount = 0; eventCount = eventsService.insertSelective(req,record); // 插入警情信息成功后返回前台 if (eventCount > 0){ result.put("result", true); }else { result.put("result", false); } } }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/11201.html