木头人的gravatar头像
木头人 2017-03-28 09:39:54

angular js+require+spring boot+spring mvc+mybatis实战演练demo

在工作闲暇之余,想把很久没用的技术拿来用一下,遇到很多问题,最终还是通过各种手段搭建起来了这个demo。

1.require.js的使用

/**
 * require.js异步载入所有文件,手动启动angularjs应用
 */
require.config({
	baseUrl: 'static/js',
	paths:{
		"angular":"./vender/angularjs/angular",
		"bootstrap":"./vender/bootstrap/bootstrap",
		"bootstrapDate":"./vender/bootstrap/bootstrap-datetimepicker",
		"moment":"./vender/moment/moment-with-locales",
		"angularRoute":"./vender/angularjs/angular-route",
		"angularResource":"./vender/angularjs/angular-resource",
		"jquery":"./vender/jquery/jquery-1.9.1.min"
	},
	
	shim:{
		angular:{
			exports:"angular"
		},
		angularRoute:{
			deps:['angular']
		},
		angularResource:{
			deps:['angular']
		},
		bootstrap:{
			deps:['jquery']
		},
		bootstrapDate:{
			deps:['bootstrap','moment']
		}
	},
	
	urlArgs: "bust=" + (new Date()).getTime()  //防止读取缓存,调试用 
});

define(["routes"], function () {  
    //使用bootstrap方法启动Angular应用  
    angular.bootstrap(document, ["app"]);  
});
'use strict';

define([ 
	'angular',
	'bootstrapDate', 
	'angularResource', 
	'angularRoute', 
	'controllers/index',
	'services/index' 
	], function(angular) {
	return angular.module('app', [ 'ngRoute', 'ngResource', 'controllers',
			'services' ]);
})

2.angular的路由(采用的angular自带的路由)

define(['app'],function(app){
	app.config(['$locationProvider','$routeProvider',function($locationProvider,$routeProvider){
		//angularjs1.6.x版本号后路由出现的问题(多了一个感叹号)
		$locationProvider.hashPrefix('');
		$routeProvider.when('/home',{
			templateUrl: 'static/template/home.html',  
            controller: 'HomeController',
            controllerAs:'homeCtrl'
		}).when('/user',{
			templateUrl: 'static/template/userinfo.html',  
            controller: 'UserController',
            controllerAs:'userCtrl'
		}).otherwise({
			redirectTo:'/home'
		});
	}]);
});

3.项目目录结构

angular js+require+spring boot+spring mvc+mybatis实战演练demo

4.运行效果

angular js+require+spring boot+spring mvc+mybatis实战演练demo

angular js+require+spring boot+spring mvc+mybatis实战演练demoangular js+require+spring boot+spring mvc+mybatis实战演练demo


打赏

文件名:angular.zip,文件大小:1703.065K 下载
最代码最近下载分享源代码列表最近下载
WASDZZ  LV13 2023年2月3日
a1677596408  LV23 2022年7月1日
9843637  LV9 2021年12月13日
Kentucky  LV5 2021年7月16日
ssm123  LV9 2020年7月5日
cex12345  LV4 2020年6月5日
1358849392  LV21 2020年5月7日
dyt-123  LV7 2020年3月28日
pahirdin  LV12 2020年1月26日
fsheng122  LV7 2019年12月26日
最代码最近浏览分享源代码列表最近浏览
飞呀飞呀飞不放  LV7 2023年8月25日
微信网友_6442588254851072  LV2 2023年4月21日
李亮  LV19 2023年3月6日
wxd1997  LV13 2022年11月4日
new_docker  LV15 2022年8月5日
谢谢谢谢谢谢你  LV6 2022年7月19日
a1677596408  LV23 2022年7月1日
fengzhou888  LV5 2022年6月16日
WASDZZ  LV13 2022年5月10日
kissnicky  LV7 2022年4月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友